Commit 38a4b371 authored by Tom Quirk's avatar Tom Quirk Committed by Brandon Labuschagne

Refactor design scaler tests

This commit is in light of the previous commit,
where GlButtonGroup is now used in the component.
parent 43290d0d
<script> <script>
import { GlIcon } from '@gitlab/ui'; import { GlButtonGroup, GlButton } from '@gitlab/ui';
const SCALE_STEP_SIZE = 0.2; const SCALE_STEP_SIZE = 0.2;
const DEFAULT_SCALE = 1; const DEFAULT_SCALE = 1;
...@@ -8,7 +8,8 @@ const MAX_SCALE = 2; ...@@ -8,7 +8,8 @@ const MAX_SCALE = 2;
export default { export default {
components: { components: {
GlIcon, GlButtonGroup,
GlButton,
}, },
data() { data() {
return { return {
...@@ -49,17 +50,9 @@ export default { ...@@ -49,17 +50,9 @@ export default {
</script> </script>
<template> <template>
<div class="design-scaler btn-group" role="group"> <gl-button-group class="gl-z-index-1">
<button class="btn" :disabled="disableDecrease" @click="decrementScale"> <gl-button icon="dash" :disabled="disableDecrease" @click="decrementScale" />
<span class="gl-display-flex gl-justify-content-center gl-align-items-center gl-icon s16"> <gl-button icon="redo" :disabled="disableReset" @click="resetScale" />
<gl-button icon="plus" :disabled="disableIncrease" @click="incrementScale" />
</span> </gl-button-group>
</button>
<button class="btn" :disabled="disableReset" @click="resetScale">
<gl-icon name="redo" />
</button>
<button class="btn" :disabled="disableIncrease" @click="incrementScale">
<gl-icon name="plus" />
</button>
</div>
</template> </template>
...@@ -75,10 +75,6 @@ $t-gray-a-16-design-pin: rgba($black, 0.16); ...@@ -75,10 +75,6 @@ $t-gray-a-16-design-pin: rgba($black, 0.16);
left: 0; left: 0;
} }
.design-scaler {
z-index: 1;
}
.design-scaler-wrapper { .design-scaler-wrapper {
bottom: 0; bottom: 0;
left: 50%; left: 50%;
......
---
title: Refresh design zooming buttons
merge_request: 46205
author:
type: changed
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Design management design scaler component minus and reset buttons are disabled when scale === 1 1`] = `
<div
class="design-scaler btn-group"
role="group"
>
<button
class="btn"
disabled="disabled"
>
<span
class="gl-display-flex gl-justify-content-center gl-align-items-center gl-icon s16"
>
</span>
</button>
<button
class="btn"
disabled="disabled"
>
<gl-icon-stub
name="redo"
size="16"
/>
</button>
<button
class="btn"
>
<gl-icon-stub
name="plus"
size="16"
/>
</button>
</div>
`;
exports[`Design management design scaler component minus and reset buttons are enabled when scale > 1 1`] = `
<div
class="design-scaler btn-group"
role="group"
>
<button
class="btn"
>
<span
class="gl-display-flex gl-justify-content-center gl-align-items-center gl-icon s16"
>
</span>
</button>
<button
class="btn"
>
<gl-icon-stub
name="redo"
size="16"
/>
</button>
<button
class="btn"
>
<gl-icon-stub
name="plus"
size="16"
/>
</button>
</div>
`;
exports[`Design management design scaler component plus button is disabled when scale === 2 1`] = `
<div
class="design-scaler btn-group"
role="group"
>
<button
class="btn"
>
<span
class="gl-display-flex gl-justify-content-center gl-align-items-center gl-icon s16"
>
</span>
</button>
<button
class="btn"
>
<gl-icon-stub
name="redo"
size="16"
/>
</button>
<button
class="btn"
disabled="disabled"
>
<gl-icon-stub
name="plus"
size="16"
/>
</button>
</div>
`;
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlButton } from '@gitlab/ui';
import DesignScaler from '~/design_management/components/design_scaler.vue'; import DesignScaler from '~/design_management/components/design_scaler.vue';
describe('Design management design scaler component', () => { describe('Design management design scaler component', () => {
let wrapper; let wrapper;
function createComponent(propsData, data = {}) { const getButtons = () => wrapper.findAll(GlButton);
wrapper = shallowMount(DesignScaler, { const getDecreaseScaleButton = () => getButtons().at(0);
propsData, const getResetScaleButton = () => getButtons().at(1);
const getIncreaseScaleButton = () => getButtons().at(2);
const setScale = scale => wrapper.vm.setScale(scale);
const createComponent = () => {
wrapper = shallowMount(DesignScaler);
};
beforeEach(() => {
createComponent();
}); });
wrapper.setData(data);
}
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
}); });
const getButton = type => { describe('when `scale` value is greater than 1', () => {
const buttonTypeOrder = ['minus', 'reset', 'plus']; beforeEach(async () => {
const buttons = wrapper.findAll('button'); setScale(1.6);
return buttons.at(buttonTypeOrder.indexOf(type)); await wrapper.vm.$nextTick();
}; });
it('emits @scale event when "plus" button clicked', () => {
createComponent();
getButton('plus').trigger('click'); it('emits @scale event when "reset" button clicked', () => {
expect(wrapper.emitted('scale')).toEqual([[1.2]]); getResetScaleButton().vm.$emit('click');
expect(wrapper.emitted('scale')[1]).toEqual([1]);
}); });
it('emits @scale event when "reset" button clicked (scale > 1)', () => { it('emits @scale event when "decrement" button clicked', async () => {
createComponent({}, { scale: 1.6 }); getDecreaseScaleButton().vm.$emit('click');
return wrapper.vm.$nextTick().then(() => { expect(wrapper.emitted('scale')[1]).toEqual([1.4]);
getButton('reset').trigger('click');
expect(wrapper.emitted('scale')).toEqual([[1]]);
}); });
it('enables the "reset" button', () => {
const resetButton = getResetScaleButton();
expect(resetButton.exists()).toBe(true);
expect(resetButton.props('disabled')).toBe(false);
}); });
it('emits @scale event when "minus" button clicked (scale > 1)', () => { it('enables the "decrement" button', () => {
createComponent({}, { scale: 1.6 }); const decrementButton = getDecreaseScaleButton();
return wrapper.vm.$nextTick().then(() => { expect(decrementButton.exists()).toBe(true);
getButton('minus').trigger('click'); expect(decrementButton.props('disabled')).toBe(false);
expect(wrapper.emitted('scale')).toEqual([[1.4]]);
}); });
}); });
it('minus and reset buttons are disabled when scale === 1', () => { it('emits @scale event when "plus" button clicked', () => {
createComponent(); getIncreaseScaleButton().vm.$emit('click');
expect(wrapper.emitted('scale')).toEqual([[1.2]]);
});
expect(wrapper.element).toMatchSnapshot(); 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('minus and reset buttons are enabled when scale > 1', () => { it('disables the "decrement" button', () => {
createComponent({}, { scale: 1.2 }); const decrementButton = getDecreaseScaleButton();
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.element).toMatchSnapshot(); expect(decrementButton.exists()).toBe(true);
expect(decrementButton.props('disabled')).toBe(true);
}); });
}); });
it('plus button is disabled when scale === 2', () => { describe('when `scale` value is 2 (maximum)', () => {
createComponent({}, { scale: 2 }); beforeEach(async () => {
return wrapper.vm.$nextTick().then(() => { setScale(2);
expect(wrapper.element).toMatchSnapshot(); await wrapper.vm.$nextTick();
});
it('disables the "increment" button', () => {
const incrementButton = getIncreaseScaleButton();
expect(incrementButton.exists()).toBe(true);
expect(incrementButton.props('disabled')).toBe(true);
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment