Skip to content

Commit 2f2a3d6

Browse files
committed
test(confirm-move-file-dialog): fixed tests
1 parent 730b77d commit 2f2a3d6

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
lines changed

src/app/features/files/components/confirm-move-file-dialog/confirm-move-file-dialog.component.spec.ts

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,65 @@
1+
import { TranslatePipe } from '@ngx-translate/core';
2+
import { MockComponents, MockPipe } from 'ng-mocks';
3+
4+
import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog';
5+
6+
import { signal } from '@angular/core';
17
import { ComponentFixture, TestBed } from '@angular/core/testing';
28

9+
import { FileSelectDestinationComponent } from '@osf/shared/components/file-select-destination/file-select-destination.component';
10+
import { IconComponent } from '@osf/shared/components/icon/icon.component';
11+
import { LoadingSpinnerComponent } from '@osf/shared/components/loading-spinner/loading-spinner.component';
12+
import { CustomConfirmationService } from '@osf/shared/services/custom-confirmation.service';
13+
import { FilesService } from '@osf/shared/services/files.service';
14+
import { ToastService } from '@osf/shared/services/toast.service';
15+
16+
import { FilesSelectors } from '../../store';
17+
318
import { ConfirmMoveFileDialogComponent } from './confirm-move-file-dialog.component';
419

5-
describe('ConfirmMoveFileDialogComponent', () => {
20+
import { OSFTestingModule } from '@testing/osf.testing.module';
21+
import { CustomConfirmationServiceMock } from '@testing/providers/custom-confirmation-provider.mock';
22+
import { provideMockStore } from '@testing/providers/store-provider.mock';
23+
import { ToastServiceMock } from '@testing/providers/toast-provider.mock';
24+
25+
describe('ConfirmConfirmMoveFileDialogComponent', () => {
626
let component: ConfirmMoveFileDialogComponent;
727
let fixture: ComponentFixture<ConfirmMoveFileDialogComponent>;
828

29+
const mockFilesService = {
30+
moveFiles: jest.fn(),
31+
getMoveDialogFiles: jest.fn(),
32+
};
33+
934
beforeEach(async () => {
35+
const dialogRefMock = {
36+
close: jest.fn(),
37+
};
38+
39+
const dialogConfigMock = {
40+
data: { files: [], destination: { name: 'files' } },
41+
};
42+
1043
await TestBed.configureTestingModule({
11-
imports: [ConfirmMoveFileDialogComponent],
44+
imports: [
45+
ConfirmMoveFileDialogComponent,
46+
OSFTestingModule,
47+
...MockComponents(IconComponent, LoadingSpinnerComponent, FileSelectDestinationComponent),
48+
MockPipe(TranslatePipe),
49+
],
50+
providers: [
51+
{ provide: DynamicDialogRef, useValue: dialogRefMock },
52+
{ provide: DynamicDialogConfig, useValue: dialogConfigMock },
53+
{ provide: FilesService, useValue: mockFilesService },
54+
{ provide: ToastService, useValue: ToastServiceMock.simple() },
55+
{ provide: CustomConfirmationService, useValue: CustomConfirmationServiceMock.simple() },
56+
provideMockStore({
57+
signals: [
58+
{ selector: FilesSelectors.getMoveDialogFiles, value: signal([]) },
59+
{ selector: FilesSelectors.getProvider, value: signal(null) },
60+
],
61+
}),
62+
],
1263
}).compileComponents();
1364

1465
fixture = TestBed.createComponent(ConfirmMoveFileDialogComponent);
@@ -19,4 +70,14 @@ describe('ConfirmMoveFileDialogComponent', () => {
1970
it('should create', () => {
2071
expect(component).toBeTruthy();
2172
});
73+
74+
it('should initialize with correct properties', () => {
75+
expect(component.config).toBeDefined();
76+
expect(component.dialogRef).toBeDefined();
77+
expect(component.files).toBeDefined();
78+
});
79+
80+
it('should get files from store', () => {
81+
expect(component.files()).toEqual([]);
82+
});
2283
});

src/app/features/files/components/confirm-move-file-dialog/confirm-move-file-dialog.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { FilesSelectors } from '@osf/features/files/store';
1616
import { CustomConfirmationService } from '@osf/shared/services/custom-confirmation.service';
1717
import { FilesService } from '@osf/shared/services/files.service';
1818
import { ToastService } from '@osf/shared/services/toast.service';
19-
import { CurrentResourceSelectors } from '@osf/shared/stores/current-resource';
2019
import { FileMenuType } from '@shared/enums/file-menu-type.enum';
2120
import { FileModel } from '@shared/models/files/file.model';
2221

@@ -37,7 +36,6 @@ export class ConfirmMoveFileDialogComponent {
3736
private readonly customConfirmationService = inject(CustomConfirmationService);
3837

3938
readonly files = select(FilesSelectors.getMoveDialogFiles);
40-
readonly currentProject = select(CurrentResourceSelectors.getCurrentResource);
4139
readonly provider = select(FilesSelectors.getProvider);
4240

4341
private fileProjectId = this.config.data.resourceId;

src/app/shared/components/files-tree/files-tree.component.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { MockComponents, MockProvider } from 'ng-mocks';
22

3+
import { TreeDragDropService } from 'primeng/api';
34
import { DialogService } from 'primeng/dynamicdialog';
45

56
import { signal } from '@angular/core';
@@ -53,6 +54,7 @@ describe('FilesTreeComponent', () => {
5354
MockProvider(ToastService),
5455
MockProvider(CustomConfirmationService),
5556
MockProvider(DialogService),
57+
TreeDragDropService,
5658
],
5759
}).compileComponents();
5860

0 commit comments

Comments
 (0)