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);
wrapper.setData(data);
}
afterEach(() => { const setScale = scale => wrapper.vm.setScale(scale);
wrapper.destroy();
});
const getButton = type => { const createComponent = () => {
const buttonTypeOrder = ['minus', 'reset', 'plus']; wrapper = shallowMount(DesignScaler);
const buttons = wrapper.findAll('button');
return buttons.at(buttonTypeOrder.indexOf(type));
}; };
it('emits @scale event when "plus" button clicked', () => { beforeEach(() => {
createComponent(); createComponent();
});
getButton('plus').trigger('click'); afterEach(() => {
expect(wrapper.emitted('scale')).toEqual([[1.2]]); wrapper.destroy();
wrapper = null;
}); });
it('emits @scale event when "reset" button clicked (scale > 1)', () => { describe('when `scale` value is greater than 1', () => {
createComponent({}, { scale: 1.6 }); beforeEach(async () => {
return wrapper.vm.$nextTick().then(() => { setScale(1.6);
getButton('reset').trigger('click'); await wrapper.vm.$nextTick();
expect(wrapper.emitted('scale')).toEqual([[1]]);
}); });
});
it('emits @scale event when "minus" button clicked (scale > 1)', () => { it('emits @scale event when "reset" button clicked', () => {
createComponent({}, { scale: 1.6 }); getResetScaleButton().vm.$emit('click');
expect(wrapper.emitted('scale')[1]).toEqual([1]);
});
return wrapper.vm.$nextTick().then(() => { it('emits @scale event when "decrement" button clicked', async () => {
getButton('minus').trigger('click'); getDecreaseScaleButton().vm.$emit('click');
expect(wrapper.emitted('scale')).toEqual([[1.4]]); expect(wrapper.emitted('scale')[1]).toEqual([1.4]);
}); });
});
it('minus and reset buttons are disabled when scale === 1', () => { it('enables the "reset" button', () => {
createComponent(); const resetButton = getResetScaleButton();
expect(resetButton.exists()).toBe(true);
expect(resetButton.props('disabled')).toBe(false);
});
it('enables the "decrement" button', () => {
const decrementButton = getDecreaseScaleButton();
expect(wrapper.element).toMatchSnapshot(); 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]]);
}); });
it('minus and reset buttons are enabled when scale > 1', () => { describe('when `scale` value is 1', () => {
createComponent({}, { scale: 1.2 }); it('disables the "reset" button', () => {
return wrapper.vm.$nextTick().then(() => { const resetButton = getResetScaleButton();
expect(wrapper.element).toMatchSnapshot();
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);
}); });
}); });
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