-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: added component + auth store tests [WTEL-4374]
- Loading branch information
Showing
10 changed files
with
497 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Admin CI | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '20.x' | ||
- run: npm ci | ||
- run: npm run test:unit |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { shallowMount, mount } from '@vue/test-utils'; | ||
import { createStore } from 'vuex'; | ||
import router from '../../../router/router.js'; | ||
import TheAuth from '../the-auth.vue'; | ||
|
||
describe('TheAuth', () => { | ||
let store; | ||
|
||
beforeEach(() => { | ||
store = createStore({ | ||
modules: { | ||
auth: { | ||
namespaced: true, | ||
}, | ||
appearance: { | ||
namespaced: true, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should render', () => { | ||
const wrapper = shallowMount(TheAuth, { | ||
global: { | ||
plugins: [store, router], | ||
mocks: { | ||
$breakpoint: {}, | ||
}, | ||
}, | ||
}); | ||
expect(wrapper.exists()).toBe(true); | ||
}); | ||
|
||
it('calls "submit auth" action on submit event', () => { | ||
const mock = vi.spyOn(TheAuth.methods, 'submitAuth').mockImplementationOnce(vi.fn()); | ||
|
||
const wrapper = mount(TheAuth, { | ||
global: { | ||
plugins: [store, router], | ||
mocks: { | ||
$breakpoint: {}, | ||
}, | ||
}, | ||
}); | ||
|
||
wrapper.findComponent({ name: 'TheLogin'}).vm.$emit('submit'); | ||
|
||
expect(mock).toHaveBeenCalled(); | ||
}); | ||
}); |
81 changes: 81 additions & 0 deletions
81
src/components/auth/register/__tests__/the-register.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,81 @@ | ||
import { shallowMount, mount } from '@vue/test-utils'; | ||
import { createStore } from 'vuex'; | ||
import TheRegister from '../the-register.vue'; | ||
|
||
describe('TheRegister', () => { | ||
let store; | ||
|
||
beforeEach(() => { | ||
store = createStore({ | ||
modules: { | ||
auth: { | ||
namespaced: true, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should render', () => { | ||
const wrapper = shallowMount(TheRegister, { | ||
global: { | ||
plugins: [store], | ||
}, | ||
}); | ||
expect(wrapper.exists()).toBe(true); | ||
}); | ||
|
||
|
||
|
||
it('"next" from first step calls domain check action', () => { | ||
const mock = vi.spyOn(TheRegister.methods, 'checkDomain') | ||
.mockImplementationOnce(vi.fn()); | ||
const wrapper = mount(TheRegister, { | ||
shallow: true, | ||
global: { | ||
plugins: [store], | ||
stubs: { | ||
WtStepper: false, | ||
TheRegisterFirstStep: false, | ||
}, | ||
}, | ||
}); | ||
wrapper.findComponent({ name: 'TheRegisterFirstStep' }).vm.$emit('next'); | ||
expect(mock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('"next" from second step increments activeStep', () => { | ||
const wrapper = mount(TheRegister, { | ||
shallow: true, | ||
global: { | ||
plugins: [store], | ||
stubs: { | ||
WtStepper: false, | ||
TheRegisterSecondStep: false, | ||
}, | ||
}, | ||
data: () => ({ | ||
activeStep: 2, | ||
}), | ||
}); | ||
wrapper.findComponent({ name: 'TheRegisterSecondStep' }).vm.$emit('next'); | ||
expect(wrapper.vm.activeStep).toBe(3); | ||
}); | ||
|
||
it('"next" from third step emits "submit" event', () => { | ||
const wrapper = mount(TheRegister, { | ||
shallow: true, | ||
global: { | ||
plugins: [store], | ||
stubs: { | ||
WtStepper: false, | ||
TheRegisterThirdStep: false, | ||
}, | ||
}, | ||
data: () => ({ | ||
activeStep: 3, | ||
}), | ||
}); | ||
wrapper.findComponent({ name: 'TheRegisterThirdStep' }).vm.$emit('next'); | ||
expect(wrapper.emitted('submit')).toBeTruthy(); | ||
}); | ||
}); |
62 changes: 62 additions & 0 deletions
62
src/components/auth/register/steps/__tests__/the-register-first-step.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,62 @@ | ||
import { shallowMount, mount } from '@vue/test-utils'; | ||
import { createStore } from 'vuex'; | ||
import TheRegisterFirstStep from '../the-register-first-step.vue'; | ||
|
||
const v$ = { | ||
value: { | ||
$touch: vi.fn(), | ||
}, | ||
}; | ||
|
||
describe('TheRegisterFirstStep', () => { | ||
let store; | ||
|
||
beforeEach(() => { | ||
store = createStore({ | ||
modules: { | ||
auth: { | ||
namespaced: true, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should render', () => { | ||
const wrapper = shallowMount(TheRegisterFirstStep, { | ||
global: { | ||
plugins: [store], | ||
}, | ||
data: () => ({ v$ }), | ||
}); | ||
expect(wrapper.exists()).toBe(true); | ||
}); | ||
|
||
it('emits "next" event on "next" btn click', () => { | ||
const wrapper = mount(TheRegisterFirstStep, { | ||
shallow: true, | ||
global: { | ||
plugins: [store], | ||
stubs: { | ||
WtButton: false, | ||
}, | ||
}, | ||
data: () => ({ v$ }), | ||
}); | ||
wrapper.findAllComponents({ name: 'WtButton' }).find((btn) => { | ||
return btn.html().toLocaleLowerCase().includes('next'); | ||
}).vm.$emit('click'); | ||
expect(wrapper.emitted('next')).toBeTruthy(); | ||
}); | ||
|
||
it('emits "login" event on register link click', () => { | ||
const wrapper = mount(TheRegisterFirstStep, { | ||
shallow: true, | ||
global: { | ||
plugins: [store], | ||
}, | ||
data: () => ({ v$ }), | ||
}); | ||
wrapper.find('.auth-form-actions--link').trigger('click'); | ||
expect(wrapper.emitted('login')).toBeTruthy(); | ||
}); | ||
}); |
67 changes: 67 additions & 0 deletions
67
src/components/auth/register/steps/__tests__/the-register-second-step.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,67 @@ | ||
import { shallowMount, mount } from '@vue/test-utils'; | ||
import { createStore } from 'vuex'; | ||
import TheRegisterSecondStep from '../the-register-second-step.vue'; | ||
|
||
const v$ = { | ||
value: { | ||
$touch: vi.fn(), | ||
}, | ||
}; | ||
|
||
describe('TheRegisterSecondStep', () => { | ||
let store; | ||
|
||
beforeEach(() => { | ||
store = createStore({ | ||
modules: { | ||
auth: { | ||
namespaced: true, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should render', () => { | ||
const wrapper = shallowMount(TheRegisterSecondStep, { | ||
global: { | ||
plugins: [store], | ||
}, | ||
data: () => ({ v$ }), | ||
}); | ||
expect(wrapper.exists()).toBe(true); | ||
}); | ||
|
||
it('emits "next" event on "next" btn click', () => { | ||
const wrapper = mount(TheRegisterSecondStep, { | ||
shallow: true, | ||
global: { | ||
plugins: [store], | ||
stubs: { | ||
WtButton: false, | ||
}, | ||
}, | ||
data: () => ({ v$ }), | ||
}); | ||
wrapper.findAllComponents({ name: 'WtButton' }).find((btn) => { | ||
return btn.html().toLocaleLowerCase().includes('next'); | ||
}).vm.$emit('click'); | ||
expect(wrapper.emitted('next')).toBeTruthy(); | ||
}); | ||
|
||
it('emits "back" event on back button click', () => { | ||
const wrapper = mount(TheRegisterSecondStep, { | ||
shallow: true, | ||
global: { | ||
plugins: [store], | ||
stubs: { | ||
WtButton: false, | ||
}, | ||
}, | ||
data: () => ({ v$ }), | ||
}); | ||
wrapper.findAllComponents({ name: 'WtButton' }).find((btn) => { | ||
return btn.html().toLocaleLowerCase().includes('back'); | ||
}).vm.$emit('click'); | ||
expect(wrapper.emitted('back')).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.