forked from hackaru-app/hackaru-desktop
/
auth.spec.js
58 lines (50 loc) · 1.44 KB
/
auth.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { Store } from 'vuex-mock-store';
import { shallowMount } from '@vue/test-utils';
import Auth from '@/pages/auth';
describe('Auth', () => {
let wrapper;
const $store = new Store({});
const $electron = {
ipcRenderer: {
send: jest.fn(),
on: () => {}
}
};
const factory = () =>
shallowMount(Auth, {
mocks: {
$store,
$electron
}
});
describe('when click submit-button', () => {
beforeEach(() => {
$store.dispatch.mockReturnValue(true);
wrapper = factory();
wrapper.find('.api-url').vm.$emit('input', 'https://www.example.com');
wrapper.find('form').trigger('submit.prevent');
});
it('dispatch auth/fetchAppToken', () => {
expect($store.dispatch).toHaveBeenCalledWith(
'auth/fetchAppToken',
'https://www.example.com'
);
});
it('send showAuthentication', () => {
expect($electron.ipcRenderer.send).toHaveBeenCalledWith(
'showAuthentication'
);
});
});
describe('when click submit-button but fetch app token failed', () => {
beforeEach(() => {
$store.dispatch.mockReturnValue(false);
wrapper = factory();
wrapper.find('.api-url').vm.$emit('input', 'https://www.example.com');
wrapper.find('form').trigger('submit.prevent');
});
it('does not send showAuthentication', () => {
expect($electron.ipcRenderer.send).not.toHaveBeenCalled();
});
});
});