Skip to content

Commit

Permalink
Merge pull request #378 from PermanentOrg/PER-9521-cannot-upload-the-…
Browse files Browse the repository at this point in the history
…same-file-twice
  • Loading branch information
crisnicandrei authored Apr 9, 2024
2 parents 6356f9e + d0869b1 commit c949fd0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import * as Testing from '@root/test/testbedConfig';
import { cloneDeep } from 'lodash';
import { cloneDeep } from 'lodash';

import { DataService } from '@shared/services/data/data.service';
import { FolderVO, ArchiveVO } from '@root/app/models';
Expand Down Expand Up @@ -28,9 +28,11 @@ describe('UploadButtonComponent', () => {

beforeEach(() => {
accountService = TestBed.get(AccountService);
accountService.setArchive(new ArchiveVO({
accessRole: 'access.role.owner'
}));
accountService.setArchive(
new ArchiveVO({
accessRole: 'access.role.owner',
})
);
dataService = TestBed.get(DataService);

fixture = TestBed.createComponent(UploadButtonComponent);
Expand All @@ -49,35 +51,57 @@ describe('UploadButtonComponent', () => {
});

it('should be visible and enabled when current folder is not an apps folder', async () => {
dataService.setCurrentFolder(new FolderVO({
type: 'type.folder.private',
accessRole: 'access.role.owner'
}));
dataService.setCurrentFolder(
new FolderVO({
type: 'type.folder.private',
accessRole: 'access.role.owner',
})
);
await fixture.whenStable();

expect(component.hidden).toBeFalsy();
expect(component.disabled).toBeFalsy();
});

it('should be disabled when current folder is an apps folder', async () => {
dataService.setCurrentFolder(new FolderVO({
accessRole: 'access.role.owner',
type: 'type.folder.app'
}));
dataService.setCurrentFolder(
new FolderVO({
accessRole: 'access.role.owner',
type: 'type.folder.app',
})
);
await fixture.whenStable();

expect(component.hidden).toBeFalsy();
expect(component.disabled).toBeTruthy();
});

it('should be disabled when current folder does not have write access', async () => {
dataService.setCurrentFolder(new FolderVO({
type: 'type.folder.private',
accessRole: 'access.role.viewer'
}));
dataService.setCurrentFolder(
new FolderVO({
type: 'type.folder.private',
accessRole: 'access.role.viewer',
})
);
await fixture.whenStable();

expect(component.hidden).toBeFalsy();
expect(component.disabled).toBeTruthy();
});

it('should reset file input after a file is selected', async () => {
const fileInput =
fixture.debugElement.nativeElement.querySelector('input[type="file"]');

const testFile = new File([''], 'test-file.txt');
const dataTransfer = new DataTransfer();
dataTransfer.items.add(testFile);
fileInput.files = dataTransfer.files;

fileInput.dispatchEvent(new Event('change'));
fixture.detectChanges();
await fixture.whenStable();

expect(fileInput.files.length).toEqual(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export class UploadButtonComponent
this.upload.uploadFiles(this.currentFolder, this.files);
}
}
event.target.value = '';
}

async filePickerClick() {
Expand Down

0 comments on commit c949fd0

Please sign in to comment.