import * as DomRepository from "." ; import { CastAny } from "../../../shared/types/utils" ; import { createMockDocumentBy } from "../../__test__/Helper" ; import * as Document from "../QuerySelector/Document" ; import { html as swagger20JsonHtml } from "./fixtures/GitHubPageHtml_swagger_2_0_json" ; import { html as swagger20YamlHtml_InPrivateBrowsing } from "./fixtures/GitHubPageHtml_swagger_2_0_yaml_InPrivateBrowsing" ; import { html as swagger30YamlHtml } from "./fixtures/GitHubPageHtml_swagger_3_0_yaml" ; /**
 * 注意: DomRepository に直接アクセスすると、Mockが無効になってしまう。
 * DomRepository を直接使うテストは、別ファイルにする必要がある。
 */ describe ( "GitHubPageHtml swagger 2.0 json tests" , ( ) => { let sut ; let mockDocument ; beforeAll ( ( ) => { jest . mock ( "../QuerySelector/Document" ) ; mockDocument = require ( "../QuerySelector/Document" ) ; ( mockDocument as CastAny ) . getDocument . mockReturnValue ( createMockDocumentBy ( swagger20JsonHtml , "https://github.com/arx-8/swagger-viewer/blob/master/swagger-viewer/app-src/shared/__test__/fixtures/swagger_2_0.json" ) ) ; sut = require ( "." ) ; } ) ; describe ( "whole tests" , ( ) => { it ( "isConverted" , ( ) => { expect ( sut . isConverted ( ) ) . toStrictEqual ( false ) ; } ) ; it ( "getElmOfSrcCode" , ( ) => { const result = sut . getElmOfSrcCode ( ) ; expect ( result . textContent != null ) . toStrictEqual ( true ) ; expect ( result . children . length ) . toStrictEqual ( 1 ) ; } ) ; it ( "extractSrc" , ( ) => { expect ( sut . extractSrc ( ) ) . toMatchSnapshot ( ) ; } ) ; } ) ; } ) ; /**
 * プライベートブラウザ（シークレットモード） + organizationアカウント？では少し違ったDOMが表示されるため、別途テスト
 */ describe ( "GitHubPageHtml swagger 2.0 yaml tests in Private browsing" , ( ) => { let sut ; let mockDocument ; beforeAll ( ( ) => { jest . mock ( "../QuerySelector/Document" ) ; mockDocument = require ( "../QuerySelector/Document" ) ; ( mockDocument as CastAny ) . getDocument . mockReturnValue ( createMockDocumentBy ( swagger20YamlHtml_InPrivateBrowsing , "https://github.com/arx-8/swagger-viewer/blob/master/swagger-viewer/app-src/shared/__test__/fixtures/swagger_2_0.yaml" ) ) ; sut = require ( "." ) ; } ) ; describe ( "whole tests" , ( ) => { it ( "isConverted" , ( ) => { expect ( sut . isConverted ( ) ) . toStrictEqual ( false ) ; } ) ; it ( "getElmOfSrcCode" , ( ) => { const result = sut . getElmOfSrcCode ( ) ; expect ( result . textContent != null ) . toStrictEqual ( true ) ; expect ( result . children . length ) . toStrictEqual ( 1 ) ; } ) ; it ( "extractSrc" , ( ) => { expect ( sut . extractSrc ( ) ) . toMatchSnapshot ( ) ; } ) ; } ) ; } ) ; describe ( "GitHubPageHtml swagger 3.0 yaml tests" , ( ) => { let sut ; let mockDocument ; beforeAll ( ( ) => { jest . mock ( "../QuerySelector/Document" ) ; mockDocument = require ( "../QuerySelector/Document" ) ; ( mockDocument as CastAny ) . getDocument . mockReturnValue ( createMockDocumentBy ( swagger30YamlHtml , "https://github.com/arx-8/swagger-viewer/blob/master/swagger-viewer/app-src/shared/__test__/fixtures/swagger_3_0.yaml" ) ) ; sut = require ( "." ) ; } ) ; describe ( "whole tests" , ( ) => { it ( "isConverted" , ( ) => { expect ( sut . isConverted ( ) ) . toStrictEqual ( false ) ; } ) ; it ( "getElmOfSrcCode" , ( ) => { const result = sut . getElmOfSrcCode ( ) ; expect ( result . textContent != null ) . toStrictEqual ( true ) ; expect ( result . children . length ) . toStrictEqual ( 1 ) ; } ) ; it ( "extractSrc" , ( ) => { expect ( sut . extractSrc ( ) ) . toMatchSnapshot ( ) ; } ) ; } ) ; } ) ; describe ( "GitHubPageHtml swagger 3.1 yaml tests" , ( ) => { let sut ; let mockDocument ; beforeAll ( ( ) => { jest . mock ( "../QuerySelector/Document" ) ; mockDocument = require ( "../QuerySelector/Document" ) ; ( mockDocument as CastAny ) . getDocument . mockReturnValue ( createMockDocumentBy ( swagger30YamlHtml , "https://github.com/arx-8/swagger-viewer/blob/master/swagger-viewer/app-src/shared/__test__/fixtures/swagger_3_1.yaml" ) ) ; sut = require ( "." ) ; } ) ; describe ( "whole tests" , ( ) => { it ( "isConverted" , ( ) => { expect ( sut . isConverted ( ) ) . toStrictEqual ( false ) ; } ) ; it ( "getElmOfSrcCode" , ( ) => { const result = sut . getElmOfSrcCode ( ) ; expect ( result . textContent != null ) . toStrictEqual ( true ) ; expect ( result . children . length ) . toStrictEqual ( 1 ) ; } ) ; it ( "extractSrc" , ( ) => { expect ( sut . extractSrc ( ) ) . toMatchSnapshot ( ) ; } ) ; } ) ; } ) ; describe ( "empty page" , ( ) => { let sut ; let mockDocument ; beforeAll ( ( ) => { jest . mock ( "../QuerySelector/Document" ) ; mockDocument = require ( "../QuerySelector/Document" ) ; ( mockDocument as CastAny ) . getDocument . mockReturnValue ( createMockDocumentBy ( `<!DOCTYPE html><html lang="en"><head><title>empty</title></head><body></body></html>` , "https://example.com" ) ) ; sut = require ( "." ) ; } ) ; describe ( "whole tests" , ( ) => { it ( "isConverted" , ( ) => { expect ( sut . isConverted ( ) ) . toStrictEqual ( false ) ; } ) ; it ( "getElmOfSrcCode" , ( ) => { expect ( ( ) => { sut . getElmOfSrcCode ( ) ; } ) . toThrowErrorMatchingInlineSnapshot ( `"Unexpected DOM. Probably GitHub has been updated. Please contact the developer or wait until the extension is fixed. selector: \\"#repo-content-pjax-container div.Box-body table\\""` ) ; } ) ; it ( "extractSrc" , ( ) => { expect ( ( ) => { sut . extractSrc ( ) ; } ) . toThrowErrorMatchingInlineSnapshot ( `"Unexpected DOM. Probably GitHub has been updated. Please contact the developer or wait until the extension is fixed. selector: \\"#repo-content-pjax-container div.Box-body table\\""` ) ; } ) ; } ) ; } ) ;