diff --git a/admin/src/App.spec.js b/admin/src/App.spec.js new file mode 100644 index 000000000..048493a4d --- /dev/null +++ b/admin/src/App.spec.js @@ -0,0 +1,67 @@ +import { mount } from '@vue/test-utils' +import App from './App' + +const localVue = global.localVue + +const storeCommitMock = jest.fn() + +const mocks = { + $store: { + commit: storeCommitMock, + }, +} + +const storageMock = () => { + let storage = {} + + return { + setItem: function(key, value) { + console.log('SET CALLED') + storage[key] = value || '' + }, + getItem: function(key) { + console.log('GET CALLED') + return key in storage ? storage[key] : null + } + } +} + +// window.localStorage = storageMock() + +describe('App', () => { + let wrapper + + const Wrapper = () => { + return mount(App, { localVue, mocks }) + } + + describe('mount', () => { + beforeEach(() => { + wrapper = Wrapper() + }) + + it('has a div with id "app"', () => { + expect(wrapper.find('div#app').exists()).toBeTruthy() + }) + }) + + describe('window localStorage is undefined', () => { + it('does not commit a token to the store', () => { + expect(storeCommitMock).not.toBeCalled() + }) + }) + + describe('with token in local storage', () => { + beforeEach(() => { + console.log('Test', window.localStorage) + window.localStorage = { 'foo': 'bar' } + console.log('Test', window.localStorage) + //window.localStorage.setItem('vuex', { token: 1234 }) + }) + + it('commits the token to the store', () => { + expect(storeCommitMock).toBeCalledWith('token', 1234) + }) + }) +}) + diff --git a/admin/src/App.vue b/admin/src/App.vue index 8db46b135..4e7248f1b 100644 --- a/admin/src/App.vue +++ b/admin/src/App.vue @@ -3,17 +3,18 @@ diff --git a/admin/test/testSetup.js b/admin/test/testSetup.js index 118c0b1ce..3b6b50218 100644 --- a/admin/test/testSetup.js +++ b/admin/test/testSetup.js @@ -2,6 +2,9 @@ import { createLocalVue } from '@vue/test-utils' import Vue from 'vue' import { BootstrapVue } from 'bootstrap-vue' +// without this async calls are not working +import 'regenerator-runtime' + global.localVue = createLocalVue() global.localVue.use(BootstrapVue)