Skip to content

Commit 9015369

Browse files
committed
test: add password input tests
Signed-off-by: Akshat Patel <[email protected]>
1 parent e47d329 commit 9015369

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

src/input/password.spec.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { TestBed, ComponentFixture } from "@angular/core/testing";
2+
import { Component, DebugElement } from "@angular/core";
3+
import { By } from "@angular/platform-browser";
4+
5+
import { PasswordInputLabelComponent, PasswordInput } from "./";
6+
import { Tooltip } from "../tooltip";
7+
8+
@Component({
9+
template: `
10+
<cds-password-label>
11+
Password
12+
<input
13+
cdsPassword
14+
type="password">
15+
</cds-password-label>
16+
`
17+
})
18+
class TestPasswordInputComponent {}
19+
20+
fdescribe("Password", () => {
21+
let fixture: ComponentFixture<TestPasswordInputComponent>;
22+
let component: TestPasswordInputComponent;
23+
let passwordEl: DebugElement;
24+
25+
beforeEach(() => {
26+
TestBed.configureTestingModule({
27+
declarations: [PasswordInputLabelComponent, PasswordInput, Tooltip, TestPasswordInputComponent]
28+
});
29+
fixture = TestBed.createComponent(TestPasswordInputComponent);
30+
component = fixture.componentInstance;
31+
fixture.detectChanges();
32+
passwordEl = fixture.debugElement.query(By.css("cds-password-label"));
33+
});
34+
35+
it("should create a password component", () => {
36+
expect(component).toBeTruthy();
37+
expect(passwordEl).not.toBeNull();
38+
});
39+
40+
it("should assign wrapper classes to the host element", () => {
41+
expect(passwordEl.nativeElement.classList.contains("cds--form-item")).toBeTruthy();
42+
expect(passwordEl.nativeElement.classList.contains("cds--password-input-wrapper")).toBeTruthy();
43+
expect(passwordEl.nativeElement.classList.contains("cds--text-input-wrapper")).toBeTruthy();
44+
});
45+
46+
it("should set initial input type to 'password'", () => {
47+
expect(passwordEl.nativeElement.querySelector("input[type='password']")).not.toBeNull();
48+
});
49+
50+
it("should set input type to 'text' when toggle button is clicked", () => {
51+
const visibilityToggleButton = passwordEl.nativeElement.querySelector("button.cds--text-input--password__visibility__toggle");
52+
visibilityToggleButton.click();
53+
fixture.detectChanges();
54+
expect(passwordEl.nativeElement.querySelector("input[type='password']")).toBeNull();
55+
expect(passwordEl.nativeElement.querySelector("input[type='text']")).not.toBeNull();
56+
});
57+
});

0 commit comments

Comments
 (0)