2020-11-05 12:09:05 +00:00
|
|
|
import { GlButton } from '@gitlab/ui';
|
2021-02-14 18:09:20 +00:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-05-07 12:09:46 +00:00
|
|
|
import DesignScaler from '~/design_management/components/design_scaler.vue';
|
|
|
|
|
|
|
|
describe('Design management design scaler component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2020-11-05 12:09:05 +00:00
|
|
|
const getButtons = () => wrapper.findAll(GlButton);
|
|
|
|
const getDecreaseScaleButton = () => getButtons().at(0);
|
|
|
|
const getResetScaleButton = () => getButtons().at(1);
|
|
|
|
const getIncreaseScaleButton = () => getButtons().at(2);
|
2020-05-07 12:09:46 +00:00
|
|
|
|
2020-12-23 21:10:24 +00:00
|
|
|
const setScale = (scale) => wrapper.vm.setScale(scale);
|
2020-05-07 12:09:46 +00:00
|
|
|
|
2020-11-05 12:09:05 +00:00
|
|
|
const createComponent = () => {
|
|
|
|
wrapper = shallowMount(DesignScaler);
|
2020-05-07 12:09:46 +00:00
|
|
|
};
|
|
|
|
|
2020-11-05 12:09:05 +00:00
|
|
|
beforeEach(() => {
|
2020-05-07 12:09:46 +00:00
|
|
|
createComponent();
|
2020-11-05 12:09:05 +00:00
|
|
|
});
|
2020-05-07 12:09:46 +00:00
|
|
|
|
2020-11-05 12:09:05 +00:00
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
2020-05-07 12:09:46 +00:00
|
|
|
});
|
|
|
|
|
2020-11-05 12:09:05 +00:00
|
|
|
describe('when `scale` value is greater than 1', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
setScale(1.6);
|
|
|
|
await wrapper.vm.$nextTick();
|
2020-05-07 12:09:46 +00:00
|
|
|
});
|
|
|
|
|
2020-11-05 12:09:05 +00:00
|
|
|
it('emits @scale event when "reset" button clicked', () => {
|
|
|
|
getResetScaleButton().vm.$emit('click');
|
|
|
|
expect(wrapper.emitted('scale')[1]).toEqual([1]);
|
|
|
|
});
|
2020-05-07 12:09:46 +00:00
|
|
|
|
2020-11-05 12:09:05 +00:00
|
|
|
it('emits @scale event when "decrement" button clicked', async () => {
|
|
|
|
getDecreaseScaleButton().vm.$emit('click');
|
|
|
|
expect(wrapper.emitted('scale')[1]).toEqual([1.4]);
|
2020-05-07 12:09:46 +00:00
|
|
|
});
|
|
|
|
|
2020-11-05 12:09:05 +00:00
|
|
|
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-07 12:09:46 +00:00
|
|
|
|
2020-11-05 12:09:05 +00:00
|
|
|
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-07 12:09:46 +00:00
|
|
|
});
|
|
|
|
|
2020-11-05 12:09:05 +00:00
|
|
|
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-07 12:09:46 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-05 12:09:05 +00:00
|
|
|
describe('when `scale` value is 2 (maximum)', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
setScale(2);
|
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('disables the "increment" button', () => {
|
|
|
|
const incrementButton = getIncreaseScaleButton();
|
|
|
|
|
|
|
|
expect(incrementButton.exists()).toBe(true);
|
|
|
|
expect(incrementButton.props('disabled')).toBe(true);
|
2020-05-07 12:09:46 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|