-
Notifications
You must be signed in to change notification settings - Fork 81
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
Add tests for KModal
#320
Merged
Merged
Add tests for KModal
#320
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import { shallowMount } from '@vue/test-utils'; | ||
import KModal from '../KModal'; | ||
|
||
// jest.mock('kolibri.utils.coreStrings', () => { | ||
// const translations = { | ||
// readReference: 'Reference', | ||
// }; | ||
// return { | ||
// $tr: jest.fn(key => { | ||
// return translations[key]; | ||
// }), | ||
// }; | ||
// }); | ||
|
||
describe('KModal component', () => { | ||
it(`smoke test`, () => { | ||
const wrapper = shallowMount(KModal); | ||
expect(wrapper.exists()).toBe(true); | ||
}); | ||
|
||
describe('props', () => { | ||
it(`a title should appear`, () => { | ||
const title = 'test title'; | ||
const wrapper = shallowMount(KModal, { | ||
propsData: { | ||
title: title, | ||
}, | ||
}); | ||
expect(wrapper.find('.title').text()).toEqual(title); | ||
}); | ||
it(`text should appear on the submit button`, () => { | ||
const submitText = 'hello'; | ||
const onClick = jest.fn(); | ||
const wrapper = shallowMount(KModal, { | ||
propsData: { | ||
submitText: submitText, | ||
}, | ||
listeners: { submit: onClick }, | ||
}); | ||
expect(wrapper.findComponent({ name: 'KButton' }).props().text).toEqual(submitText); | ||
}); | ||
|
||
it(`text should appear on the close button`, () => { | ||
let cancelText = 'goodbye'; | ||
const onClick = jest.fn(); | ||
const wrapper = shallowMount(KModal, { | ||
propsData: { | ||
cancelText: cancelText, | ||
}, | ||
listeners: { cancel: onClick }, | ||
}); | ||
expect(wrapper.findComponent({ name: 'KButton' }).props().text).toEqual(cancelText); | ||
}); | ||
|
||
it(`submit button is disabled if submitDisabled is true`, () => { | ||
let submitText = 'hello'; | ||
const onClick = jest.fn(); | ||
const wrapper = shallowMount(KModal, { | ||
propsData: { | ||
submitText: submitText, | ||
submitDisabled: true, | ||
}, | ||
listeners: { submit: onClick }, | ||
}); | ||
expect(wrapper.findComponent({ name: 'KButton' }).props().disabled).toBeTruthy(); | ||
}); | ||
|
||
it(`cancel button is disabled if cancelDisabled is true`, () => { | ||
let cancelText = 'goodbye'; | ||
const onClick = jest.fn(); | ||
const wrapper = shallowMount(KModal, { | ||
propsData: { | ||
cancelText: cancelText, | ||
cancelDisabled: true, | ||
}, | ||
listeners: { cancel: onClick }, | ||
}); | ||
expect(wrapper.findComponent({ name: 'KButton' }).props().disabled).toBeTruthy(); | ||
}); | ||
|
||
it(`size of modal can be determined with string prop`, () => { | ||
const wrapper = shallowMount(KModal, { | ||
propsData: { | ||
size: 'large', | ||
}, | ||
}); | ||
expect(wrapper.find('.modal').element.style['width']).toEqual('100%'); | ||
}); | ||
|
||
it(`size of modal can be determined by integer prop`, () => { | ||
const wrapper = shallowMount(KModal, { | ||
propsData: { | ||
size: 789, | ||
}, | ||
}); | ||
expect(wrapper.find('.modal').element.style['width']).toEqual('789px'); | ||
}); | ||
|
||
it(`error message is in a visually hidden span if hasError is true`, () => { | ||
const error = 'watch out for the error'; | ||
const wrapper = shallowMount(KModal, { | ||
propsData: { | ||
hasError: true, | ||
errorMessage: error, | ||
}, | ||
}); | ||
expect(wrapper.find('.visuallyhidden').element).toBeTruthy(); | ||
expect(wrapper.find('.visuallyhidden').text()).toContain(error); | ||
}); | ||
}); | ||
describe('slots', () => { | ||
it(`content is displayed in default <slot>`, () => { | ||
const slot = '<div><p>main content appears here</p></div>'; | ||
const wrapper = shallowMount(KModal, { | ||
slots: { | ||
default: slot, | ||
}, | ||
}); | ||
expect(wrapper.find('.content').text()).toContain('main content appears here'); | ||
}); | ||
it(`alternative content is displayed below main content if actions <slot> is used`, () => { | ||
const slot = '<div><p>main content appears here</p></div>'; | ||
const actionsSlot = '<div><p class="actionsSlot">actions content</p></div>'; | ||
const wrapper = shallowMount(KModal, { | ||
slots: { | ||
default: slot, | ||
actions: actionsSlot, | ||
}, | ||
}); | ||
expect(wrapper.find('.content').text()).toContain('main content appears here'); | ||
expect(wrapper.find('.actions').text()).toContain('actions content'); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never again will I import the component now that I know I can pass an object with the name property!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YES! I learned that, I think, from reading someone else's test, and 🤯 .