-
Notifications
You must be signed in to change notification settings - Fork 2
[PER-10679] Replace navigateLean with getWithChildren for the timeline view #1138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
30cc0a1
Add missing fields to stela objects and extra lookout for folder
aasandei-vsp 28d9d8a
Update the lean folder response with getWithChildren and handle error
aasandei-vsp 86de307
Update the timeline navigation to getWithChildren and the unit testing
aasandei-vsp 13fb2e7
Normalize the Stela breadcrumb paths and the deep-link identifier
aasandei-vsp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
211 changes: 211 additions & 0 deletions
211
src/app/core/resolves/lean-folder-resolve.service.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,211 @@ | ||
| import { TestBed } from '@angular/core/testing'; | ||
| import * as Testing from '@root/test/testbedConfig'; | ||
| import { cloneDeep } from 'lodash'; | ||
| import { Router } from '@angular/router'; | ||
|
|
||
| import { LeanFolderResolveService } from '@core/resolves/lean-folder-resolve.service'; | ||
| import { ApiService } from '@shared/services/api/api.service'; | ||
| import { AccountService } from '@shared/services/account/account.service'; | ||
| import { FolderResponse } from '@shared/services/api/folder.repo'; | ||
| import { FolderVO } from '@models/index'; | ||
| import { | ||
| MessageDisplayOptions, | ||
| MessageService, | ||
| } from '@shared/services/message/message.service'; | ||
|
|
||
| const buildFolderResponse = (folderData: Record<string, unknown>) => | ||
| new FolderResponse({ | ||
| isSuccessful: true, | ||
| Results: [{ data: [{ FolderVO: { ChildItemVOs: [], ...folderData } }] }], | ||
| }); | ||
|
|
||
| describe('LeanFolderResolveService', () => { | ||
| let service: LeanFolderResolveService; | ||
| let api: ApiService; | ||
| let accountService: AccountService; | ||
| let message: MessageService; | ||
| let router: Router; | ||
|
|
||
| beforeEach(() => { | ||
| const config = cloneDeep(Testing.BASE_TEST_CONFIG); | ||
| config.providers.push(LeanFolderResolveService); | ||
| TestBed.configureTestingModule(config); | ||
|
|
||
| service = TestBed.inject(LeanFolderResolveService); | ||
| api = TestBed.inject(ApiService); | ||
| accountService = TestBed.inject(AccountService); | ||
| message = TestBed.inject(MessageService); | ||
| router = TestBed.inject(Router); | ||
|
|
||
| spyOn(accountService, 'getRootFolder').and.returnValue( | ||
| new FolderVO({ | ||
| ChildItemVOs: [ | ||
| new FolderVO({ | ||
| folderId: '11', | ||
| type: 'type.folder.root.private', | ||
| archiveNbr: '0001-0001', | ||
| }), | ||
| new FolderVO({ | ||
| folderId: '22', | ||
| type: 'type.folder.root.app', | ||
| archiveNbr: '0001-0002', | ||
| }), | ||
| ], | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('should be created', () => { | ||
| expect(service).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should load My Files by default', async () => { | ||
| const getSpy = spyOn( | ||
| api.folder, | ||
| 'getWithChildrenByIdentifier', | ||
| ).and.resolveTo(buildFolderResponse({ displayName: 'My Files' })); | ||
|
|
||
| const result = await service.resolve( | ||
| { params: {} } as any, | ||
| { url: '/private' } as any, | ||
| ); | ||
|
|
||
| expect(getSpy).toHaveBeenCalled(); | ||
| expect(getSpy.calls.mostRecent().args[0].folderId).toBe('11'); | ||
| expect(result.displayName).toBe('My Files'); | ||
| }); | ||
|
|
||
| it('should load the apps folder on /apps', async () => { | ||
| const getSpy = spyOn( | ||
| api.folder, | ||
| 'getWithChildrenByIdentifier', | ||
| ).and.resolveTo(buildFolderResponse({ displayName: 'Apps' })); | ||
|
|
||
| await service.resolve({ params: {} } as any, { url: '/apps' } as any); | ||
|
|
||
| expect(getSpy.calls.mostRecent().args[0].folderId).toBe('22'); | ||
| }); | ||
|
|
||
| it('should pass the route identifiers through for a deep link', async () => { | ||
| const getSpy = spyOn( | ||
| api.folder, | ||
| 'getWithChildrenByIdentifier', | ||
| ).and.resolveTo(buildFolderResponse({ displayName: 'Deep Linked' })); | ||
|
|
||
| const result = await service.resolve( | ||
| { params: { archiveNbr: '0001-0005', folderLinkId: '99' } } as any, | ||
| { url: '/view/timeline/0001-0005/99' } as any, | ||
| ); | ||
|
|
||
| const requestedFolder = getSpy.calls.mostRecent().args[0]; | ||
|
|
||
| expect(requestedFolder.archiveNbr).toBe('0001-0005'); | ||
| expect(requestedFolder.folder_linkId).toBe(99); | ||
| expect(requestedFolder.folderId).toBeUndefined(); | ||
| expect(result.displayName).toBe('Deep Linked'); | ||
| }); | ||
|
|
||
| it('should splice share crumbs onto a shared record without calling the API', async () => { | ||
| const getSpy = spyOn(api.folder, 'getWithChildrenByIdentifier'); | ||
| const sharedRecord = { displayName: 'A shared photo' }; | ||
|
|
||
| const result = await service.resolve( | ||
| { | ||
| params: {}, | ||
| parent: { | ||
| data: { | ||
| sharePreviewVO: { FolderVO: null, RecordVO: sharedRecord }, | ||
| currentFolder: new FolderVO({ | ||
| pathAsText: ['My Files'], | ||
| pathAsArchiveNbr: ['0001-0001'], | ||
| pathAsFolder_linkId: [11], | ||
| }), | ||
| }, | ||
| }, | ||
| } as any, | ||
| { url: '/share/abc123/view/timeline' } as any, | ||
| ); | ||
|
|
||
| expect(getSpy).not.toHaveBeenCalled(); | ||
| expect(result.pathAsText).toEqual(['Shares', 'Record', 'My Files']); | ||
| expect(result.pathAsArchiveNbr).toEqual([ | ||
| '0000-0000', | ||
| '0000-0000', | ||
| '0001-0001', | ||
| ]); | ||
|
|
||
| expect(result.pathAsFolder_linkId).toEqual([0, 0, 11]); | ||
| expect(result.ChildItemVOs).toEqual([sharedRecord] as any); | ||
| }); | ||
|
|
||
| it('should surface the server message when the load fails', async () => { | ||
| spyOn(api.folder, 'getWithChildrenByIdentifier').and.rejectWith( | ||
| new FolderResponse({ | ||
| isSuccessful: false, | ||
| Results: [{ message: ['Test Error'] }], | ||
| }), | ||
| ); | ||
| spyOn(accountService, 'logOut').and.resolveTo(null); | ||
| spyOn(router, 'navigate'); | ||
| let displayedErrorMessage: string; | ||
| spyOn(message, 'showError').and.callFake((data: MessageDisplayOptions) => { | ||
| displayedErrorMessage = data.message; | ||
| }); | ||
|
|
||
| await expectAsync( | ||
| service.resolve({ params: {} } as any, { url: '/private' } as any), | ||
| ).toBeRejected(); | ||
|
|
||
| expect(displayedErrorMessage).toBe('Test Error'); | ||
| }); | ||
|
|
||
| it('should log out when a root folder fails to load', async () => { | ||
| spyOn(api.folder, 'getWithChildrenByIdentifier').and.rejectWith( | ||
| new Error('Network down'), | ||
| ); | ||
| const logOutSpy = spyOn(accountService, 'logOut').and.resolveTo(null); | ||
| spyOn(router, 'navigate'); | ||
| spyOn(message, 'showError'); | ||
|
|
||
| await expectAsync( | ||
| service.resolve({ params: {} } as any, { url: '/private' } as any), | ||
| ).toBeRejected(); | ||
|
|
||
| expect(logOutSpy).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should fall back to a generic message for a raw error', async () => { | ||
| spyOn(api.folder, 'getWithChildrenByIdentifier').and.rejectWith( | ||
| new Error('Network down'), | ||
| ); | ||
| spyOn(accountService, 'logOut').and.resolveTo(null); | ||
| spyOn(router, 'navigate'); | ||
| let displayedErrorMessage: string; | ||
| spyOn(message, 'showError').and.callFake((data: MessageDisplayOptions) => { | ||
| displayedErrorMessage = data.message; | ||
| }); | ||
|
|
||
| await expectAsync( | ||
| service.resolve({ params: {} } as any, { url: '/private' } as any), | ||
| ).toBeRejected(); | ||
|
|
||
| expect(displayedErrorMessage).toBe('error.generic.internal'); | ||
| }); | ||
|
|
||
| it('should redirect rather than throw when a deep link fails', async () => { | ||
| spyOn(api.folder, 'getWithChildrenByIdentifier').and.rejectWith( | ||
| new Error('Network down'), | ||
| ); | ||
| const navigateSpy = spyOn(router, 'navigate'); | ||
| spyOn(message, 'showError'); | ||
|
|
||
| await expectAsync( | ||
| service.resolve( | ||
| { params: { archiveNbr: '0001-0005', folderLinkId: '99' } } as any, | ||
| { url: '/view/timeline/0001-0005/99' } as any, | ||
| ), | ||
| ).toBeRejectedWith(false); | ||
|
|
||
| expect(navigateSpy).toHaveBeenCalledWith(['/private']); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.