|
| 1 | +import { Component } from '@navikt/skjemadigitalisering-shared-domain'; |
1 | 2 | import { componentHasDependencyMatchingFilters, getPropertyFromTarget, targetMatchesFilters } from './filterUtils';
|
2 | 3 | import {
|
3 | 4 | componentWithAdvancedConditionalToRadio,
|
4 | 5 | componentWithSimpleConditionalToRadio,
|
5 | 6 | formWithSimpleConditionalToRadio,
|
| 7 | + originalOtherDocumentationAttachmentComponent, |
6 | 8 | originalTextFieldComponent,
|
7 | 9 | } from './testData';
|
8 | 10 |
|
9 | 11 | describe('filterUtils', () => {
|
10 | 12 | describe('getPropertyFromComponent', () => {
|
11 | 13 | it('gets the value of a property in the object as a string', () => {
|
12 |
| - const actual = getPropertyFromTarget({ value: 'the value' }, ['value']); |
| 14 | + const actual = getPropertyFromTarget({ value: 'the value' } as unknown as Component, ['value']); |
13 | 15 | expect(actual).toBe('the value');
|
14 | 16 | });
|
15 | 17 |
|
16 | 18 | it('gets properties from nested objects', () => {
|
17 |
| - const actual = getPropertyFromTarget({ firstLevel: { secondLevel: { thirdLevel: { value: 'the value' } } } }, [ |
18 |
| - 'firstLevel', |
19 |
| - 'secondLevel', |
20 |
| - 'thirdLevel', |
21 |
| - 'value', |
22 |
| - ]); |
| 19 | + const actual = getPropertyFromTarget( |
| 20 | + { firstLevel: { secondLevel: { thirdLevel: { value: 'the value' } } } } as unknown as Component, |
| 21 | + ['firstLevel', 'secondLevel', 'thirdLevel', 'value'], |
| 22 | + ); |
23 | 23 | expect(actual).toBe('the value');
|
24 | 24 | });
|
25 | 25 | });
|
@@ -70,6 +70,18 @@ describe('filterUtils', () => {
|
70 | 70 | ).toBe(false);
|
71 | 71 | });
|
72 | 72 |
|
| 73 | + it('handles nested properties with three levels', () => { |
| 74 | + expect( |
| 75 | + targetMatchesFilters(originalOtherDocumentationAttachmentComponent, [ |
| 76 | + { |
| 77 | + key: 'attachmentValues.leggerVedNaa.enabled', |
| 78 | + value: null, |
| 79 | + operator: 'exists', |
| 80 | + }, |
| 81 | + ]), |
| 82 | + ).toBe(true); |
| 83 | + }); |
| 84 | + |
73 | 85 | describe('With operators', () => {
|
74 | 86 | const typeEqTextfield = { key: 'type', value: 'textfield' };
|
75 | 87 | const typeEqRadio = { key: 'type', value: 'radio' };
|
|
0 commit comments