Skip to content

Add unit tests for DatasetFileSelectorComponent #5471

@Ma77Ball

Description

@Ma77Ball

Task Summary

DatasetFileSelectorComponent (frontend/src/app/workspace/component/dataset-file-selector/dataset-file-selector.component.ts) has no *.spec.ts file. It is a Formly FieldType whose only method, onClickOpenFileSelectionModal(), opens an ng-zorro modal and writes the chosen path back into formControl when the modal closes with a value. It injects NzModalService, WorkflowActionService, and GuiConfigService.

What to do (step by step)

  1. Create the spec next to the component, with the Apache license header.
  2. Stub the three injected services. Only NzModalService.create needs real behavior (return { afterClose: of("/path") }); the others can be empty vi.fn() stubs unless the method reads from them, in which case provide the minimal fields it uses.
  3. Because the component extends FieldType, set component.field and component.formControl (a FormControl) before calling the method.
  4. Assert behavior, run yarn test -- dataset-file-selector, then yarn lint.

Cover

  • should create.
  • onClickOpenFileSelectionModal() calls modalService.create once.
  • When afterClose emits a truthy path, formControl.setValue is called with it.
  • When afterClose emits a falsy value, formControl is unchanged.

Suggested providers / mocks

import { of } from "rxjs";
import { FormControl } from "@angular/forms";
import { NzModalService } from "ng-zorro-antd/modal";
import { WorkflowActionService } from "src/app/workspace/service/workflow-graph/model/workflow-action.service";
import { GuiConfigService } from "src/app/common/service/gui-config.service";

const modalServiceSpy = { create: vi.fn().mockReturnValue({ afterClose: of("/path") }) };
providers: [
  { provide: NzModalService, useValue: modalServiceSpy },
  { provide: WorkflowActionService, useValue: {} },
  { provide: GuiConfigService, useValue: {} },
]

This mirrors DatasetVersionSelectorComponent. Read the method body to confirm which
service fields it actually reads and keep the stubs minimal.

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