Skip to content

Add unit tests for DatasetVersionSelectorComponent #5470

@Ma77Ball

Description

@Ma77Ball

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)

  1. Create the spec next to the component, with the Apache license header.
  2. Stub NzModalService.create to return an object with an afterClose observable you control (use rxjs of(...)).
  3. Because the component extends FieldType, set component.field and component.formControl (a FormControl) before calling the method.
  4. Call onClickOpenDatasetSelectionModal() and assert behavior.
  5. 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

  • Refactor / Cleanup
  • DevOps / Deployment / CI
  • Testing / QA
  • Documentation
  • Performance
  • Other

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions