Task Summary
DatasetVersionSelectorComponent (frontend/src/app/workspace/component/dataset-version-selector/dataset-version-selector.component.ts) has no *.spec.ts file. It is a Formly FieldType whose only method, onClickOpenDatasetSelectionModal(), opens an ng-zorro modal and, when the modal closes with a value, writes that value into formControl. Its single dependency is NzModalService, which is easy to stub.
What to do (step by step)
- Create the spec next to the component, with the Apache license header.
- Stub
NzModalService.create to return an object with an afterClose observable you control (use rxjs of(...)).
- Because the component extends
FieldType, set component.field and component.formControl (a FormControl) before calling the method.
- Call
onClickOpenDatasetSelectionModal() and assert behavior.
- Run
yarn test -- dataset-version-selector, then yarn lint.
Cover
should create.
onClickOpenDatasetSelectionModal() calls modalService.create once.
- When
afterClose emits a truthy path, formControl.setValue is called with that path.
- When
afterClose emits a falsy value, formControl is left unchanged.
Suggested providers / mocks
import { of } from "rxjs";
import { FormControl } from "@angular/forms";
import { NzModalService } from "ng-zorro-antd/modal";
const modalServiceSpy = {
create: vi.fn().mockReturnValue({ afterClose: of("/selected/path") }),
};
providers: [{ provide: NzModalService, useValue: modalServiceSpy }]
// in the test, before calling the method:
component.field = {} as any;
(component as any).formControl = new FormControl("");
Sibling component DatasetFileSelectorComponent is nearly identical; the same test
shape applies (see its own draft).
Task Type
Task Summary
DatasetVersionSelectorComponent(frontend/src/app/workspace/component/dataset-version-selector/dataset-version-selector.component.ts) has no*.spec.tsfile. It is a FormlyFieldTypewhose only method,onClickOpenDatasetSelectionModal(), opens an ng-zorro modal and, when the modal closes with a value, writes that value intoformControl. Its single dependency isNzModalService, which is easy to stub.What to do (step by step)
NzModalService.createto return an object with anafterCloseobservable you control (userxjsof(...)).FieldType, setcomponent.fieldandcomponent.formControl(aFormControl) before calling the method.onClickOpenDatasetSelectionModal()and assert behavior.yarn test -- dataset-version-selector, thenyarn lint.Cover
should create.onClickOpenDatasetSelectionModal()callsmodalService.createonce.afterCloseemits a truthy path,formControl.setValueis called with that path.afterCloseemits a falsy value,formControlis left unchanged.Suggested providers / mocks
Task Type