diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-19 03:08:01 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-19 03:08:01 +0300 |
commit | 1caa60060b2f9e3417ab335e2f1dea1064163434 (patch) | |
tree | 01c0d5825bd345ee625bb70b7433c6e10307fcce /spec/frontend/vue_shared | |
parent | 7f8330873c1a5860b8a9a52d111083a65d210249 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/vue_shared')
-rw-r--r-- | spec/frontend/vue_shared/components/loading_button_spec.js | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/spec/frontend/vue_shared/components/loading_button_spec.js b/spec/frontend/vue_shared/components/loading_button_spec.js new file mode 100644 index 00000000000..34fac37c250 --- /dev/null +++ b/spec/frontend/vue_shared/components/loading_button_spec.js @@ -0,0 +1,96 @@ +import { shallowMount } from '@vue/test-utils'; +import LoadingButton from '~/vue_shared/components/loading_button.vue'; + +const LABEL = 'Hello'; + +describe('LoadingButton', () => { + let wrapper; + + afterEach(() => { + wrapper.destroy(); + }); + + const buildWrapper = (propsData = {}) => { + wrapper = shallowMount(LoadingButton, { + propsData, + }); + }; + const findButtonLabel = () => wrapper.find('.js-loading-button-label'); + const findButtonIcon = () => wrapper.find('.js-loading-button-icon'); + + describe('loading spinner', () => { + it('shown when loading', () => { + buildWrapper({ loading: true }); + + expect(findButtonIcon().exists()).toBe(true); + }); + }); + + describe('disabled state', () => { + it('disabled when loading', () => { + buildWrapper({ loading: true }); + expect(wrapper.attributes('disabled')).toBe('disabled'); + }); + + it('not disabled when normal', () => { + buildWrapper({ loading: false }); + + expect(wrapper.attributes('disabled')).toBe(undefined); + }); + }); + + describe('label', () => { + it('shown when normal', () => { + buildWrapper({ loading: false, label: LABEL }); + expect(findButtonLabel().text()).toBe(LABEL); + }); + + it('shown when loading', () => { + buildWrapper({ loading: false, label: LABEL }); + expect(findButtonLabel().text()).toBe(LABEL); + }); + }); + + describe('container class', () => { + it('should default to btn btn-align-content', () => { + buildWrapper(); + + expect(wrapper.classes()).toContain('btn'); + expect(wrapper.classes()).toContain('btn-align-content'); + }); + + it('should be configurable through props', () => { + const containerClass = 'test-class'; + + buildWrapper({ + containerClass, + }); + + expect(wrapper.classes()).not.toContain('btn'); + expect(wrapper.classes()).not.toContain('btn-align-content'); + expect(wrapper.classes()).toContain(containerClass); + }); + }); + + describe('click callback prop', () => { + it('calls given callback when normal', () => { + buildWrapper({ + loading: false, + }); + + wrapper.trigger('click'); + + expect(wrapper.emitted('click')).toBeTruthy(); + }); + + it('does not call given callback when disabled because of loading', () => { + buildWrapper({ + loading: true, + }); + + wrapper.trigger('click'); + + expect(wrapper.emitted('click')).toBeFalsy(); + }); + }); +}); |