debian-mirror-gitlab/spec/frontend/design_management/components/design_scaler_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

106 lines
2.9 KiB
JavaScript
Raw Normal View History

2021-01-29 00:20:46 +05:30
import { GlButton } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
2020-05-24 23:13:21 +05:30
import DesignScaler from '~/design_management/components/design_scaler.vue';
describe('Design management design scaler component', () => {
let wrapper;
2022-08-27 11:52:29 +05:30
const getButtons = () => wrapper.findAllComponents(GlButton);
2021-01-29 00:20:46 +05:30
const getDecreaseScaleButton = () => getButtons().at(0);
const getResetScaleButton = () => getButtons().at(1);
const getIncreaseScaleButton = () => getButtons().at(2);
2020-05-24 23:13:21 +05:30
2021-03-08 18:12:59 +05:30
const setScale = (scale) => wrapper.vm.setScale(scale);
2020-05-24 23:13:21 +05:30
2021-01-29 00:20:46 +05:30
const createComponent = () => {
2021-11-11 11:23:49 +05:30
wrapper = shallowMount(DesignScaler, {
propsData: {
maxScale: 2,
},
});
2020-05-24 23:13:21 +05:30
};
2021-01-29 00:20:46 +05:30
beforeEach(() => {
2020-05-24 23:13:21 +05:30
createComponent();
2021-01-29 00:20:46 +05:30
});
2020-05-24 23:13:21 +05:30
2021-01-29 00:20:46 +05:30
describe('when `scale` value is greater than 1', () => {
beforeEach(async () => {
setScale(1.6);
2022-04-04 11:22:00 +05:30
await nextTick();
2020-05-24 23:13:21 +05:30
});
2021-01-29 00:20:46 +05:30
it('emits @scale event when "reset" button clicked', () => {
getResetScaleButton().vm.$emit('click');
expect(wrapper.emitted('scale')[1]).toEqual([1]);
});
2020-05-24 23:13:21 +05:30
2023-06-20 00:43:36 +05:30
it('emits @scale event when "decrement" button clicked', () => {
2021-01-29 00:20:46 +05:30
getDecreaseScaleButton().vm.$emit('click');
expect(wrapper.emitted('scale')[1]).toEqual([1.4]);
2020-05-24 23:13:21 +05:30
});
2021-01-29 00:20:46 +05:30
it('enables the "reset" button', () => {
const resetButton = getResetScaleButton();
expect(resetButton.exists()).toBe(true);
expect(resetButton.props('disabled')).toBe(false);
});
it('enables the "decrement" button', () => {
const decrementButton = getDecreaseScaleButton();
2020-05-24 23:13:21 +05:30
2021-01-29 00:20:46 +05:30
expect(decrementButton.exists()).toBe(true);
expect(decrementButton.props('disabled')).toBe(false);
});
});
it('emits @scale event when "plus" button clicked', () => {
getIncreaseScaleButton().vm.$emit('click');
expect(wrapper.emitted('scale')).toEqual([[1.2]]);
2020-05-24 23:13:21 +05:30
});
2021-11-11 11:23:49 +05:30
it('computes & increments correct stepSize based on maxScale', async () => {
wrapper.setProps({ maxScale: 11 });
2022-04-04 11:22:00 +05:30
await nextTick();
2021-11-11 11:23:49 +05:30
getIncreaseScaleButton().vm.$emit('click');
2022-04-04 11:22:00 +05:30
await nextTick();
2021-11-11 11:23:49 +05:30
expect(wrapper.emitted().scale[0][0]).toBe(3);
});
2021-01-29 00:20:46 +05:30
describe('when `scale` value is 1', () => {
it('disables the "reset" button', () => {
const resetButton = getResetScaleButton();
expect(resetButton.exists()).toBe(true);
expect(resetButton.props('disabled')).toBe(true);
});
it('disables the "decrement" button', () => {
const decrementButton = getDecreaseScaleButton();
expect(decrementButton.exists()).toBe(true);
expect(decrementButton.props('disabled')).toBe(true);
2020-05-24 23:13:21 +05:30
});
});
2021-11-11 11:23:49 +05:30
describe('when `scale` value is maximum', () => {
2021-01-29 00:20:46 +05:30
beforeEach(async () => {
setScale(2);
2022-04-04 11:22:00 +05:30
await nextTick();
2021-01-29 00:20:46 +05:30
});
it('disables the "increment" button', () => {
const incrementButton = getIncreaseScaleButton();
expect(incrementButton.exists()).toBe(true);
expect(incrementButton.props('disabled')).toBe(true);
2020-05-24 23:13:21 +05:30
});
});
});