-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests, use task for loading spaces
- Loading branch information
1 parent
418c360
commit 087f5f8
Showing
4 changed files
with
125 additions
and
50 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
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,75 @@ | ||
import { mount } from '@vue/test-utils' | ||
import { localVue } from '../views/views.setup' | ||
import { createStore } from 'vuex-extensions' | ||
|
||
import Spaces from '../../../src/spaces/views/Spaces.vue' | ||
|
||
import VueRouter from 'vue-router' | ||
import Vuex from 'vuex' | ||
import mockAxios from 'jest-mock-axios' | ||
|
||
localVue.use(VueRouter) | ||
|
||
const selectors = { | ||
sharesNoContentMessage: '#files-spaces-empty', | ||
spacesList: '.spaces-list' | ||
} | ||
|
||
const spacesDefaultImg = 'spaces.svg' | ||
|
||
beforeEach(mockAxios.reset) | ||
|
||
describe('Spaces component', () => { | ||
it('sets a default image for spaces', () => { | ||
const wrapper = getMountedWrapper() | ||
expect(wrapper.vm.defaultImg).toEqual(spacesDefaultImg) | ||
}) | ||
it('should show a "no content" message', async () => { | ||
mockAxios.request.mockImplementationOnce(() => { | ||
return Promise.resolve({ | ||
data: { | ||
value: [] | ||
} | ||
}) | ||
}) | ||
|
||
const wrapper = getMountedWrapper() | ||
await wrapper.vm.loadSpacesTask.last | ||
|
||
expect(wrapper.find(selectors.sharesNoContentMessage).exists()).toBeTruthy() | ||
}) | ||
|
||
it('should only list drives of type "project"', async () => { | ||
mockAxios.request.mockImplementationOnce(() => { | ||
return Promise.resolve({ | ||
data: { | ||
value: [{ driveType: 'project' }, { driveType: 'personal' }] | ||
} | ||
}) | ||
}) | ||
|
||
const wrapper = getMountedWrapper() | ||
await wrapper.vm.loadSpacesTask.last | ||
|
||
expect(wrapper.vm.spaces.length).toEqual(1) | ||
}) | ||
}) | ||
|
||
function getMountedWrapper() { | ||
return mount(Spaces, { | ||
localVue, | ||
router: new VueRouter(), | ||
store: createStore(Vuex.Store, { | ||
getters: { | ||
configuration: jest.fn(() => ({ | ||
server: 'https://example.com/', | ||
theme: { | ||
spaces: { | ||
defaultImg: spacesDefaultImg | ||
} | ||
} | ||
})) | ||
} | ||
}) | ||
}) | ||
} |