Skip to content

Commit 9fed9f4

Browse files
committed
test(form-select): coverage
1 parent 07c5cd7 commit 9fed9f4

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,67 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { Component, ComponentRef, DebugElement, input } from '@angular/core';
13
import { FormSelectDirective } from './form-select.directive';
2-
import { TestBed } from '@angular/core/testing';
4+
import { By } from '@angular/platform-browser';
5+
6+
@Component({
7+
imports: [FormSelectDirective],
8+
template: ` <select cSelect [sizing]="sizing()" [valid]="valid()"></select> `
9+
})
10+
class TestComponent {
11+
readonly sizing = input<'' | 'sm' | 'lg' | string>();
12+
readonly valid = input<boolean>();
13+
}
314

415
describe('FormSelectDirective', () => {
16+
let component: TestComponent;
17+
let fixture: ComponentFixture<TestComponent>;
18+
let debugElement: DebugElement;
19+
let componentRef: ComponentRef<TestComponent>;
20+
21+
beforeEach(() => {
22+
TestBed.configureTestingModule({
23+
imports: [TestComponent]
24+
}).compileComponents();
25+
26+
fixture = TestBed.createComponent(TestComponent);
27+
component = fixture.componentInstance;
28+
componentRef = fixture.componentRef;
29+
debugElement = fixture.debugElement.query(By.directive(FormSelectDirective));
30+
fixture.detectChanges();
31+
});
32+
533
it('should create an instance', () => {
634
TestBed.runInInjectionContext(() => {
735
const directive = new FormSelectDirective();
836
expect(directive).toBeTruthy();
937
});
1038
});
39+
40+
it('should have css classes', () => {
41+
expect(debugElement.nativeElement).toHaveClass('form-select');
42+
componentRef.setInput('sizing', 'sm');
43+
fixture.detectChanges();
44+
expect(debugElement.nativeElement).toHaveClass('form-select-sm');
45+
componentRef.setInput('sizing', 'lg');
46+
fixture.detectChanges();
47+
expect(debugElement.nativeElement).toHaveClass('form-select-lg');
48+
componentRef.setInput('sizing', '');
49+
fixture.detectChanges();
50+
expect(debugElement.nativeElement).not.toHaveClass('form-select-sm');
51+
expect(debugElement.nativeElement).not.toHaveClass('form-select-lg');
52+
expect(debugElement.nativeElement).not.toHaveClass('is-invalid');
53+
expect(debugElement.nativeElement).not.toHaveClass('is-valid');
54+
componentRef.setInput('valid', true);
55+
fixture.detectChanges();
56+
expect(debugElement.nativeElement).not.toHaveClass('is-invalid');
57+
expect(debugElement.nativeElement).toHaveClass('is-valid');
58+
componentRef.setInput('valid', false);
59+
fixture.detectChanges();
60+
expect(debugElement.nativeElement).toHaveClass('is-invalid');
61+
expect(debugElement.nativeElement).not.toHaveClass('is-valid');
62+
componentRef.setInput('valid', undefined);
63+
fixture.detectChanges();
64+
expect(debugElement.nativeElement).not.toHaveClass('is-invalid');
65+
expect(debugElement.nativeElement).not.toHaveClass('is-valid');
66+
});
1167
});

0 commit comments

Comments
 (0)