2019-11-22 04:06:20 -05:00
|
|
|
import Vue from 'vue';
|
2020-01-09 04:07:51 -05:00
|
|
|
import { mount } from '@vue/test-utils';
|
2019-11-22 04:06:20 -05:00
|
|
|
import ExpandButton from '~/vue_shared/components/expand_button.vue';
|
|
|
|
|
|
|
|
const text = {
|
|
|
|
expanded: 'Expanded!',
|
|
|
|
short: 'Short',
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('Expand button', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const expanderPrependEl = () => wrapper.find('.js-text-expander-prepend');
|
|
|
|
const expanderAppendEl = () => wrapper.find('.js-text-expander-append');
|
|
|
|
|
|
|
|
const factory = (options = {}) => {
|
2020-01-09 04:07:51 -05:00
|
|
|
wrapper = mount(ExpandButton, {
|
2019-11-22 04:06:20 -05:00
|
|
|
...options,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
slots: {
|
|
|
|
expanded: `<p>${text.expanded}</p>`,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the prepended collapse button', () => {
|
|
|
|
expect(expanderPrependEl().isVisible()).toBe(true);
|
|
|
|
expect(expanderAppendEl().isVisible()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders no text when short text is not provided', () => {
|
|
|
|
expect(wrapper.find(ExpandButton).text()).toBe('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render expanded text', () => {
|
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find(ExpandButton)
|
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
).not.toBe(text.short);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when short text is provided', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
slots: {
|
|
|
|
expanded: `<p>${text.expanded}</p>`,
|
|
|
|
short: `<p>${text.short}</p>`,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders short text', () => {
|
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find(ExpandButton)
|
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
).toBe(text.short);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders button before text', () => {
|
|
|
|
expect(expanderPrependEl().isVisible()).toBe(true);
|
|
|
|
expect(expanderAppendEl().isVisible()).toBe(false);
|
2020-01-22 07:08:40 -05:00
|
|
|
expect(wrapper.find(ExpandButton).element).toMatchSnapshot();
|
2019-11-22 04:06:20 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('on click', () => {
|
|
|
|
beforeEach(done => {
|
|
|
|
expanderPrependEl().trigger('click');
|
|
|
|
Vue.nextTick(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
expanderAppendEl().trigger('click');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders only the append collapse button', () => {
|
|
|
|
expect(expanderAppendEl().isVisible()).toBe(true);
|
|
|
|
expect(expanderPrependEl().isVisible()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the expanded text', () => {
|
|
|
|
expect(wrapper.find(ExpandButton).text()).toContain(text.expanded);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when short text is provided', () => {
|
|
|
|
beforeEach(done => {
|
|
|
|
factory({
|
|
|
|
slots: {
|
|
|
|
expanded: `<p>${text.expanded}</p>`,
|
|
|
|
short: `<p>${text.short}</p>`,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expanderPrependEl().trigger('click');
|
|
|
|
Vue.nextTick(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('only renders expanded text', () => {
|
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find(ExpandButton)
|
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
).toBe(text.expanded);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders button after text', () => {
|
|
|
|
expect(expanderPrependEl().isVisible()).toBe(false);
|
|
|
|
expect(expanderAppendEl().isVisible()).toBe(true);
|
2020-01-22 07:08:40 -05:00
|
|
|
expect(wrapper.find(ExpandButton).element).toMatchSnapshot();
|
2019-11-22 04:06:20 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('append button', () => {
|
|
|
|
beforeEach(done => {
|
|
|
|
expanderPrependEl().trigger('click');
|
|
|
|
Vue.nextTick(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('clicking hides itself and shows prepend', () => {
|
|
|
|
expect(expanderAppendEl().isVisible()).toBe(true);
|
|
|
|
expanderAppendEl().trigger('click');
|
2020-01-01 01:09:01 -05:00
|
|
|
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(expanderPrependEl().isVisible()).toBe(true);
|
|
|
|
});
|
2019-11-22 04:06:20 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('clicking hides expanded text', () => {
|
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find(ExpandButton)
|
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
).toBe(text.expanded);
|
|
|
|
expanderAppendEl().trigger('click');
|
2020-01-01 01:09:01 -05:00
|
|
|
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find(ExpandButton)
|
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
).not.toBe(text.expanded);
|
|
|
|
});
|
2019-11-22 04:06:20 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('when short text is provided', () => {
|
|
|
|
beforeEach(done => {
|
|
|
|
factory({
|
|
|
|
slots: {
|
|
|
|
expanded: `<p>${text.expanded}</p>`,
|
|
|
|
short: `<p>${text.short}</p>`,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expanderPrependEl().trigger('click');
|
|
|
|
Vue.nextTick(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('clicking reveals short text', () => {
|
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find(ExpandButton)
|
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
).toBe(text.expanded);
|
|
|
|
expanderAppendEl().trigger('click');
|
2020-01-01 01:09:01 -05:00
|
|
|
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find(ExpandButton)
|
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
).toBe(text.short);
|
|
|
|
});
|
2019-11-22 04:06:20 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|