Commit a628a289 authored by Paul Slaughter's avatar Paul Slaughter

Add content_transition unit tests

- It needs to be tested yo
parent 9a23bf3f
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`~/vue_shared/components/content_transition.vue default shows all transitions and only default is visible 1`] = `
<div>
<transition-stub
name="test_transition_name"
>
<div
data-testval="default"
>
<p>
Default
</p>
</div>
</transition-stub>
<transition-stub
name="test_transition_name"
>
<div
data-testval="foo"
style="display: none;"
>
<p>
Foo
</p>
</div>
</transition-stub>
<transition-stub
name="test_transition_name"
>
<div
data-testval="bar"
style="display: none;"
>
<p>
Bar
</p>
</div>
</transition-stub>
</div>
`;
import { groupBy, mapValues } from 'lodash';
import { shallowMount } from '@vue/test-utils';
import ContentTransition from '~/vue_shared/components/content_transition.vue';
const TEST_CURRENT_SLOT = 'default';
const TEST_TRANSITION_NAME = 'test_transition_name';
const TEST_SLOTS = [
{ key: 'default', attributes: { 'data-testval': 'default' } },
{ key: 'foo', attributes: { 'data-testval': 'foo' } },
{ key: 'bar', attributes: { 'data-testval': 'bar' } },
];
describe('~/vue_shared/components/content_transition.vue', () => {
let wrapper;
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
const createComponent = (props = {}, slots = {}) => {
wrapper = shallowMount(ContentTransition, {
propsData: {
transitionName: TEST_TRANSITION_NAME,
currentSlot: TEST_CURRENT_SLOT,
slots: TEST_SLOTS,
...props,
},
slots: {
default: '<p>Default</p>',
foo: '<p>Foo</p>',
bar: '<p>Bar</p>',
dne: '<p>DOES NOT EXIST</p>',
...slots,
},
});
};
const findTransitionsData = () =>
wrapper.findAll('transition-stub').wrappers.map((transition) => {
const child = transition.find('[data-testval]');
const { style, ...attributes } = child.attributes();
return {
transitionName: transition.attributes('name'),
isVisible: child.isVisible(),
attributes,
text: transition.text(),
};
});
const findVisibleData = () => {
const group = groupBy(findTransitionsData(), (x) => x.attributes['data-testval']);
return mapValues(group, (x) => x[0].isVisible);
};
describe('default', () => {
beforeEach(() => {
createComponent();
});
it('shows all transitions and only default is visible', () => {
expect(wrapper.element).toMatchSnapshot();
});
it('render transitions for each slot', () => {
expect(findTransitionsData()).toEqual([
{
attributes: {
'data-testval': 'default',
},
isVisible: true,
text: 'Default',
transitionName: 'test_transition_name',
},
{
attributes: {
'data-testval': 'foo',
},
isVisible: false,
text: 'Foo',
transitionName: 'test_transition_name',
},
{
attributes: {
'data-testval': 'bar',
},
isVisible: false,
text: 'Bar',
transitionName: 'test_transition_name',
},
]);
});
});
describe('with currentSlot=foo', () => {
beforeEach(() => {
createComponent({ currentSlot: 'foo' });
});
it('should only show the foo slot', () => {
expect(findVisibleData()).toEqual({
default: false,
foo: true,
bar: false,
});
});
});
});
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