Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DataService } from '@shared/services/data/data.service';
import { EditService } from '@core/services/edit/edit.service';
import { AccountService } from '@shared/services/account/account.service';
import { ArchiveVO, RecordVO } from '@models/index';
import { ArchiveVO, FolderVO, RecordVO } from '@models/index';
import { GetThumbnailPipe } from '@shared/pipes/get-thumbnail.pipe';
import { BehaviorSubject, Subject } from 'rxjs';
import { DateTimeModel } from '@shared/services/edtf-service/edtf.service';
Expand Down Expand Up @@ -655,4 +655,45 @@ describe('SidebarComponent', () => {
expect(saveSpy).not.toHaveBeenCalled();
});
});

describe('current folder full-data fetch', () => {
const originalCurrentFolder = mockDataService.currentFolder;
let fetchFullItemsSpy: jasmine.Spy;

beforeEach(() => {
fetchFullItemsSpy = spyOn(mockDataService, 'fetchFullItems');
});

afterEach(() => {
mockDataService.currentFolder = originalCurrentFolder;
});

it('should not fetch a synthetic root folder that has no folderId', async () => {
mockDataService.currentFolder = new FolderVO({
displayName: 'Shares',
pathAsText: ['Shares'],
type: 'type.folder.root.share',
ChildItemVOs: [],
});

selectedItemsSubject.next(new Set());
await fixture.whenStable();

expect(fetchFullItemsSpy).not.toHaveBeenCalled();
});

it('should fetch the current folder when it has a folderId and no displayTime', async () => {
mockDataService.currentFolder = new FolderVO({
folderId: 42,
type: 'type.folder.private',
});

selectedItemsSubject.next(new Set());
await fixture.whenStable();

expect(fetchFullItemsSpy).toHaveBeenCalledWith([
mockDataService.currentFolder,
]);
});
});
});
5 changes: 4 additions & 1 deletion src/app/file-browser/components/sidebar/sidebar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,11 @@ export class SidebarComponent implements OnDestroy, HasSubscriptions {
this.isLoading = false;
}
} else if (
// Synthetic root folders (e.g. the Shares workspace) have no
// folderId, so there is nothing to fetch for them.
this.selectedItem?.isFolder &&
!this.selectedItem?.displayTime
this.selectedItem.folderId &&
!this.selectedItem.displayTime
) {
await this.dataService.fetchFullItems([this.selectedItem]);
}
Expand Down
22 changes: 22 additions & 0 deletions src/app/shared/services/api/folder.repo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,5 +372,27 @@ describe('Folder repo', () => {

expect(folders[0]).toBeDefined();
});

it('should not issue a request when no folder has a folderId', async () => {
const syntheticFolder = new FolderVO({ type: 'type.folder.root.share' });

const result = await folderRepo.getStelaFolderVOs([syntheticFolder]);

expect(httpV2Spy.get).not.toHaveBeenCalled();
expect(result.getFolderVOs().length).toBe(0);
});

it('should query only the folders that have a folderId', async () => {
const folderWithId = new FolderVO({ folderId: 123 });
const folderWithoutId = new FolderVO({ type: 'type.folder.root.share' });

httpV2Spy.get.and.returnValue(of([{ items: [mockStelaFolder] }]));

await folderRepo.getStelaFolderVOs([folderWithId, folderWithoutId]);

expect(httpV2Spy.get).toHaveBeenCalledWith('v2/folder', {
folderIds: [123],
});
});
});
});
8 changes: 7 additions & 1 deletion src/app/shared/services/api/folder.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,14 @@ export class FolderRepo extends BaseRepo {
folderVOs: FolderVO[],
shareToken: string = null,
): Promise<StelaFolder[]> {
const validFolderIds = folderVOs
.map((currentFolder) => currentFolder.folderId)
.filter((folderId) => folderId != null);
if (!validFolderIds.length) {
return [];
}
const queryData = {
folderIds: folderVOs.map((currentFolder) => currentFolder.folderId),
folderIds: validFolderIds,
};
let folderResponse: PagedStelaResponse<StelaFolder>;
if (shareToken) {
Expand Down