|
| 1 | +import { BooleanValueComponent } from './boolean-value/boolean-value.component'; |
| 2 | +import { LinkValueComponent } from './link-value/link-value.component'; |
| 3 | +import { SecretValueComponent } from './secret-value/secret-value.component'; |
1 | 4 | import { ValueCellComponent } from './value-cell.component'; |
2 | 5 | import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; |
3 | 6 | import { ComponentFixture, TestBed } from '@angular/core/testing'; |
@@ -50,7 +53,15 @@ describe('ValueCellComponent', () => { |
50 | 53 | beforeEach(() => { |
51 | 54 | TestBed.configureTestingModule({ |
52 | 55 | imports: [ValueCellComponent], |
53 | | - schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 56 | + }).overrideComponent(ValueCellComponent, { |
| 57 | + set: { |
| 58 | + imports: [ |
| 59 | + BooleanValueComponent, |
| 60 | + LinkValueComponent, |
| 61 | + SecretValueComponent, |
| 62 | + ], |
| 63 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 64 | + }, |
54 | 65 | }); |
55 | 66 | }); |
56 | 67 |
|
@@ -164,82 +175,49 @@ describe('ValueCellComponent', () => { |
164 | 175 | }); |
165 | 176 |
|
166 | 177 | describe('labelDisplay functionality', () => { |
167 | | - it('should render label-value component when labelDisplay is an object', () => { |
| 178 | + it('should apply label styles when labelDisplay is an object', () => { |
168 | 179 | const labelDisplay = { backgroundColor: '#ffffff', color: '#000000' }; |
169 | 180 | const { fixture } = makeComponent('test-value', { |
170 | 181 | uiSettings: { labelDisplay }, |
171 | 182 | }); |
172 | 183 | const compiled = fixture.nativeElement; |
| 184 | + const span = compiled.querySelector('span'); |
173 | 185 |
|
174 | | - expect(compiled.querySelector('wc-label-value')).toBeTruthy(); |
175 | | - expect(component.isLabelValue()).toBe(true); |
176 | | - expect(component.labelDisplayValue()).toEqual(labelDisplay); |
| 186 | + expect(span.classList.contains('label-value')).toBe(true); |
| 187 | + expect(component.labelDisplay()).toEqual(labelDisplay); |
177 | 188 | }); |
178 | 189 |
|
179 | | - it('should render label-value component when labelDisplay is true', () => { |
| 190 | + it('should apply label-value class when labelDisplay is true', () => { |
180 | 191 | const { fixture } = makeComponent('test-value', { |
181 | 192 | uiSettings: { labelDisplay: true }, |
182 | 193 | }); |
183 | 194 | const compiled = fixture.nativeElement; |
| 195 | + const span = compiled.querySelector('span'); |
184 | 196 |
|
185 | | - expect(compiled.querySelector('wc-label-value')).toBeTruthy(); |
186 | | - expect(component.isLabelValue()).toBe(true); |
187 | | - expect(component.labelDisplayValue()).toEqual({}); |
| 197 | + expect(span.classList.contains('label-value')).toBe(true); |
| 198 | + expect(component.labelDisplay()).toEqual({}); |
188 | 199 | }); |
189 | 200 |
|
190 | | - it('should not render label-value component when labelDisplay is false', () => { |
| 201 | + it('should not apply label-value class when labelDisplay is false', () => { |
191 | 202 | const { fixture } = makeComponent('test-value', { |
192 | 203 | uiSettings: { labelDisplay: false }, |
193 | 204 | }); |
194 | 205 | const compiled = fixture.nativeElement; |
| 206 | + const span = compiled.querySelector('span'); |
195 | 207 |
|
196 | | - expect(compiled.querySelector('wc-label-value')).toBeFalsy(); |
197 | | - expect(component.isLabelValue()).toBe(false); |
198 | | - expect(component.labelDisplayValue()).toBeUndefined(); |
| 208 | + expect(span.classList.contains('label-value')).toBe(false); |
| 209 | + expect(component.labelDisplay()).toBeUndefined(); |
199 | 210 | }); |
200 | 211 |
|
201 | | - it('should not render label-value component when labelDisplay is undefined', () => { |
| 212 | + it('should not apply label-value class when labelDisplay is undefined', () => { |
202 | 213 | const { fixture } = makeComponent('test-value', { |
203 | 214 | uiSettings: { labelDisplay: undefined }, |
204 | 215 | }); |
205 | 216 | const compiled = fixture.nativeElement; |
| 217 | + const span = compiled.querySelector('span'); |
206 | 218 |
|
207 | | - expect(compiled.querySelector('wc-label-value')).toBeFalsy(); |
208 | | - expect(component.isLabelValue()).toBe(false); |
209 | | - expect(component.labelDisplayValue()).toBeUndefined(); |
210 | | - }); |
211 | | - |
212 | | - it('should not render label-value component when labelDisplay is null', () => { |
213 | | - const { fixture } = makeComponent('test-value', { |
214 | | - uiSettings: { labelDisplay: null as any }, |
215 | | - }); |
216 | | - const compiled = fixture.nativeElement; |
217 | | - |
218 | | - expect(compiled.querySelector('wc-label-value')).toBeFalsy(); |
219 | | - expect(component.isLabelValue()).toBe(false); |
220 | | - expect(component.labelDisplayValue()).toBeUndefined(); |
221 | | - }); |
222 | | - |
223 | | - it('should render label-value component when labelDisplay is a string', () => { |
224 | | - const { fixture } = makeComponent('test-value', { |
225 | | - uiSettings: { labelDisplay: 'some-string' as any }, |
226 | | - }); |
227 | | - const compiled = fixture.nativeElement; |
228 | | - |
229 | | - expect(compiled.querySelector('wc-label-value')).toBeTruthy(); |
230 | | - expect(component.isLabelValue()).toBe(true); |
231 | | - expect(component.labelDisplayValue()).toEqual({}); |
232 | | - }); |
233 | | - |
234 | | - it('should render label-value component when labelDisplay is a number', () => { |
235 | | - const { fixture } = makeComponent('test-value', { |
236 | | - uiSettings: { labelDisplay: 42 as any }, |
237 | | - }); |
238 | | - const compiled = fixture.nativeElement; |
239 | | - |
240 | | - expect(compiled.querySelector('wc-label-value')).toBeTruthy(); |
241 | | - expect(component.isLabelValue()).toBe(true); |
242 | | - expect(component.labelDisplayValue()).toEqual({}); |
| 219 | + expect(span.classList.contains('label-value')).toBe(false); |
| 220 | + expect(component.labelDisplay()).toBeUndefined(); |
243 | 221 | }); |
244 | 222 | }); |
245 | 223 |
|
@@ -355,7 +333,6 @@ describe('ValueCellComponent', () => { |
355 | 333 |
|
356 | 334 | expect(compiled.querySelector('wc-boolean-value')).toBeFalsy(); |
357 | 335 | expect(compiled.querySelector('wc-link-value')).toBeFalsy(); |
358 | | - expect(compiled.querySelector('wc-label-value')).toBeFalsy(); |
359 | 336 | expect(compiled.querySelector('wc-secret-value')).toBeFalsy(); |
360 | 337 | expect(compiled.textContent.trim()).toContain('test-value'); |
361 | 338 | }); |
@@ -657,51 +634,18 @@ describe('ValueCellComponent', () => { |
657 | 634 |
|
658 | 635 | expect(compiled.querySelector('wc-boolean-value')).toBeTruthy(); |
659 | 636 | expect(compiled.querySelector('wc-link-value')).toBeFalsy(); |
660 | | - expect(compiled.querySelector('wc-label-value')).toBeFalsy(); |
661 | | - }); |
662 | | - |
663 | | - it('should prioritize boolean over label when both are valid', () => { |
664 | | - const { fixture } = makeComponent('true', { |
665 | | - uiSettings: { labelDisplay: { backgroundColor: '#ffffff' } }, |
666 | | - }); |
667 | | - const compiled = fixture.nativeElement; |
668 | | - |
669 | | - expect(compiled.querySelector('wc-boolean-value')).toBeTruthy(); |
670 | | - expect(compiled.querySelector('wc-link-value')).toBeFalsy(); |
671 | | - expect(compiled.querySelector('wc-label-value')).toBeFalsy(); |
672 | | - }); |
673 | | - |
674 | | - it('should prioritize URL over label when both are valid', () => { |
675 | | - const { fixture } = makeComponent('https://example.com', { |
676 | | - uiSettings: { labelDisplay: { backgroundColor: '#ffffff' } }, |
677 | | - }); |
678 | | - const compiled = fixture.nativeElement; |
679 | | - |
680 | | - expect(compiled.querySelector('wc-boolean-value')).toBeFalsy(); |
681 | | - expect(compiled.querySelector('wc-link-value')).toBeTruthy(); |
682 | | - expect(compiled.querySelector('wc-label-value')).toBeFalsy(); |
683 | | - }); |
684 | | - |
685 | | - it('should render label when boolean and URL are not valid but labelDisplay is provided', () => { |
686 | | - const { fixture } = makeComponent('some-text', { |
687 | | - uiSettings: { labelDisplay: { backgroundColor: '#ffffff' } }, |
688 | | - }); |
689 | | - const compiled = fixture.nativeElement; |
690 | | - |
691 | | - expect(compiled.querySelector('wc-boolean-value')).toBeFalsy(); |
692 | | - expect(compiled.querySelector('wc-link-value')).toBeFalsy(); |
693 | | - expect(compiled.querySelector('wc-label-value')).toBeTruthy(); |
694 | 637 | }); |
695 | 638 |
|
696 | 639 | it('should render plain text when no special rendering is needed', () => { |
697 | 640 | const { fixture } = makeComponent('some-text', { |
698 | 641 | uiSettings: { labelDisplay: false }, |
699 | 642 | }); |
700 | 643 | const compiled = fixture.nativeElement; |
| 644 | + const span = compiled.querySelector('span'); |
701 | 645 |
|
702 | 646 | expect(compiled.querySelector('wc-boolean-value')).toBeFalsy(); |
703 | 647 | expect(compiled.querySelector('wc-link-value')).toBeFalsy(); |
704 | | - expect(compiled.querySelector('wc-label-value')).toBeFalsy(); |
| 648 | + expect(span.classList.contains('label-value')).toBe(false); |
705 | 649 | expect(compiled.textContent.trim()).toBe('some-text'); |
706 | 650 | }); |
707 | 651 | }); |
|
0 commit comments