-
Notifications
You must be signed in to change notification settings - Fork 1
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
PER-9881: The location picker never closes #476
Merged
crisnicandrei
merged 8 commits into
main
from
PER-9881-the-location-picker-never-closes
Oct 25, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
213ad21
PER-9881: The location picker never closes
crisnicandrei 7a0fa30
removed console log
crisnicandrei 84540a6
add tests
crisnicandrei e863b03
add tests
crisnicandrei 373d64d
Fix SidebarComponent tests
meisekimiu 79e3b8a
added more tests
crisnicandrei d074975
prettier
crisnicandrei e307391
Revert changes
crisnicandrei 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 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
164 changes: 139 additions & 25 deletions
164
src/app/file-browser/components/sidebar/sidebar.component.spec.ts
This file contains 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 |
---|---|---|
@@ -1,25 +1,139 @@ | ||
// import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
// import { SidebarComponent } from './sidebar.component'; | ||
|
||
// describe('SidebarComponent', () => { | ||
// let component: SidebarComponent; | ||
// let fixture: ComponentFixture<SidebarComponent>; | ||
|
||
// beforeEach(async(() => { | ||
// TestBed.configureTestingModule({ | ||
// declarations: [ SidebarComponent ] | ||
// }) | ||
// .compileComponents(); | ||
// })); | ||
|
||
// beforeEach(() => { | ||
// fixture = TestBed.createComponent(SidebarComponent); | ||
// component = fixture.componentInstance; | ||
// fixture.detectChanges(); | ||
// }); | ||
|
||
// it('should create', () => { | ||
// expect(component).toBeTruthy(); | ||
// }); | ||
// }); | ||
/* @format */ | ||
import { Shallow } from 'shallow-render'; | ||
import { FileBrowserComponentsModule } from '@fileBrowser/file-browser-components.module'; | ||
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 { of } from 'rxjs'; | ||
import { RecordCastPipe } from '@shared/pipes/cast.pipe'; | ||
import { SidebarComponent } from './sidebar.component'; | ||
|
||
const mockDataService = { | ||
selectedItems$: () => | ||
of( | ||
new Set([ | ||
new RecordVO({ | ||
accessRole: 'access.role.owner', | ||
}), | ||
]), | ||
), | ||
fetchFullItems: (_) => {}, | ||
}; | ||
|
||
const mockEditService = { | ||
openLocationDialog: (_) => {}, | ||
}; | ||
|
||
class MockAccountService { | ||
getArchive() { | ||
return new ArchiveVO({}); | ||
} | ||
checkMinimumArchiveAccess() { | ||
return true; | ||
} | ||
checkMinimumAccess() { | ||
return true; | ||
} | ||
} | ||
|
||
describe('SidebarComponent', () => { | ||
let shallow: Shallow<SidebarComponent>; | ||
|
||
beforeEach(() => { | ||
shallow = new Shallow(SidebarComponent, FileBrowserComponentsModule) | ||
.provideMock({ | ||
provide: DataService, | ||
useValue: mockDataService, | ||
}) | ||
.provideMock({ | ||
provide: EditService, | ||
useValue: mockEditService, | ||
}) | ||
.provideMock({ | ||
provide: AccountService, | ||
useClass: MockAccountService, | ||
}) | ||
.dontMock(RecordCastPipe); | ||
}); | ||
|
||
it('should create', async () => { | ||
const { instance } = await shallow.render(); | ||
|
||
expect(instance).toBeTruthy(); | ||
}); | ||
|
||
it('should open location dialog on Enter key press if editable', async () => { | ||
const { instance } = await shallow.render(); | ||
|
||
const locationDialogSpy = spyOn( | ||
mockEditService, | ||
'openLocationDialog', | ||
).and.callThrough(); | ||
|
||
instance.onLocationEnterPress( | ||
new KeyboardEvent('keydown', { key: 'Enter' }), | ||
); | ||
|
||
expect(locationDialogSpy).toHaveBeenCalledWith(instance.selectedItem); | ||
}); | ||
|
||
it('should set currentTab correctly when setCurrentTab is called', async () => { | ||
const { instance, fixture } = await shallow.render(); | ||
|
||
instance.setCurrentTab('info'); | ||
fixture.detectChanges(); | ||
|
||
expect(instance.currentTab).toBe('info'); | ||
|
||
instance.isRootFolder = false; | ||
instance.isPublicItem = false; | ||
instance.setCurrentTab('sharing'); | ||
fixture.detectChanges(); | ||
|
||
expect(instance.currentTab).toBe('sharing'); | ||
}); | ||
|
||
it('should call editService.openLocationDialog when onLocationClick is called if editable', async () => { | ||
const { instance, inject } = await shallow.render(); | ||
const editService = inject(EditService); | ||
spyOn(editService, 'openLocationDialog'); | ||
|
||
instance.canEdit = true; | ||
instance.selectedItem = new RecordVO({}); | ||
|
||
instance.onLocationClick(); | ||
|
||
expect(editService.openLocationDialog).toHaveBeenCalledWith( | ||
instance.selectedItem, | ||
); | ||
}); | ||
|
||
it('should correctly update canEdit and canShare when checkPermissions is called', async () => { | ||
const { instance } = await shallow.render(); | ||
|
||
instance.selectedItem = new RecordVO({ | ||
accessRole: 'access.role.editor', | ||
}); | ||
instance.selectedItems = [instance.selectedItem]; | ||
instance.isRootFolder = false; | ||
instance.isPublicItem = false; | ||
|
||
instance.checkPermissions(); | ||
|
||
expect(instance.canEdit).toBe(true); | ||
expect(instance.canShare).toBe(true); | ||
|
||
instance.selectedItem = new RecordVO({ | ||
accessRole: 'access.role.viewer', | ||
}); | ||
instance.selectedItems = [instance.selectedItem]; | ||
instance.isRootFolder = false; | ||
instance.isPublicItem = false; | ||
|
||
instance.checkPermissions(); | ||
|
||
expect(instance.canEdit).toBe(false); | ||
expect(instance.canShare).toBe(true); | ||
}); | ||
}); |
This file contains 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
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.
Can you cover this function with some basic tests? You do not need to cover the rest of the component for now.