debian-mirror-gitlab/spec/frontend/vue_shared/components/toggle_button_spec.js

102 lines
2.5 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import Vue from 'vue';
2020-05-24 23:13:21 +05:30
import mountComponent from 'helpers/vue_mount_component_helper';
2020-01-01 13:55:28 +05:30
import toggleButton from '~/vue_shared/components/toggle_button.vue';
2018-03-17 18:26:18 +05:30
describe('Toggle Button', () => {
let vm;
let Component;
beforeEach(() => {
Component = Vue.extend(toggleButton);
});
afterEach(() => {
vm.$destroy();
});
describe('render output', () => {
beforeEach(() => {
vm = mountComponent(Component, {
value: true,
name: 'foo',
});
});
it('renders input with provided name', () => {
expect(vm.$el.querySelector('input').getAttribute('name')).toEqual('foo');
});
it('renders input with provided value', () => {
expect(vm.$el.querySelector('input').getAttribute('value')).toEqual('true');
});
it('renders input status icon', () => {
expect(vm.$el.querySelectorAll('span.toggle-icon').length).toEqual(1);
2020-10-24 23:57:45 +05:30
expect(vm.$el.querySelectorAll('svg.s18').length).toEqual(1);
2018-03-17 18:26:18 +05:30
});
});
describe('is-checked', () => {
beforeEach(() => {
vm = mountComponent(Component, {
value: true,
});
2020-05-24 23:13:21 +05:30
jest.spyOn(vm, '$emit').mockImplementation(() => {});
2018-03-17 18:26:18 +05:30
});
it('renders is checked class', () => {
expect(vm.$el.querySelector('button').classList.contains('is-checked')).toEqual(true);
});
it('sets aria-label representing toggle state', () => {
vm.value = true;
2018-12-13 13:39:08 +05:30
2018-03-17 18:26:18 +05:30
expect(vm.ariaLabel).toEqual('Toggle Status: ON');
vm.value = false;
2018-12-13 13:39:08 +05:30
2018-03-17 18:26:18 +05:30
expect(vm.ariaLabel).toEqual('Toggle Status: OFF');
});
it('emits change event when clicked', () => {
vm.$el.querySelector('button').click();
expect(vm.$emit).toHaveBeenCalledWith('change', false);
});
});
describe('is-disabled', () => {
beforeEach(() => {
vm = mountComponent(Component, {
value: true,
disabledInput: true,
});
2020-05-24 23:13:21 +05:30
jest.spyOn(vm, '$emit').mockImplementation(() => {});
2018-03-17 18:26:18 +05:30
});
it('renders disabled button', () => {
expect(vm.$el.querySelector('button').classList.contains('is-disabled')).toEqual(true);
});
it('does not emit change event when clicked', () => {
vm.$el.querySelector('button').click();
expect(vm.$emit).not.toHaveBeenCalled();
});
});
describe('is-loading', () => {
beforeEach(() => {
vm = mountComponent(Component, {
value: true,
isLoading: true,
});
});
it('renders loading class', () => {
expect(vm.$el.querySelector('button').classList.contains('is-loading')).toEqual(true);
});
});
});