Skip to content

Commit

Permalink
Add unit tests for breadcrumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Dec 2, 2022
1 parent 9c8cb98 commit cb372f2
Showing 1 changed file with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@ describe('GenericSpace view', () => {
expect(wrapper.find('resource-table-stub').exists()).toBeTruthy()
})
})
describe('breadcrumbs', () => {
it.each([
{ driveType: 'personal', expectedItems: 1 },
{ driveType: 'project', expectedItems: 2 },
{ driveType: 'share', expectedItems: 3 }
])('include root item(s)', (data) => {
const { driveType } = data
const space = { id: 1, getDriveAliasAndItem: jest.fn(), driveType }
const { wrapper } = getMountedWrapper({ files, props: { space } })
expect(wrapper.find('app-bar-stub').props().breadcrumbs.length).toBe(data.expectedItems)
})
it('include the root item and the current folder', () => {
const folderName = 'someFolder'
const { wrapper } = getMountedWrapper({ files, props: { item: `/${folderName}` } })
expect(wrapper.find('app-bar-stub').props().breadcrumbs.length).toBe(2)
expect(wrapper.find('app-bar-stub').props().breadcrumbs[1].text).toEqual(folderName)
})
it('omit the "page"-query of the current route', () => {
const currentRoute = { name: 'files-spaces-generic', path: '/', query: { page: '2' } }
const { wrapper } = getMountedWrapper({ files, props: { item: 'someFolder' }, currentRoute })
const breadCrumbItem = wrapper.find('app-bar-stub').props().breadcrumbs[0]
expect(breadCrumbItem.to.query.page).toBeUndefined()
})
})
describe('loader task', () => {
it('re-loads the resources on item change', async () => {
const loaderSpy = jest.spyOn((GenericSpace as any).methods, 'performLoaderTask')
Expand All @@ -85,17 +109,21 @@ describe('GenericSpace view', () => {
})
})

function getMountedWrapper({ mocks = {}, props = {}, files = [], loading = false } = {}) {
function getMountedWrapper({
mocks = {},
props = {},
files = [],
loading = false,
currentRoute = { name: 'files-spaces-generic', path: '/' }
} = {}) {
jest.mocked(useResourcesViewDefaults).mockImplementation(() =>
useResourcesViewDefaultsMock({
paginatedResources: ref(files),
areResourcesLoading: ref(loading)
})
)
const defaultMocks = {
...defaultComponentMocks({
currentRoute: { name: 'files-spaces-generic', path: '/' }
}),
...defaultComponentMocks({ currentRoute }),
...(mocks && mocks)
}
const storeOptions = { ...defaultStoreMockOptions }
Expand Down

0 comments on commit cb372f2

Please sign in to comment.