mirror of
https://github.com/bec-project/bec_atlas.git
synced 2025-07-13 22:51:49 +02:00
test: add test for dialog component
This commit is contained in:
@ -7,11 +7,17 @@ import {
|
||||
MatDialogRef,
|
||||
} from '@angular/material/dialog';
|
||||
|
||||
import { MatCheckboxChange } from '@angular/material/checkbox';
|
||||
|
||||
describe('ColumnSelectionDialogComponent', () => {
|
||||
let component: ColumnSelectionDialogComponent;
|
||||
let fixture: ComponentFixture<ColumnSelectionDialogComponent>;
|
||||
let dialogRefSpy: jasmine.SpyObj<MatDialogRef<ColumnSelectionDialogComponent>>;
|
||||
|
||||
beforeEach(async () => {
|
||||
|
||||
dialogRefSpy = jasmine.createSpyObj<MatDialogRef<ColumnSelectionDialogComponent>>(['close']);
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
providers: [
|
||||
{
|
||||
@ -23,7 +29,7 @@ describe('ColumnSelectionDialogComponent', () => {
|
||||
},
|
||||
{
|
||||
provide: MatDialogRef,
|
||||
useValue: {},
|
||||
useValue: dialogRefSpy,
|
||||
},
|
||||
],
|
||||
imports: [ColumnSelectionDialogComponent, MatDialogModule],
|
||||
@ -37,4 +43,33 @@ describe('ColumnSelectionDialogComponent', () => {
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should update the selected columns', () => {
|
||||
component.columns = [
|
||||
{ name: 'column1', selected: true },
|
||||
{ name: 'column2', selected: false },
|
||||
];
|
||||
let checkbox_changed = new MatCheckboxChange();
|
||||
checkbox_changed.checked = true;
|
||||
component.handleCheckboxChecked(checkbox_changed, 1);
|
||||
expect(component.columns).toEqual([
|
||||
{ name: 'column1', selected: true },
|
||||
{ name: 'column2', selected: true },
|
||||
]);
|
||||
});
|
||||
|
||||
it('should close dialog on cancel, no data', () => {
|
||||
component.onCancelClick();
|
||||
expect(dialogRefSpy.close).toHaveBeenCalledWith(null);
|
||||
});
|
||||
|
||||
it('should close dialog on apply, with data', () => {
|
||||
component.columns = [
|
||||
{ name: 'column1', selected: true },
|
||||
{ name: 'column2', selected: false },
|
||||
];
|
||||
component.onApplyClick();
|
||||
expect(dialogRefSpy.close).toHaveBeenCalledWith(['column1']);
|
||||
});
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user