-
Notifications
You must be signed in to change notification settings - Fork 2
[PER-10679] Replace navigateLean with getWithChildren in the publish functionality #1135
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
Open
aasandei-vsp
wants to merge
1
commit into
PER-10476-replace-navigate-min
Choose a base branch
from
PER-10679-replace-navigate-lean-publish
base: PER-10476-replace-navigate-min
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -3,59 +3,89 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; | |
| import { AccountService } from '@shared/services/account/account.service'; | ||
| import { FolderVO, RecordVO } from '@models/index'; | ||
| import { FolderResponse } from '@shared/services/api/folder.repo'; | ||
| import { Observable } from 'rxjs'; | ||
| import { MessageService } from '@shared/services/message/message.service'; | ||
| import { EventService } from '@shared/services/event/event.service'; | ||
| import { GoogleAnalyticsService } from '@shared/services/google-analytics/google-analytics.service'; | ||
| import { DIALOG_DATA, DialogRef } from '@angular/cdk/dialog'; | ||
| import { Router } from '@angular/router'; | ||
| import { ArchiveVO } from '../../../models/archive-vo'; | ||
| import { ApiService } from '../../../shared/services/api/api.service'; | ||
| import { PublishComponent } from './publish.component'; | ||
|
|
||
| const mockAccountService = { | ||
| getArchive: () => { | ||
| const archive = new ArchiveVO({ accessRole: 'access.role.viewer' }); | ||
| return archive; | ||
| }, | ||
| getRootFolder: () => ({ | ||
| ChildItemVOs: [], | ||
| }), | ||
| refreshAccountDebounced: () => {}, | ||
| }; | ||
| const PUBLIC_ROOT = new FolderVO({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this object magical / meaningful / must have these specific values? If not, let's call this |
||
| folderId: '140683', | ||
| folder_linkId: 55, | ||
| archiveNbr: '0001-0000', | ||
| type: 'type.folder.root.public', | ||
| }); | ||
|
|
||
| // Shaped the way getWithChildren returns it: a v1-style envelope whose child items | ||
| // are the converted Stela folders. | ||
| function publicRootResponseWithChildren( | ||
| children: Array<Record<string, unknown>>, | ||
| ): FolderResponse { | ||
| return new FolderResponse({ | ||
| isSuccessful: true, | ||
| isSystemUp: true, | ||
| Results: [ | ||
| { | ||
| data: [ | ||
| { | ||
| FolderVO: { | ||
| ...PUBLIC_ROOT, | ||
| ChildItemVOs: children, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }); | ||
| } | ||
|
|
||
| class MockDialogRef { | ||
| close() {} | ||
| } | ||
|
|
||
| const mockApiService = { | ||
| folder: { | ||
| copy: async ( | ||
| folderVOs: FolderVO[], | ||
| destination: FolderVO, | ||
| ): Promise<FolderResponse> => await Promise.resolve(new FolderResponse({})), | ||
| navigateLean: (folder: FolderVO): Observable<FolderResponse> => | ||
| new Observable<FolderResponse>(), | ||
| }, | ||
| publish: { | ||
| getInternetArchiveLink: async () => ({ | ||
| getPublishIaVO: () => null, | ||
| }), | ||
| publishToInternetArchive: async () => ({ | ||
| getPublishIaVO: () => null, | ||
| }), | ||
| }, | ||
| record: { | ||
| copy: async () => ({ | ||
| getRecordVO: () => new RecordVO({}), | ||
| }), | ||
| }, | ||
| }; | ||
|
|
||
| describe('PublishComponent', () => { | ||
| let component: PublishComponent; | ||
| let fixture: ComponentFixture<PublishComponent>; | ||
| let mockApiService: any; | ||
| let mockAccountService: any; | ||
| let showErrorSpy: jasmine.Spy; | ||
|
|
||
| beforeEach(async () => { | ||
| mockAccountService = { | ||
| getArchive: () => new ArchiveVO({ accessRole: 'access.role.owner' }), | ||
| getRootFolder: () => ({ ChildItemVOs: [PUBLIC_ROOT] }), | ||
| refreshAccountDebounced: () => {}, | ||
| }; | ||
|
|
||
| mockApiService = { | ||
| folder: { | ||
| copy: jasmine | ||
| .createSpy('copy') | ||
| .and.resolveTo(new FolderResponse({ isSuccessful: true })), | ||
| getWithChildren: jasmine | ||
| .createSpy('getWithChildren') | ||
| .and.resolveTo(publicRootResponseWithChildren([])), | ||
| }, | ||
| publish: { | ||
| getInternetArchiveLink: async () => ({ | ||
| getPublishIaVO: () => null, | ||
| }), | ||
| publishToInternetArchive: async () => ({ | ||
| getPublishIaVO: () => null, | ||
| }), | ||
| }, | ||
| record: { | ||
| copy: async () => ({ | ||
| getRecordVO: () => new RecordVO({}), | ||
| }), | ||
| }, | ||
| }; | ||
|
|
||
| showErrorSpy = jasmine.createSpy('showError'); | ||
|
|
||
| await TestBed.configureTestingModule({ | ||
| declarations: [PublishComponent], | ||
| providers: [ | ||
|
|
@@ -71,15 +101,15 @@ describe('PublishComponent', () => { | |
| EventService, | ||
| { | ||
| provide: MessageService, | ||
| useValue: { | ||
| showError: () => {}, | ||
| }, | ||
| useValue: { showError: showErrorSpy }, | ||
| }, | ||
| { | ||
| provide: Router, | ||
| useValue: { | ||
| navigate: () => {}, | ||
| }, | ||
| useValue: { navigate: () => {} }, | ||
| }, | ||
| { | ||
| provide: GoogleAnalyticsService, | ||
| useValue: { sendEvent: () => {} }, | ||
| }, | ||
| ], | ||
| schemas: [CUSTOM_ELEMENTS_SCHEMA], | ||
|
|
@@ -95,6 +125,10 @@ describe('PublishComponent', () => { | |
| }); | ||
|
|
||
| it('should disaple the public to internet archive button if the user does not have the correct access role', () => { | ||
|
|
||
| mockAccountService.getArchive = () => | ||
| new ArchiveVO({ accessRole: 'access.role.viewer' }); | ||
| fixture = TestBed.createComponent(PublishComponent); | ||
| component = fixture.componentInstance; | ||
| component.publicItem = new RecordVO({ recordId: 1 }); | ||
| component.publishIa = null; | ||
| component.publicLink = null; | ||
|
|
@@ -105,4 +139,129 @@ describe('PublishComponent', () => { | |
|
|
||
| expect(button.disabled).toBeTruthy(); | ||
| }); | ||
|
|
||
| describe('publishing a folder', () => { | ||
| beforeEach(() => { | ||
| component.sourceItem = new FolderVO({ | ||
| folderId: '900', | ||
| archiveNbr: '0002-0001', | ||
| folder_linkId: 12, | ||
| displayName: 'Trip to Iceland', | ||
| type: 'type.folder.private', | ||
| }); | ||
| }); | ||
|
|
||
| it('should load the public root through getWithChildren', async () => { | ||
| mockApiService.folder.getWithChildren.and.resolveTo( | ||
| publicRootResponseWithChildren([ | ||
| { | ||
| folderId: '901', | ||
| archiveNbr: '0001-0002', | ||
| folder_linkId: 71, | ||
| displayName: 'Trip to Iceland', | ||
| type: 'type.folder.public', | ||
| updatedDT: '2026-08-10T10:00:00Z', | ||
| ChildItemVOs: [], | ||
| }, | ||
| ]), | ||
| ); | ||
|
|
||
| await component.publishItem(); | ||
|
|
||
| expect(mockApiService.folder.getWithChildren).toHaveBeenCalledWith([ | ||
| PUBLIC_ROOT, | ||
| ]); | ||
|
|
||
| expect(mockApiService.folder.getWithChildren).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('should pick the most recently updated folder matching the source name', async () => { | ||
| mockApiService.folder.getWithChildren.and.resolveTo( | ||
| publicRootResponseWithChildren([ | ||
| { | ||
| folderId: '901', | ||
| archiveNbr: '0001-0002', | ||
| folder_linkId: 71, | ||
| displayName: 'Trip to Iceland', | ||
| type: 'type.folder.public', | ||
| updatedDT: '2026-01-01T10:00:00Z', | ||
| ChildItemVOs: [], | ||
| }, | ||
| { | ||
| folderId: '902', | ||
| archiveNbr: '0001-0003', | ||
| folder_linkId: 72, | ||
| displayName: 'Trip to Iceland', | ||
| type: 'type.folder.public', | ||
| updatedDT: '2026-08-10T10:00:00Z', | ||
| ChildItemVOs: [], | ||
| }, | ||
| ]), | ||
| ); | ||
|
|
||
| await component.publishItem(); | ||
|
|
||
| // The newer of the two copies. This asserts the selection given a mapped | ||
| // updatedDT; that the Stela conversion actually populates it is covered | ||
| // in folder.repo.spec.ts. | ||
| expect(component.publicItem.folder_linkId).toBe(72); | ||
| expect(component.publicLink).toContain('0001-0003'); | ||
| }); | ||
|
|
||
| it('should ignore child records when looking for the copy', async () => { | ||
| mockApiService.folder.getWithChildren.and.resolveTo( | ||
| publicRootResponseWithChildren([ | ||
| { | ||
| recordId: '500', | ||
| archiveNbr: '0001-0009', | ||
| folder_linkId: 80, | ||
| displayName: 'Trip to Iceland', | ||
| updatedDT: '2026-08-10T12:00:00Z', | ||
| }, | ||
| { | ||
| folderId: '901', | ||
| archiveNbr: '0001-0002', | ||
| folder_linkId: 71, | ||
| displayName: 'Trip to Iceland', | ||
| type: 'type.folder.public', | ||
| updatedDT: '2026-08-10T10:00:00Z', | ||
| ChildItemVOs: [], | ||
| }, | ||
| ]), | ||
| ); | ||
|
|
||
| await component.publishItem(); | ||
|
|
||
| expect(component.publicItem instanceof FolderVO).toBeTrue(); | ||
| expect(component.publicItem.folder_linkId).toBe(71); | ||
| }); | ||
|
|
||
| it('should surface a generic error when the request rejects without a message', async () => { | ||
| mockApiService.folder.getWithChildren.and.rejectWith( | ||
| new Error('500 from the server'), | ||
| ); | ||
|
|
||
| await component.publishItem(); | ||
|
|
||
| expect(showErrorSpy).toHaveBeenCalledWith({ | ||
| message: 'error.generic.internal', | ||
| translate: true, | ||
| }); | ||
|
|
||
| expect(component.waiting).toBeFalse(); | ||
| }); | ||
|
|
||
| it('should keep showing the server message when one is available', async () => { | ||
| mockApiService.folder.copy.and.rejectWith({ | ||
| getMessage: () => 'warning.record.copy_status', | ||
| }); | ||
|
|
||
| await component.publishItem(); | ||
|
|
||
| expect(showErrorSpy).toHaveBeenCalledWith({ | ||
| message: | ||
| 'Sorry, this record cannot be copied or published until processing completes.', | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
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
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this related to the migration to
getWithChildrenor was it a "we found this issue while here" addition?If the latter, let's make it a separate commit.