Skip to content

Commit c1ff4b0

Browse files
committed
fix(files): fixed some issues and updated tests
1 parent 4bec941 commit c1ff4b0

28 files changed

Lines changed: 1161 additions & 141 deletions

src/app/features/files/components/files-tree-explorer/files-tree-explorer.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ <h3 class="font-normal mb-4 text-no-transform">{{ 'files.emptyState' | translate
3939
} @else {
4040
<div class="flex flex-column align-items-center justify-content-center">
4141
<i class="fa-solid fa-cloud-arrow-up text-5xl"></i>
42-
<p class="text-xl">{{ 'files.dropText' | translate }}</p>
42+
<p class="text-xl text-center">{{ 'files.dropText' | translate }}</p>
4343
</div>
4444
}
4545
</div>

src/app/features/files/components/files-tree-explorer/files-tree-explorer.component.spec.ts

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

3-
import { Mock } from 'vitest';
4-
53
import { ComponentFixture, TestBed } from '@angular/core/testing';
64
import { Router } from '@angular/router';
75

@@ -24,6 +22,10 @@ import { FileModelMock } from '@testing/mocks/file.model.mock';
2422
import { provideOSFCore } from '@testing/osf.testing.provider';
2523
import { DataciteServiceMock, DataciteServiceMockType } from '@testing/providers/datacite.service.mock';
2624
import { FilesServiceMock, FilesServiceMockType } from '@testing/providers/files-service.mock';
25+
import {
26+
FilesShareEmbedServiceMock,
27+
FilesShareEmbedServiceMockType,
28+
} from '@testing/providers/files-share-embed-provider.mock';
2729
import { RouterMockBuilder, RouterMockType } from '@testing/providers/router-provider.mock';
2830
import { ViewOnlyLinkHelperMock, ViewOnlyLinkHelperMockType } from '@testing/providers/view-only-link-helper.mock';
2931

@@ -37,10 +39,7 @@ describe('FilesTreeExplorerComponent', () => {
3739
let routerMock: RouterMockType;
3840
let filesService: FilesServiceMockType;
3941
let dataciteService: DataciteServiceMockType;
40-
let filesShareEmbedService: Pick<FilesShareEmbedService, 'getShareLink' | 'copyEmbedToClipboard'> & {
41-
getShareLink: Mock;
42-
copyEmbedToClipboard: Mock;
43-
};
42+
let filesShareEmbedService: FilesShareEmbedServiceMockType;
4443
let viewOnlyHelper: ViewOnlyLinkHelperMockType;
4544

4645
const currentFolder: FileFolderModel = {
@@ -66,10 +65,7 @@ describe('FilesTreeExplorerComponent', () => {
6665
filesService = FilesServiceMock.simple();
6766
dataciteService = DataciteServiceMock.simple();
6867
viewOnlyHelper = ViewOnlyLinkHelperMock.simple(false);
69-
filesShareEmbedService = {
70-
getShareLink: vi.fn(),
71-
copyEmbedToClipboard: vi.fn(),
72-
};
68+
filesShareEmbedService = FilesShareEmbedServiceMock.simple();
7369

7470
TestBed.configureTestingModule({
7571
imports: [

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<div class="flex flex-column gap-2">
1616
<div class="files-table flex flex-column relative">
1717
@if (previousFolder()) {
18-
<div class="files-table-row previous-folder px-3">
18+
<div class="files-table-row px-3">
1919
<p-button
2020
class="link-btn-no-padding w-full h-full"
2121
styleClass="w-full h-full justify-content-start"

src/app/features/files/components/move-file-row/move-file-row.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</div>
1414
} @else {
1515
<p-button
16-
class="filename-link link-btn-no-padding overflow-ellipsis font-normal"
16+
class="filename-link link-btn-no-padding font-normal"
1717
icon="fas fa-folder"
1818
severity="secondary"
1919
[link]="true"

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

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import { MockComponent } from 'ng-mocks';
2+
13
import { ComponentFixture, TestBed } from '@angular/core/testing';
24

5+
import { IconComponent } from '@osf/shared/components/icon/icon.component';
36
import { FileKind } from '@osf/shared/enums/file-kind.enum';
47
import { FileModel } from '@osf/shared/models/files/file.model';
58

9+
import { FileModelMock } from '@testing/mocks/file.model.mock';
610
import { provideOSFCore } from '@testing/osf.testing.provider';
711

812
import { MoveFileRowComponent } from './move-file-row.component';
@@ -11,37 +15,18 @@ describe('MoveFileRowComponent', () => {
1115
let component: MoveFileRowComponent;
1216
let fixture: ComponentFixture<MoveFileRowComponent>;
1317

14-
const createFile = (kind: FileKind, name: string): FileModel => ({
15-
id: `${kind}-id`,
16-
guid: null,
17-
name,
18-
kind,
19-
path: `/${name}`,
20-
size: 1,
21-
materializedPath: `/${name}`,
22-
dateModified: '2026-01-01',
23-
extra: {
24-
hashes: { md5: 'md5', sha256: 'sha256' },
25-
downloads: 0,
26-
},
27-
links: {
28-
info: '/info',
29-
move: '/move',
30-
upload: '/upload',
31-
delete: '/delete',
32-
download: '/download',
33-
render: '/render',
34-
html: '/html',
35-
self: '/self',
36-
},
37-
filesLink: null,
38-
previousFolder: false,
39-
provider: 'osfstorage',
40-
});
18+
const createFile = (kind: FileKind, name: string): FileModel =>
19+
FileModelMock.simple({
20+
id: `${kind}-id`,
21+
name,
22+
kind,
23+
path: `/${name}`,
24+
materializedPath: `/${name}`,
25+
});
4126

42-
const setup = (item: FileModel, isBlocked = false, isIndented = false) => {
27+
function setup(item: FileModel, isBlocked = false, isIndented = false) {
4328
TestBed.configureTestingModule({
44-
imports: [MoveFileRowComponent],
29+
imports: [MoveFileRowComponent, MockComponent(IconComponent)],
4530
providers: [provideOSFCore()],
4631
});
4732

@@ -51,14 +36,14 @@ describe('MoveFileRowComponent', () => {
5136
fixture.componentRef.setInput('isBlocked', isBlocked);
5237
fixture.componentRef.setInput('isIndented', isIndented);
5338
fixture.detectChanges();
54-
};
39+
}
5540

5641
it('should render file row as disabled', () => {
5742
setup(createFile(FileKind.File, 'paper.pdf'));
5843

5944
expect(component.isFile()).toBe(true);
6045
expect(fixture.nativeElement.textContent).toContain('paper.pdf');
61-
expect(fixture.nativeElement.querySelector('.fa-file')).toBeTruthy();
46+
expect(fixture.nativeElement.querySelector('.filename-link.disabled')?.textContent?.trim()).toBe('paper.pdf');
6247
expect(fixture.nativeElement.querySelector('button')).toBeNull();
6348
});
6449

@@ -67,7 +52,8 @@ describe('MoveFileRowComponent', () => {
6752

6853
expect(component.isFile()).toBe(false);
6954
expect(fixture.nativeElement.textContent).toContain('docs');
70-
expect(fixture.nativeElement.querySelector('.fa-folder')).toBeTruthy();
55+
expect(fixture.nativeElement.querySelector('.filename-link.disabled')).toBeNull();
56+
expect(fixture.nativeElement.querySelector('p-button')).toBeNull();
7157
expect(fixture.nativeElement.querySelector('button')).toBeNull();
7258
});
7359

0 commit comments

Comments
 (0)