debian-mirror-gitlab/spec/javascripts/vue_shared/components/loading_button_spec.js

112 lines
2.8 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import Vue from 'vue';
2018-03-27 19:54:05 +05:30
import mountComponent from 'spec/helpers/vue_mount_component_helper';
2020-01-01 13:55:28 +05:30
import loadingButton from '~/vue_shared/components/loading_button.vue';
2018-03-17 18:26:18 +05:30
const LABEL = 'Hello';
2018-12-13 13:39:08 +05:30
describe('LoadingButton', function() {
2018-03-17 18:26:18 +05:30
let vm;
let LoadingButton;
beforeEach(() => {
LoadingButton = Vue.extend(loadingButton);
});
afterEach(() => {
vm.$destroy();
});
describe('loading spinner', () => {
it('shown when loading', () => {
vm = mountComponent(LoadingButton, {
loading: true,
});
expect(vm.$el.querySelector('.js-loading-button-icon')).toBeDefined();
});
});
describe('disabled state', () => {
it('disabled when loading', () => {
vm = mountComponent(LoadingButton, {
loading: true,
});
expect(vm.$el.disabled).toEqual(true);
});
it('not disabled when normal', () => {
vm = mountComponent(LoadingButton, {
loading: false,
});
expect(vm.$el.disabled).toEqual(false);
});
});
describe('label', () => {
it('shown when normal', () => {
vm = mountComponent(LoadingButton, {
loading: false,
label: LABEL,
});
const label = vm.$el.querySelector('.js-loading-button-label');
expect(label.textContent.trim()).toEqual(LABEL);
});
it('shown when loading', () => {
vm = mountComponent(LoadingButton, {
loading: true,
label: LABEL,
});
const label = vm.$el.querySelector('.js-loading-button-label');
expect(label.textContent.trim()).toEqual(LABEL);
});
});
describe('container class', () => {
it('should default to btn btn-align-content', () => {
vm = mountComponent(LoadingButton, {});
2018-12-13 13:39:08 +05:30
2018-03-17 18:26:18 +05:30
expect(vm.$el.classList.contains('btn')).toEqual(true);
expect(vm.$el.classList.contains('btn-align-content')).toEqual(true);
});
it('should be configurable through props', () => {
vm = mountComponent(LoadingButton, {
containerClass: 'test-class',
});
2018-12-13 13:39:08 +05:30
2018-03-17 18:26:18 +05:30
expect(vm.$el.classList.contains('btn')).toEqual(false);
expect(vm.$el.classList.contains('btn-align-content')).toEqual(false);
expect(vm.$el.classList.contains('test-class')).toEqual(true);
});
});
describe('click callback prop', () => {
it('calls given callback when normal', () => {
vm = mountComponent(LoadingButton, {
loading: false,
});
spyOn(vm, '$emit');
vm.$el.click();
expect(vm.$emit).toHaveBeenCalledWith('click', jasmine.any(Object));
});
it('does not call given callback when disabled because of loading', () => {
vm = mountComponent(LoadingButton, {
loading: true,
});
spyOn(vm, '$emit');
vm.$el.click();
expect(vm.$emit).not.toHaveBeenCalled();
});
});
});