-
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.
added test cases for auth pages and input field
- Loading branch information
janearisah
committed
Aug 2, 2021
1 parent
829306b
commit 2f50b0a
Showing
8 changed files
with
136 additions
and
16 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
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,48 @@ | ||
import { shallowMount } from '@vue/test-utils'; | ||
import InputField from '@/components/InputField.vue'; | ||
|
||
describe('Input Field Component', () => { | ||
let wrapper; | ||
const handleOnInvalid = jest.spyOn(InputField.methods, 'handleOnInvalid'); | ||
|
||
beforeEach(() => { | ||
wrapper = shallowMount(InputField, { | ||
propsData: { | ||
placeholder: '', | ||
label: '', | ||
name: '' | ||
} | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
wrapper.destroy(); | ||
}); | ||
|
||
it('has a label and an input field', () => { | ||
const labels = wrapper.findAll('label'); | ||
const inputs = wrapper.findAll('input'); | ||
expect(labels.length).toEqual(1); | ||
expect(inputs.length).toEqual(1); | ||
}); | ||
|
||
it('emits the invalid method when triggered', async () => { | ||
const input = wrapper.find('input'); | ||
await input.trigger('invalid'); | ||
expect(handleOnInvalid).toHaveBeenCalled(); | ||
}); | ||
|
||
it('emits the input value', async () => { | ||
const TEST_INPUT = 'test input'; | ||
const input = wrapper.find('input'); | ||
await input.setValue(TEST_INPUT); | ||
expect(wrapper.emitted().input[0]).toEqual([TEST_INPUT]); | ||
}); | ||
|
||
it('has the correct label displayed', async () => { | ||
const TEST_LABEL = 'Email'; | ||
await wrapper.setProps({ label: TEST_LABEL }); | ||
const label = wrapper.find('label'); | ||
expect(label.text()).toEqual(TEST_LABEL); | ||
}); | ||
}); |
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,40 @@ | ||
import { shallowMount } from '@vue/test-utils'; | ||
import Login from '@/components/Login.vue'; | ||
import InputField from '@/components/InputField.vue'; | ||
|
||
describe('Login View', () => { | ||
let wrapper; | ||
const switchToRegister = jest.spyOn(Login.methods, 'switchToRegister'); | ||
|
||
beforeEach(() => { | ||
wrapper = shallowMount(Login); | ||
}); | ||
|
||
afterEach(() => { | ||
wrapper.destroy(); | ||
}); | ||
|
||
it('has a form title called "Sign in"', () => { | ||
const formTitle = wrapper.find('.form__title'); | ||
expect(formTitle.text()).toMatch('Sign in'); | ||
}); | ||
|
||
it('has a form with 2 input fields', () => { | ||
const inputFields = wrapper.findAllComponents(InputField); | ||
const forms = wrapper.findAll('form'); | ||
expect(inputFields.length).toEqual(2); | ||
expect(forms.length).toEqual(1); | ||
}); | ||
|
||
it('has a meta button that shows the register page', () => { | ||
const button = wrapper.find('button.btn-link'); | ||
expect(button.exists()).toBe(true); | ||
expect(button.text()).toBe('Create account'); | ||
}); | ||
|
||
it('changes page state when button is clicked', async () => { | ||
const button = wrapper.find('button.btn-link'); | ||
await button.trigger('click'); | ||
expect(switchToRegister).toHaveBeenCalled(); | ||
}); | ||
}); |
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,40 @@ | ||
import { shallowMount } from '@vue/test-utils'; | ||
import Register from '@/components/Register.vue'; | ||
import InputField from '@/components/InputField.vue'; | ||
|
||
describe('Register View', () => { | ||
let wrapper; | ||
const switchToLogin = jest.spyOn(Register.methods, 'switchToLogin'); | ||
|
||
beforeEach(() => { | ||
wrapper = shallowMount(Register); | ||
}); | ||
|
||
afterEach(() => { | ||
wrapper.destroy(); | ||
}); | ||
|
||
it('has a form title called "Create Account"', () => { | ||
const formTitle = wrapper.find('.form__title'); | ||
expect(formTitle.text()).toMatch('Create Account'); | ||
}); | ||
|
||
it('has a form with 3 input fields', () => { | ||
const inputFields = wrapper.findAllComponents(InputField); | ||
const forms = wrapper.findAll('form'); | ||
expect(forms.length).toEqual(1); | ||
expect(inputFields.length).toEqual(3); | ||
}); | ||
|
||
it('has a meta button that shows the login page', () => { | ||
const button = wrapper.find('button.btn-link'); | ||
expect(button.exists()).toBe(true); | ||
expect(button.text()).toBe('Already have an account?'); | ||
}); | ||
|
||
it('changes page state when button is clicked', async () => { | ||
const button = wrapper.find('button.btn-link'); | ||
await button.trigger('click'); | ||
expect(switchToLogin).toHaveBeenCalled(); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.