|
| 1 | +import { Component } from '@angular/core'; |
| 2 | +import { TestBed } from '@angular/core/testing'; |
| 3 | + |
| 4 | +import { NgAisReverseSnippetModule } from '../reverse-snippet.module'; |
| 5 | + |
| 6 | +const render = ({ hit, attribute, highlightedTagName = 'mark' }) => { |
| 7 | + @Component({ |
| 8 | + selector: 'test-component', |
| 9 | + template: ` |
| 10 | + <ais-reverse-snippet [attribute]="attribute" [hit]="hit" [highlightedTagName]="highlightedTagName"> |
| 11 | + </ais-reverse-snippet> |
| 12 | + `, |
| 13 | + }) |
| 14 | + class TestComponent { |
| 15 | + hit = hit; |
| 16 | + attribute: string = attribute; |
| 17 | + highlightedTagName = highlightedTagName; |
| 18 | + } |
| 19 | + |
| 20 | + TestBed.configureTestingModule({ |
| 21 | + declarations: [TestComponent], |
| 22 | + imports: [NgAisReverseSnippetModule], |
| 23 | + }); |
| 24 | + |
| 25 | + const fixture = TestBed.createComponent(TestComponent); |
| 26 | + fixture.detectChanges(); |
| 27 | + |
| 28 | + return fixture; |
| 29 | +}; |
| 30 | + |
| 31 | +describe('reverse snippet', () => { |
| 32 | + it('should snippet strings', () => { |
| 33 | + const fixture = render({ |
| 34 | + attribute: 'description', |
| 35 | + hit: { |
| 36 | + _snippetResult: { |
| 37 | + description: { value: '… <mark>foo</mark> bar …' }, |
| 38 | + }, |
| 39 | + }, |
| 40 | + }); |
| 41 | + expect(fixture).toMatchSnapshot(); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should snippet with a custom highlightedTagName', () => { |
| 45 | + const fixture = render({ |
| 46 | + attribute: 'description', |
| 47 | + hit: { |
| 48 | + _snippetResult: { |
| 49 | + description: { value: '… <mark>foo</mark> bar …' }, |
| 50 | + }, |
| 51 | + }, |
| 52 | + highlightedTagName: 'em', |
| 53 | + }); |
| 54 | + expect(fixture).toMatchSnapshot(); |
| 55 | + }); |
| 56 | +}); |
0 commit comments