Created
May 16, 2018 23:54
-
-
Save glendaviesnz/fc8e99b41f0dda8b1c0dc4d397e0d152 to your computer and use it in GitHub Desktop.
Helper for testing Angular Material Select Menu changes in Unit Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ComponentFixture, TestBed, async, inject, fakeAsync, flush } from '@angular/core/testing'; | |
import { | |
MatCheckboxModule, | |
MatSelectModule | |
} from '@angular/material'; | |
import { By } from '@angular/platform-browser'; | |
import { SelectMenuTestHelper } from './select-menu-test.helper'; | |
describe('SelectOptionComponent', () => { | |
let component: SelectOptionComponent; | |
let fixture: ComponentFixture<SelectOptionComponent>; | |
beforeEach(() => { | |
TestBed.configureTestingModule({ | |
declarations: [ | |
SelectOptionComponent | |
], | |
imports: [ | |
MatCheckboxModule, | |
MatSelectModule, | |
BrowserAnimationsModule | |
] | |
}).compileComponents(); | |
}); | |
beforeEach(async(() => { | |
fixture = TestBed.createComponent(SelectOptionComponent); | |
component = fixture.componentInstance; | |
fixture.detectChanges(); | |
})); | |
it('should be created', () => { | |
expect(component).toBeTruthy(); | |
}); | |
describe('Select Menu changes', () => { | |
let options: HTMLElement[]; | |
let selectMenu: SelectMenuTestHelper; | |
beforeEach(() => { | |
selectMenu = new SelectMenuTestHelper(fixture); | |
component.users = [ | |
{ id: randomId(), displayName: 'User1' } | |
]; | |
}); | |
beforeEach(fakeAsync(() => { | |
selectMenu.triggerMenu(); | |
options = selectMenu.getOptions(); | |
})); | |
afterEach(() => { | |
selectMenu.cleanup(); | |
}); | |
it('should disable user check boxes if user security option inherit is selected', fakeAsync(() => { | |
options.forEach((option: HTMLElement) => { | |
selectMenu.selectOption(option); | |
const checked = fixture.debugElement.query(By.css('.mat-checkbox-input')).nativeElement; | |
if (option.innerText.trim() === 'security.inherit') { | |
expect(checked.disabled).toEqual(true); | |
} else { | |
expect(checked.disabled).toEqual(false); | |
} | |
}); | |
})); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment