|
1 | | - import { Component } from '@angular/core'; |
2 | | - import { |
3 | | - ComponentFixture, |
4 | | - TestBed, |
5 | | - } from '@angular/core/testing'; |
6 | | - |
7 | | - import { EntityIconDirective } from './entity-icon.directive'; |
8 | | - |
9 | | - describe('EntityIconDirective', () => { |
10 | | - let component: TestComponent; |
11 | | - let fixture: ComponentFixture<TestComponent>; |
12 | | - |
13 | | - beforeEach(async () => { |
14 | | - await TestBed.configureTestingModule({ |
15 | | - imports: [ |
16 | | - EntityIconDirective, |
17 | | - TestComponent |
18 | | - ], |
19 | | - }).compileComponents(); |
| 1 | +import { Component } from '@angular/core'; |
| 2 | +import { |
| 3 | + ComponentFixture, |
| 4 | + TestBed, |
| 5 | +} from '@angular/core/testing'; |
| 6 | + |
| 7 | +import { EntityIconDirective } from './entity-icon.directive'; |
| 8 | + |
| 9 | +describe('EntityIconDirective', () => { |
| 10 | + let component: TestComponent; |
| 11 | + let fixture: ComponentFixture<TestComponent>; |
| 12 | + |
| 13 | + beforeEach(async () => { |
| 14 | + await TestBed.configureTestingModule({ |
| 15 | + imports: [ |
| 16 | + EntityIconDirective, |
| 17 | + TestComponent, |
| 18 | + ], |
| 19 | + }).compileComponents(); |
| 20 | + }); |
| 21 | + |
| 22 | + describe('with default value provided', () => { |
| 23 | + beforeEach(() => { |
| 24 | + fixture = TestBed.createComponent(TestComponent); |
| 25 | + component = fixture.componentInstance; |
| 26 | + fixture.detectChanges(); |
20 | 27 | }); |
21 | 28 |
|
22 | | - describe('with default value provided', () => { |
23 | | - beforeEach(() => { |
24 | | - fixture = TestBed.createComponent(TestComponent); |
25 | | - component = fixture.componentInstance; |
26 | | - fixture.detectChanges(); |
27 | | - }); |
28 | | - |
29 | | - it('should create', () => { |
30 | | - expect(component).toBeTruthy(); |
31 | | - }); |
32 | | - |
33 | | - it('should display a text-success icon', () => { |
34 | | - const successIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i.text-success'); |
35 | | - expect(successIcon).toBeTruthy(); |
36 | | - }); |
37 | | - |
38 | | - it('should display a text-success icon after span', () => { |
39 | | - const successIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i.text-success'); |
40 | | - const entityElement = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]'); |
41 | | - // position 1 because the icon is after the span |
42 | | - expect(entityElement.children[1]).toBe(successIcon); |
43 | | - }); |
| 29 | + it('should create', () => { |
| 30 | + expect(component).toBeTruthy(); |
44 | 31 | }); |
45 | 32 |
|
46 | | - describe('with primary value provided', () => { |
47 | | - beforeEach(() => { |
48 | | - fixture = TestBed.createComponent(TestComponent); |
49 | | - component = fixture.componentInstance; |
50 | | - component.metadata.entityType = 'person'; |
51 | | - component.metadata.entityStyle = 'personStaff'; |
52 | | - component.iconPosition = 'before'; |
53 | | - fixture.detectChanges(); |
54 | | - }); |
55 | | - |
56 | | - it('should display a text-primary icon', () => { |
57 | | - const primaryIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i.text-primary'); |
58 | | - expect(primaryIcon).toBeTruthy(); |
59 | | - }); |
60 | | - |
61 | | - it('should display a text-primary icon before span', () => { |
62 | | - const primaryIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i.text-primary'); |
63 | | - const entityElement = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]'); |
64 | | - // position 0 because the icon is before the span |
65 | | - expect(entityElement.children[0]).toBe(primaryIcon); |
66 | | - }); |
| 33 | + it('should display a text-success icon', () => { |
| 34 | + const successIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i.text-success'); |
| 35 | + expect(successIcon).toBeTruthy(); |
67 | 36 | }); |
68 | 37 |
|
69 | | - describe('when given type doesn\'t exist and fallback on default disabled', () => { |
70 | | - beforeEach(() => { |
71 | | - fixture = TestBed.createComponent(TestComponent); |
72 | | - component = fixture.componentInstance; |
73 | | - component.fallbackOnDefault = false; |
74 | | - component.metadata.entityType = 'TESTFAKE'; |
75 | | - component.metadata.entityStyle = 'personFallback'; |
76 | | - component.iconPosition = 'before'; |
77 | | - fixture.detectChanges(); |
78 | | - }); |
79 | | - |
80 | | - it('should not display a text-primary icon', () => { |
81 | | - const primaryIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i'); |
82 | | - expect(primaryIcon).toBeFalsy(); |
83 | | - }); |
| 38 | + it('should display a text-success icon after span', () => { |
| 39 | + const successIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i.text-success'); |
| 40 | + const entityElement = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]'); |
| 41 | + // position 1 because the icon is after the span |
| 42 | + expect(entityElement.children[1]).toBe(successIcon); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + describe('with primary value provided', () => { |
| 47 | + beforeEach(() => { |
| 48 | + fixture = TestBed.createComponent(TestComponent); |
| 49 | + component = fixture.componentInstance; |
| 50 | + component.metadata.entityType = 'person'; |
| 51 | + component.metadata.entityStyle = 'personStaff'; |
| 52 | + component.iconPosition = 'before'; |
| 53 | + fixture.detectChanges(); |
84 | 54 | }); |
85 | 55 |
|
86 | | - describe('when given style doesn\'t exist and fallback on default disabled', () => { |
87 | | - beforeEach(() => { |
88 | | - fixture = TestBed.createComponent(TestComponent); |
89 | | - component = fixture.componentInstance; |
90 | | - component.fallbackOnDefault = false; |
91 | | - component.metadata.entityType = 'person'; |
92 | | - component.metadata.entityStyle = 'personFallback'; |
93 | | - component.iconPosition = 'before'; |
94 | | - fixture.detectChanges(); |
95 | | - }); |
96 | | - |
97 | | - it('should not display a text-primary icon', () => { |
98 | | - const primaryIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i'); |
99 | | - expect(primaryIcon).toBeFalsy(); |
100 | | - }); |
| 56 | + it('should display a text-primary icon', () => { |
| 57 | + const primaryIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i.text-primary'); |
| 58 | + expect(primaryIcon).toBeTruthy(); |
101 | 59 | }); |
102 | 60 |
|
| 61 | + it('should display a text-primary icon before span', () => { |
| 62 | + const primaryIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i.text-primary'); |
| 63 | + const entityElement = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]'); |
| 64 | + // position 0 because the icon is before the span |
| 65 | + expect(entityElement.children[0]).toBe(primaryIcon); |
| 66 | + }); |
103 | 67 | }); |
104 | 68 |
|
| 69 | + describe('when given type doesn\'t exist and fallback on default disabled', () => { |
| 70 | + beforeEach(() => { |
| 71 | + fixture = TestBed.createComponent(TestComponent); |
| 72 | + component = fixture.componentInstance; |
| 73 | + component.fallbackOnDefault = false; |
| 74 | + component.metadata.entityType = 'TESTFAKE'; |
| 75 | + component.metadata.entityStyle = 'personFallback'; |
| 76 | + component.iconPosition = 'before'; |
| 77 | + fixture.detectChanges(); |
| 78 | + }); |
| 79 | + |
| 80 | + it('should not display a text-primary icon', () => { |
| 81 | + const primaryIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i'); |
| 82 | + expect(primaryIcon).toBeFalsy(); |
| 83 | + }); |
| 84 | + }); |
| 85 | + |
| 86 | + describe('when given style doesn\'t exist and fallback on default disabled', () => { |
| 87 | + beforeEach(() => { |
| 88 | + fixture = TestBed.createComponent(TestComponent); |
| 89 | + component = fixture.componentInstance; |
| 90 | + component.fallbackOnDefault = false; |
| 91 | + component.metadata.entityType = 'person'; |
| 92 | + component.metadata.entityStyle = 'personFallback'; |
| 93 | + component.iconPosition = 'before'; |
| 94 | + fixture.detectChanges(); |
| 95 | + }); |
| 96 | + |
| 97 | + it('should not display a text-primary icon', () => { |
| 98 | + const primaryIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i'); |
| 99 | + expect(primaryIcon).toBeFalsy(); |
| 100 | + }); |
| 101 | + }); |
| 102 | + |
| 103 | +}); |
| 104 | + |
105 | 105 | // declare a test component |
106 | 106 | @Component({ |
107 | 107 | selector: 'ds-test-cmp', |
|
112 | 112 | [entityType]="metadata.entityType" |
113 | 113 | [entityStyle]="metadata.entityStyle" |
114 | 114 | [fallbackOnDefault]="fallbackOnDefault">{{ metadata.value }}</span></div>`, |
115 | | - standalone: true, |
116 | 115 | imports: [ |
117 | 116 | EntityIconDirective, |
118 | 117 | ], |
119 | 118 | }) |
120 | | - class TestComponent { |
| 119 | +class TestComponent { |
121 | 120 |
|
122 | 121 | metadata = { |
123 | 122 | authority: null, |
|
0 commit comments