Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nmarklund10/ add home page testing; refactor home page component by breaking it out into separate modules #278

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9ec16f8
add ability to run tests on docker
nmarklund10 Mar 12, 2022
daa21d6
implement test to see if submit function is called on submit
nmarklund10 Mar 12, 2022
268282b
made password reset modal a separate template
nmarklund10 Mar 12, 2022
7cf5a73
add password reset test
nmarklund10 Mar 13, 2022
270d523
move alert into separate component
nmarklund10 Mar 26, 2022
a8211c0
move password reset modal into own component
nmarklund10 Mar 26, 2022
ec296a5
remove alert logic and variables
nmarklund10 Mar 26, 2022
3baf3ca
upgrade to lockfileVersion 2
nmarklund10 Mar 26, 2022
9abf853
remove alert function
nmarklund10 Mar 26, 2022
49a37b2
created separate components for the home page description and slide show
nmarklund10 Mar 26, 2022
07b5496
move login form to separate component
nmarklund10 Mar 26, 2022
f697f21
rename login page to home component
nmarklund10 Mar 26, 2022
23289cb
move alert and password reset to new home folder
nmarklund10 Mar 26, 2022
fcc19e9
add padding to top of alert
nmarklund10 Mar 26, 2022
55819aa
remove duplicate css property
nmarklund10 Mar 26, 2022
8da9d6a
install flush-promises
nmarklund10 Mar 27, 2022
a1de530
test if alert shows properly based on api response
nmarklund10 Mar 27, 2022
9566d9b
change description of these tests; need more work on the test cases
nmarklund10 Mar 27, 2022
fb9682f
add id for css styling; add testing tag
nmarklund10 Mar 27, 2022
5fb3f3f
change login function to use await
nmarklund10 Mar 27, 2022
a8765c6
add testing tag
nmarklund10 Mar 27, 2022
6224641
use text for metric of success instead of just existence
nmarklund10 Mar 27, 2022
58b6453
remove old test files
nmarklund10 Mar 27, 2022
88a2c27
add 7 tests for the home page (alerts, modals, text, password reset)
nmarklund10 Mar 27, 2022
f700ea2
remove data-test from alert and move to login; change data-test attri…
nmarklund10 Mar 27, 2022
668a0b8
add data-test to description and tutorial
nmarklund10 Mar 27, 2022
6dcd141
rewrite resetPass with try catch for async
nmarklund10 Mar 27, 2022
8bc0741
find tutorial slide with title attribute
nmarklund10 Mar 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions __tests__/home.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { mount, createLocalVue } from '@vue/test-utils'
import { BootstrapVue } from 'bootstrap-vue'
import flushPromises from 'flush-promises'
import Login from '../src/templates/Home/Login.vue'
import Home from '../src/templates/Home/Home.vue'
import PasswordResetRequest from '../src/templates/Home/PasswordResetRequest.vue'
import { postLogin, postReset } from '../src/utils/api'

jest.mock("../src/utils/api.js", () => ({
postLogin: jest.fn(),
postReset: jest.fn()
}))

describe('Login tests', () => {
const MOCK_EMAIL = '[email protected]'
const localVue = createLocalVue()
localVue.use(BootstrapVue)
const mountOptions = {localVue}
let wrapper = null

afterEach(() => {
wrapper.destroy()
jest.resetModules()
})

test('Description is displayed on home page', () => {
wrapper = mount(Home, {
...mountOptions,
stubs: {
Login: {
template: '<div/>'
}
}
})

expect(wrapper.find('[data-test="description"]').text()).toContain('Welcome to Healthcare Roll Call')
expect(wrapper.find('[data-test="description"]').text()).toContain('Check-in for Healthcare Providers')
expect(wrapper.find('[data-test="description"]').text()).toContain('consolidates all emergency information in one database')
})

test('Tutorial is displayed on home page', () => {
wrapper = mount(Home, {
...mountOptions,
stubs: {
Login: {
template: '<div/>'
}
}
})

expect(wrapper.find('[data-test="tutorial"]').text()).toContain('Tutorial')
expect(wrapper.find('[title="tutorial"]').exists()).toBe(true)
})

test('Alert shows when POST returns error', async () => {
wrapper = mount(Login, {
...mountOptions,
mocks: {
$router: {
replace: jest.fn()
}
}
})
postLogin.mockImplementation(() => Promise.resolve({
status: 400,
message: "blah"
}))

await wrapper.get('[data-test="login-email"]').setValue(MOCK_EMAIL)
await wrapper.get('[data-test="login-password"]').setValue('test')
await wrapper.get('[data-test="login"]').trigger('submit')

await flushPromises()

expect(wrapper.vm.$router.replace).toHaveBeenCalledTimes(0)
expect(wrapper.find('[data-test="login-alert"]').text()).toContain('blah')
})

test('Alert does not show when POST succeeds', async () => {
wrapper = mount(Login, {
...mountOptions,
mocks: {
$router: {
replace: jest.fn()
}
}
})
postLogin.mockImplementation(() => Promise.resolve({
status: 200,
message: "blah"
}))

await wrapper.get('[data-test="login-email"]').setValue(MOCK_EMAIL)
await wrapper.get('[data-test="login-password"]').setValue('test')
await wrapper.get('[data-test="login"]').trigger('submit')

await flushPromises()

expect(wrapper.vm.$router.replace).toHaveBeenCalledTimes(1)
expect(wrapper.find('[data-test="login-alert"]').text()).toBe('')
})

test('Modal shows when forgot password link is clicked', async () => {
wrapper = mount(Login, mountOptions)

const modal = wrapper.findComponent({ ref: 'password-reset-modal' });
expect(modal.vm.isVisible).toBe(false);

await wrapper.get('[data-test="password-reset-link"]').trigger('click')
await flushPromises()

expect(modal.vm.isVisible).toBe(true)
})

test('Success message displayed on password reset modal when POST suceeds', async () => {
wrapper = mount(PasswordResetRequest, mountOptions)
postReset.mockImplementation(() => Promise.resolve({status: 200}))

await wrapper.get('[data-test="reset-email"]').setValue(MOCK_EMAIL)
await wrapper.get('[data-test="reset-password-submit"]').trigger('submit')
await flushPromises()

expect(wrapper.find('[data-test="reset-password-alert"]').text()).toContain("Password reset email sent!")
})

test('Error message displayed on password reset modal when POST fails', async () => {
wrapper = mount(PasswordResetRequest, mountOptions)
postReset.mockImplementation(() => Promise.resolve({status: 400}))

await wrapper.get('[data-test="reset-email"]').setValue(MOCK_EMAIL)
await wrapper.get('[data-test="reset-password-submit"]').trigger('submit')
await flushPromises()

expect(wrapper.find('[data-test="reset-password-alert"]').text()).toContain("Failed sending email")
})

})
5 changes: 5 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ services:
- ${PORT:-3000}
volumes:
- ./src:/usr/src/src
- ./__tests__:/usr/src/__tests__
- ./babel.config.js:/usr/src/babel.config.js
- ./jest.config.js:/usr/src/jest.config.js
- ./jest.init.js:/usr/src/jest.init.js
- ./__mocks__:/usr/src/__mocks__
env_file: .env
environment:
- ${PORT:-3000}
Expand Down
Loading