-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
JanAckermann
committed
Mar 18, 2022
1 parent
9f2b377
commit b2513c1
Showing
2 changed files
with
88 additions
and
2 deletions.
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
86 changes: 86 additions & 0 deletions
86
packages/web-app-files/tests/unit/mixins/spaces/navigate.spec.js
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import Vuex from 'vuex' | ||
import { createStore } from 'vuex-extensions' | ||
import { mount, createLocalVue } from '@vue/test-utils' | ||
import Navigate from '@files/src/mixins/spaces/actions/navigate.js' | ||
import { createLocationSpaces, createLocationTrash } from '../../../../src/router' | ||
|
||
const localVue = createLocalVue() | ||
localVue.use(Vuex) | ||
|
||
const Component = { | ||
render() {}, | ||
mixins: [Navigate] | ||
} | ||
|
||
describe('navigate', () => { | ||
afterEach(() => jest.clearAllMocks()) | ||
|
||
describe('isEnabled property', () => { | ||
it('should be true when no resource given', () => { | ||
const wrapper = getWrapper() | ||
expect(wrapper.vm.$_navigate_space_items[0].isEnabled({ resources: [] })).toBe(true) | ||
}) | ||
it('should be false when resource is given', () => { | ||
const wrapper = getWrapper() | ||
expect(wrapper.vm.$_navigate_space_items[0].isEnabled({ resources: [{}] })).toBe(false) | ||
}) | ||
it('should be false when location is invalid', () => { | ||
const wrapper = getWrapper({ invalidLocation: true }) | ||
expect(wrapper.vm.$_navigate_space_items[0].isEnabled({ resources: [] })).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('method "$_navigate_space_trigger"', () => { | ||
it('should trigger route change', async () => { | ||
const wrapper = getWrapper() | ||
await wrapper.vm.$_navigate_space_trigger() | ||
|
||
expect(wrapper.vm.$router.push).toHaveBeenCalledWith( | ||
createLocationSpaces('files-spaces-project', { | ||
params: { | ||
storageId: wrapper.vm.$router.currentRoute.params.storageId | ||
} | ||
}) | ||
) | ||
}) | ||
}) | ||
}) | ||
|
||
function getWrapper({ invalidLocation = false } = {}) { | ||
return mount(Component, { | ||
localVue, | ||
mocks: { | ||
$router: { | ||
currentRoute: invalidLocation | ||
? createLocationTrash('files-trash-personal') | ||
: createLocationTrash('files-trash-spaces-project', { params: { storageId: '1' } }), | ||
resolve: (r) => { | ||
return { href: r.name } | ||
}, | ||
push: jest.fn() | ||
}, | ||
$gettext: jest.fn() | ||
}, | ||
store: createStore(Vuex.Store, { | ||
actions: { | ||
createModal: jest.fn(), | ||
hideModal: jest.fn(), | ||
showMessage: jest.fn() | ||
}, | ||
getters: { | ||
configuration: () => ({ | ||
server: 'https://example.com' | ||
}), | ||
getToken: () => 'token' | ||
}, | ||
modules: { | ||
Files: { | ||
namespaced: true, | ||
mutations: { | ||
REMOVE_FILE: jest.fn() | ||
} | ||
} | ||
} | ||
}) | ||
}) | ||
} |