import { TestBed, inject } from '@angular/core/testing'; import { DiffService, ModificationType } from './diff.service'; import { LinenumberingService } from './linenumbering.service'; describe('DiffService', () => { const brMarkup = (no: number): string => { return ( '
' + ' ' ); }; const noMarkup = (no: number): string => { return ( ' ' ); }; const baseHtml1 = '

' + noMarkup(1) + 'Line 1 ' + brMarkup(2) + 'Line 2 ' + brMarkup(3) + 'Line 3
' + noMarkup(4) + 'Line 4 ' + brMarkup(5) + 'Line
5

' + '' + '

' + noMarkup(10) + 'Line 10 ' + brMarkup(11) + 'Line 11

'; let baseHtmlDom1: DocumentFragment; const baseHtml2 = '

' + noMarkup(1) + 'Single text line

\

' + noMarkup(2) + 'sdfsdfsdfsdf dsfsdfsdfdsflkewjrl ksjfl ksdjf klnlkjBavaria ipsum dolor sit amet Biazelt Auffisteign ' + brMarkup(3) + 'Schorsch mim Radl foahn Ohrwaschl Steckerleis wann griagd ma nacha wos z’dringa glacht Mamalad, ' + brMarkup(4) + 'muass? I bin a woschechta Bayer sowos oamoi und sei und glei wirds no fui lustiga: Jo mei khkhis des ' + brMarkup(5) + 'schee middn ognudelt, Trachtnhuat Biawambn gscheid: Griasd eich midnand etza nix Gwiass woass ma ned ' + brMarkup(6) + 'owe. Dahoam gscheckate middn Spuiratz des is a gmahde Wiesn. Des is schee so Obazda san da, Haferl ' + brMarkup(7) + 'pfenningguat schoo griasd eich midnand.

\ \

' + noMarkup(14) + 'I waar soweid Blosmusi es nomoi. Broadwurschtbudn des is a gmahde Wiesn Kirwa mogsd a Bussal ' + brMarkup(15) + 'Guglhupf schüds nei. Luja i moan oiwei Baamwach Watschnbaam, wiavui baddscher! Biakriagal a fescha ' + brMarkup(16) + '1Bua Semmlkneedl iabaroi oba um Godds wujn Ledahosn wui Greichats. Geh um Godds wujn luja heid ' + brMarkup(17) + 'greaßt eich nachad woaß Breihaus eam! De om auf’n Gipfe auf gehds beim Schichtl mehra Baamwach a ' + brMarkup(18) + 'bissal wos gehd ollaweil gscheid:

\
\

' + noMarkup(19) + 'Scheans Schdarmbeaga See i hob di narrisch gean i jo mei is des schee! Nia eam ' + brMarkup(20) + 'hod vasteh i sog ja nix, i red ja bloß sammawiedaguad, umma eana obandeln! Zwoa ' + brMarkup(21) + 'jo mei scheans amoi, san und hoggd Milli barfuaßat gscheit. Foidweg vui huift ' + brMarkup(22) + 'vui singan, mehra Biakriagal om auf’n Gipfe! Ozapfa sodala Charivari greaßt eich ' + brMarkup(23) + 'nachad Broadwurschtbudn do middn liberalitas Bavariae sowos Leonhardifahrt:

\
\

' + noMarkup(24) + 'Wui helfgod Wiesn, ognudelt schaugn: Dahoam gelbe Rüam Schneid singan wo hi sauba i moan scho aa no ' + brMarkup(25) + 'a Maß a Maß und no a Maß nimma. Is umananda a ganze Hoiwe zwoa, Schneid. Vui huift vui Brodzeid kumm ' + brMarkup(26) + 'geh naa i daad vo de allerweil, gor. Woaß wia Gams, damischa. A ganze Hoiwe Ohrwaschl Greichats ' + brMarkup(27) + 'iabaroi Prosd Engelgwand nix Reiwadatschi.Weibaleid ognudelt Ledahosn noch da Giasinga Heiwog i daad ' + brMarkup(28) + 'Almrausch, Ewig und drei Dog nackata wea ko, dea ko. Meidromml Graudwiggal nois dei, nackata. No ' + brMarkup(29) + 'Diandldrahn nix Gwiass woass ma ned hod boarischer: Samma sammawiedaguad wos, i hoam Brodzeid. Jo ' + brMarkup(30) + 'mei Sepp Gaudi, is ma Wuascht do Hendl Xaver Prosd eana an a bravs. Sauwedda an Brezn, abfieseln.

'; let baseHtmlDom2: DocumentFragment; const baseHtml3 = '
    ' + '
  1. ' + noMarkup(1) + 'Line 1
  2. ' + '
  3. ' + noMarkup(2) + 'Line 2
  4. ' + '
    1. ' + '
    2. ' + noMarkup(3) + 'Line 3.1
    3. ' + '
    4. ' + noMarkup(4) + 'Line 3.2
    5. ' + '
    6. ' + noMarkup(5) + 'Line 3.3
    7. ' + '
  5. ' + '
  6. ' + noMarkup(6) + ' Line 4
'; beforeAll(inject([DiffService], (service: DiffService) => { baseHtmlDom1 = service.htmlToFragment(baseHtml1); baseHtmlDom2 = service.htmlToFragment(baseHtml2); service.insertInternalLineMarkers(baseHtmlDom1); service.insertInternalLineMarkers(baseHtmlDom2); })); beforeEach(() => { TestBed.configureTestingModule({ providers: [DiffService] }); }); describe('extraction of lines', () => { it('locates line number nodes', inject([DiffService], (service: DiffService) => { let lineNumberNode = service.getLineNumberNode(baseHtmlDom1, 4); expect(lineNumberNode.parentNode.nodeName).toBe('STRONG'); lineNumberNode = service.getLineNumberNode(baseHtmlDom1, 9); expect(lineNumberNode.parentNode.nodeName).toBe('UL'); lineNumberNode = service.getLineNumberNode(baseHtmlDom1, 15); expect(lineNumberNode).toBe(null); })); it('finds the common ancestor', inject([DiffService], (service: DiffService) => { let fromLineNode, toLineNode, commonAncestor; fromLineNode = service.getLineNumberNode(baseHtmlDom1, 6); toLineNode = service.getLineNumberNode(baseHtmlDom1, 7); commonAncestor = service.getCommonAncestor(fromLineNode, toLineNode); expect(commonAncestor.commonAncestor.nodeName).toBe('#document-fragment'); fromLineNode = service.getLineNumberNode(baseHtmlDom1, 6); toLineNode = service.getLineNumberNode(baseHtmlDom1, 8); commonAncestor = service.getCommonAncestor(fromLineNode, toLineNode); expect(commonAncestor.commonAncestor.nodeName).toBe('#document-fragment'); fromLineNode = service.getLineNumberNode(baseHtmlDom1, 6); toLineNode = service.getLineNumberNode(baseHtmlDom1, 10); commonAncestor = service.getCommonAncestor(fromLineNode, toLineNode); expect(commonAncestor.commonAncestor.nodeName).toBe('#document-fragment'); })); it('renders DOMs correctly (1)', inject([DiffService], (service: DiffService) => { const lineNo = service.getLineNumberNode(baseHtmlDom1, 7), greatParent = lineNo.parentNode.parentNode; let lineTrace = [lineNo.parentNode, lineNo]; const pre = service.serializePartialDomToChild(greatParent, lineTrace, true); expect(pre).toBe('' ); })); it('renders DOMs correctly (2)', inject([DiffService], (service: DiffService) => { const lineNo = service.getLineNumberNode(baseHtmlDom1, 9), greatParent = lineNo.parentNode.parentNode, lineTrace = [lineNo.parentNode, lineNo]; const pre = service.serializePartialDomToChild(greatParent, lineTrace, true); expect(pre).toBe('
  • '); expect(diff.followingHtmlStartSnippet).toBe( '