Skip to content

Commit 5667af6

Browse files
committed
fix: fix tests
1 parent 210e28a commit 5667af6

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

projects/wc/src/app/components/generic-ui/value-cell/secret-value/secret-value.component.spec.ts

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('SecretValueComponent', () => {
4040
expect(component.maskedValue()).toBe(
4141
'*'.repeat('my-secret-password'.length),
4242
);
43-
expect(compiled.querySelector('.masked')?.textContent).toBe(
43+
expect(compiled.querySelector('.secret-value')?.textContent?.trim()).toBe(
4444
'*'.repeat('my-secret-password'.length),
4545
);
4646
});
@@ -50,15 +50,19 @@ describe('SecretValueComponent', () => {
5050
const compiled = fixture.nativeElement;
5151

5252
expect(component.maskedValue()).toBe('*'.repeat(8));
53-
expect(compiled.querySelector('.masked')?.textContent).toBe('*'.repeat(8));
53+
expect(compiled.querySelector('.secret-value')?.textContent?.trim()).toBe(
54+
'*'.repeat(8),
55+
);
5456
});
5557

5658
it('should mask short value correctly', () => {
5759
const { component, fixture } = makeComponent('abc');
5860
const compiled = fixture.nativeElement;
5961

6062
expect(component.maskedValue()).toBe('***');
61-
expect(compiled.querySelector('.masked')?.textContent).toBe('***');
63+
expect(compiled.querySelector('.secret-value')?.textContent?.trim()).toBe(
64+
'***',
65+
);
6266
});
6367

6468
it('should mask long value correctly', () => {
@@ -67,7 +71,7 @@ describe('SecretValueComponent', () => {
6771
const compiled = fixture.nativeElement;
6872

6973
expect(component.maskedValue()).toBe('*'.repeat(100));
70-
expect(compiled.querySelector('.masked')?.textContent).toBe(
74+
expect(compiled.querySelector('.secret-value')?.textContent?.trim()).toBe(
7175
'*'.repeat(100),
7276
);
7377
});
@@ -76,11 +80,13 @@ describe('SecretValueComponent', () => {
7680
const { fixture } = makeComponent('secret-value');
7781
const compiled = fixture.nativeElement;
7882

79-
const maskedSpan = compiled.querySelector('.masked');
80-
const originalSpan = compiled.querySelector('.original');
83+
const secretSpan = compiled.querySelector('.secret-value');
8184

82-
expect(maskedSpan).toBeTruthy();
83-
expect(originalSpan).toBeFalsy();
85+
expect(secretSpan).toBeTruthy();
86+
expect(secretSpan?.classList.contains('masked')).toBe(true);
87+
expect(secretSpan?.textContent?.trim()).toBe(
88+
'*'.repeat('secret-value'.length),
89+
);
8490
});
8591

8692
it('should display original value when isVisible is true', () => {
@@ -90,28 +96,30 @@ describe('SecretValueComponent', () => {
9096
fixture.detectChanges();
9197

9298
const compiled = fixture.nativeElement;
93-
const originalSpan = compiled.querySelector('.original');
94-
const maskedSpan = compiled.querySelector('.masked');
99+
const secretSpan = compiled.querySelector('.secret-value');
95100

96-
expect(originalSpan).toBeTruthy();
97-
expect(originalSpan?.textContent).toBe('secret-value');
98-
expect(maskedSpan).toBeFalsy();
101+
expect(secretSpan).toBeTruthy();
102+
expect(secretSpan?.classList.contains('masked')).toBe(false);
103+
expect(secretSpan?.textContent?.trim()).toBe('secret-value');
99104
});
100105

101106
it('should switch from masked to original when isVisible changes', () => {
102107
const { component, fixture } = makeComponent('secret-value');
103108
const compiled = fixture.nativeElement;
109+
const secretSpan = compiled.querySelector('.secret-value');
104110

105111
expect(component.isVisible()).toBe(false);
106-
expect(compiled.querySelector('.masked')).toBeTruthy();
107-
expect(compiled.querySelector('.original')).toBeFalsy();
112+
expect(secretSpan?.classList.contains('masked')).toBe(true);
113+
expect(secretSpan?.textContent?.trim()).toBe(
114+
'*'.repeat('secret-value'.length),
115+
);
108116

109117
fixture.componentRef.setInput('isVisible', true);
110118
fixture.detectChanges();
111119

112120
expect(component.isVisible()).toBe(true);
113-
expect(compiled.querySelector('.original')).toBeTruthy();
114-
expect(compiled.querySelector('.masked')).toBeFalsy();
121+
expect(secretSpan?.classList.contains('masked')).toBe(false);
122+
expect(secretSpan?.textContent?.trim()).toBe('secret-value');
115123
});
116124

117125
it('should switch back to masked when isVisible changes to false', () => {
@@ -125,12 +133,13 @@ describe('SecretValueComponent', () => {
125133
fixture.detectChanges();
126134

127135
const compiled = fixture.nativeElement;
128-
const maskedSpan = compiled.querySelector('.masked');
129-
const originalSpan = compiled.querySelector('.original');
136+
const secretSpan = compiled.querySelector('.secret-value');
130137

131138
expect(component.isVisible()).toBe(false);
132-
expect(maskedSpan).toBeTruthy();
133-
expect(originalSpan).toBeFalsy();
139+
expect(secretSpan?.classList.contains('masked')).toBe(true);
140+
expect(secretSpan?.textContent?.trim()).toBe(
141+
'*'.repeat('secret-value'.length),
142+
);
134143
});
135144

136145
it('should update masked value when input changes', () => {
@@ -156,7 +165,7 @@ describe('SecretValueComponent', () => {
156165

157166
expect(component.isVisible()).toBe(true);
158167
const compiled = fixture.nativeElement;
159-
const originalSpan = compiled.querySelector('.original');
160-
expect(originalSpan?.textContent).toBe('updated-secret');
168+
const secretSpan = compiled.querySelector('.secret-value');
169+
expect(secretSpan?.textContent?.trim()).toBe('updated-secret');
161170
});
162171
});

0 commit comments

Comments
 (0)