Skip to content

Commit 8c10b76

Browse files
Merge pull request #278 from nmarklund10/nmarklund10/275-test-suite
nmarklund10/ add home page testing; refactor home page component by breaking it out into separate modules
2 parents e920d9f + 8bc0741 commit 8c10b76

File tree

12 files changed

+23575
-505
lines changed

12 files changed

+23575
-505
lines changed

__tests__/home.spec.js

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
import { mount, createLocalVue } from '@vue/test-utils'
2+
import { BootstrapVue } from 'bootstrap-vue'
3+
import flushPromises from 'flush-promises'
4+
import Login from '../src/templates/Home/Login.vue'
5+
import Home from '../src/templates/Home/Home.vue'
6+
import PasswordResetRequest from '../src/templates/Home/PasswordResetRequest.vue'
7+
import { postLogin, postReset } from '../src/utils/api'
8+
9+
jest.mock("../src/utils/api.js", () => ({
10+
postLogin: jest.fn(),
11+
postReset: jest.fn()
12+
}))
13+
14+
describe('Login tests', () => {
15+
const MOCK_EMAIL = '[email protected]'
16+
const localVue = createLocalVue()
17+
localVue.use(BootstrapVue)
18+
const mountOptions = {localVue}
19+
let wrapper = null
20+
21+
afterEach(() => {
22+
wrapper.destroy()
23+
jest.resetModules()
24+
})
25+
26+
test('Description is displayed on home page', () => {
27+
wrapper = mount(Home, {
28+
...mountOptions,
29+
stubs: {
30+
Login: {
31+
template: '<div/>'
32+
}
33+
}
34+
})
35+
36+
expect(wrapper.find('[data-test="description"]').text()).toContain('Welcome to Healthcare Roll Call')
37+
expect(wrapper.find('[data-test="description"]').text()).toContain('Check-in for Healthcare Providers')
38+
expect(wrapper.find('[data-test="description"]').text()).toContain('consolidates all emergency information in one database')
39+
})
40+
41+
test('Tutorial is displayed on home page', () => {
42+
wrapper = mount(Home, {
43+
...mountOptions,
44+
stubs: {
45+
Login: {
46+
template: '<div/>'
47+
}
48+
}
49+
})
50+
51+
expect(wrapper.find('[data-test="tutorial"]').text()).toContain('Tutorial')
52+
expect(wrapper.find('[title="tutorial"]').exists()).toBe(true)
53+
})
54+
55+
test('Alert shows when POST returns error', async () => {
56+
wrapper = mount(Login, {
57+
...mountOptions,
58+
mocks: {
59+
$router: {
60+
replace: jest.fn()
61+
}
62+
}
63+
})
64+
postLogin.mockImplementation(() => Promise.resolve({
65+
status: 400,
66+
message: "blah"
67+
}))
68+
69+
await wrapper.get('[data-test="login-email"]').setValue(MOCK_EMAIL)
70+
await wrapper.get('[data-test="login-password"]').setValue('test')
71+
await wrapper.get('[data-test="login"]').trigger('submit')
72+
73+
await flushPromises()
74+
75+
expect(wrapper.vm.$router.replace).toHaveBeenCalledTimes(0)
76+
expect(wrapper.find('[data-test="login-alert"]').text()).toContain('blah')
77+
})
78+
79+
test('Alert does not show when POST succeeds', async () => {
80+
wrapper = mount(Login, {
81+
...mountOptions,
82+
mocks: {
83+
$router: {
84+
replace: jest.fn()
85+
}
86+
}
87+
})
88+
postLogin.mockImplementation(() => Promise.resolve({
89+
status: 200,
90+
message: "blah"
91+
}))
92+
93+
await wrapper.get('[data-test="login-email"]').setValue(MOCK_EMAIL)
94+
await wrapper.get('[data-test="login-password"]').setValue('test')
95+
await wrapper.get('[data-test="login"]').trigger('submit')
96+
97+
await flushPromises()
98+
99+
expect(wrapper.vm.$router.replace).toHaveBeenCalledTimes(1)
100+
expect(wrapper.find('[data-test="login-alert"]').text()).toBe('')
101+
})
102+
103+
test('Modal shows when forgot password link is clicked', async () => {
104+
wrapper = mount(Login, mountOptions)
105+
106+
const modal = wrapper.findComponent({ ref: 'password-reset-modal' });
107+
expect(modal.vm.isVisible).toBe(false);
108+
109+
await wrapper.get('[data-test="password-reset-link"]').trigger('click')
110+
await flushPromises()
111+
112+
expect(modal.vm.isVisible).toBe(true)
113+
})
114+
115+
test('Success message displayed on password reset modal when POST suceeds', async () => {
116+
wrapper = mount(PasswordResetRequest, mountOptions)
117+
postReset.mockImplementation(() => Promise.resolve({status: 200}))
118+
119+
await wrapper.get('[data-test="reset-email"]').setValue(MOCK_EMAIL)
120+
await wrapper.get('[data-test="reset-password-submit"]').trigger('submit')
121+
await flushPromises()
122+
123+
expect(wrapper.find('[data-test="reset-password-alert"]').text()).toContain("Password reset email sent!")
124+
})
125+
126+
test('Error message displayed on password reset modal when POST fails', async () => {
127+
wrapper = mount(PasswordResetRequest, mountOptions)
128+
postReset.mockImplementation(() => Promise.resolve({status: 400}))
129+
130+
await wrapper.get('[data-test="reset-email"]').setValue(MOCK_EMAIL)
131+
await wrapper.get('[data-test="reset-password-submit"]').trigger('submit')
132+
await flushPromises()
133+
134+
expect(wrapper.find('[data-test="reset-password-alert"]').text()).toContain("Failed sending email")
135+
})
136+
137+
})

docker-compose.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ services:
1010
- ${PORT:-3000}
1111
volumes:
1212
- ./src:/usr/src/src
13+
- ./__tests__:/usr/src/__tests__
14+
- ./babel.config.js:/usr/src/babel.config.js
15+
- ./jest.config.js:/usr/src/jest.config.js
16+
- ./jest.init.js:/usr/src/jest.init.js
17+
- ./__mocks__:/usr/src/__mocks__
1318
env_file: .env
1419
environment:
1520
- ${PORT:-3000}

0 commit comments

Comments
 (0)