-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: TopLevelHeader component unit test suite
- Loading branch information
1 parent
8326f32
commit 6657b53
Showing
10 changed files
with
739 additions
and
402 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
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 +1,6 @@ | ||
/** | ||
* Global Setup for e2e testing | ||
* here you can do whatever global thing you want | ||
* eg: mock a global module | ||
*/ | ||
jest.setTimeout(30000) |
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,10 @@ | ||
/** | ||
* Global Setup for e2e testing | ||
* here you can do whatever global thing you want | ||
* eg: mock a global module | ||
*/ | ||
jest.mock('@/plugins/axios', () => { | ||
const axios = require('axios') | ||
return axios | ||
}) | ||
jest.mock('axios') |
Large diffs are not rendered by default.
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,74 @@ | ||
import { shallowMount } from '@vue/test-utils' | ||
import TopLevelHeader from '@/components/Navbar/TopLevelHeader.vue' | ||
import store from '@/store/index' | ||
import { localVue } from '../index' | ||
import axiosInstance from '@/plugins/axios' | ||
window.FB = { | ||
logout: jest.fn(() => true) | ||
} | ||
describe('Authentication', () => { | ||
let vm | ||
beforeAll(() => { | ||
const wrapper = shallowMount(TopLevelHeader, { | ||
store, | ||
localVue, | ||
stubs: ['custom-button', 'router-view', 'v-facebook-login'] | ||
}) | ||
vm = wrapper.vm | ||
}) | ||
|
||
describe('Sign up', () => { | ||
it('should create a new use when invoke createUser', async () => { | ||
let customer = { | ||
customer_id: 1, | ||
name: 'John doe' | ||
} | ||
axiosInstance.mockImplementation(({ url, method }) => { | ||
if (url === '/customers' && method === 'post') { | ||
return Promise.resolve({ | ||
status: 200, | ||
data: { | ||
customer, | ||
token: 'token', | ||
expires_in: '2019/9/1' | ||
} | ||
}) | ||
} | ||
}) | ||
await vm.createUser() | ||
expect(vm.customer).toEqual(customer) | ||
}) | ||
}) | ||
|
||
describe('Login', () => { | ||
test('user is not logged in by default', () => { | ||
expect(vm.loggedin).toBe(false) | ||
}) | ||
|
||
test('user could log in', async () => { | ||
const customer = { | ||
customer_id: 1, | ||
name: 'John Dor' | ||
} | ||
axiosInstance.mockImplementation(({ url, method }) => { | ||
if (url === '/customers/login' && method === 'post') { | ||
return Promise.resolve({ | ||
status: 200, | ||
data: { | ||
customer, | ||
token: 'token', | ||
expires_in: '2019/9/1' | ||
} | ||
}) | ||
} | ||
}) | ||
await vm.loginUser() | ||
expect(vm.customer).toEqual(customer) | ||
}) | ||
}) | ||
|
||
test.only('logout', () => { | ||
vm.logout() | ||
expect(vm.customer).toEqual({}) | ||
}) | ||
}) |
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,18 @@ | ||
import { createLocalVue } from '@vue/test-utils' | ||
import NodeEnvironment from 'jest-environment-node' | ||
import Vuex from 'vuex' | ||
import buefy from 'buefy' | ||
import globals from '@/mixins/globals' | ||
import VeeValidate from 'vee-validate' | ||
|
||
export const localVue = createLocalVue() | ||
localVue.use(Vuex) | ||
localVue.use(buefy) | ||
localVue.mixin(globals) | ||
localVue.use(VeeValidate) | ||
|
||
localVue.prototype.$buefy = { | ||
notification: { | ||
open: () => 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
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