From 1caa60060b2f9e3417ab335e2f1dea1064163434 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 19 Dec 2019 00:08:01 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../vue_shared/components/loading_button_spec.js | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 spec/frontend/vue_shared/components/loading_button_spec.js (limited to 'spec/frontend/vue_shared') 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(); + }); + }); +}); -- cgit v1.2.3