Skip to content

Commit

Permalink
Update case-file-view-folder-selector.component.spec.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
olusegz07 committed Nov 27, 2023
1 parent 47067a1 commit 9caacdd
Showing 1 changed file with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatLegacyDialogRef as MatDialogRef, MAT_LEGACY_DIALOG_DATA } from '@angular/material/legacy-dialog';
import { CaseFileViewFolderSelectorComponent } from './case-file-view-folder-selector.component';
import { categoriesAndDocumentsTestData } from '../../test-data/categories-and-documents-test-data';

describe('CaseFileViewFolderSelectorComponent', () => {
let component: CaseFileViewFolderSelectorComponent;
let fixture: ComponentFixture<CaseFileViewFolderSelectorComponent>;
let matDialogRef: jasmine.SpyObj<MatDialogRef<CaseFileViewFolderSelectorComponent>>;

beforeEach(() => {
matDialogRef = jasmine.createSpyObj<MatDialogRef<CaseFileViewFolderSelectorComponent>>('matDialogRef', ['close']);

TestBed.configureTestingModule({
declarations: [CaseFileViewFolderSelectorComponent],
providers: [
{
provide: MatDialogRef,
useValue: matDialogRef
},
{
provide: MAT_LEGACY_DIALOG_DATA,
useValue: { categories: categoriesAndDocumentsTestData.categories, document: categoriesAndDocumentsTestData.categories[0].documents }
}
]
});
fixture = TestBed.createComponent(CaseFileViewFolderSelectorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create the component', () => {
expect(component).toBeTruthy();
});
it('should close the dialog on cancel', () => {
component.cancel();
expect(component.dialogRef.close).toHaveBeenCalled();
});

it('should close the dialog with null on save if selected is empty', () => {
component.selected = '';
component.save();
expect(component.dialogRef.close).toHaveBeenCalledWith(null);
});

it('should select the checkbox and clear lower levels when radio is checked', () => {
const event = {
target: {
checked: true,
id: 'TestId',
name: 'level-2'
}
};

component.handleChange(event);

expect(component.selected).toBe('TestId');

// // Mocking the DOM elements for testing purposes
// document.body.innerHTML = `
// <input class="govuk-radios__input" type="radio" name="level-1" id="cat1" />
// <input class="govuk-radios__input" type="radio" name="level-2" id="someId" />
// <input class="govuk-radios__input" type="radio" name="level-3" id="cat3" />
// `;

// component.handleChange(event);

// // Verify that lower levels are cleared
// expect((document.querySelector('input[name="level-3"]') as HTMLInputElement).checked).toBe(false);
});
});

0 comments on commit 9caacdd

Please sign in to comment.