2017-12-08 07:26:39 -05:00
|
|
|
import Vue from 'vue';
|
2020-06-08 08:08:26 -04:00
|
|
|
import mountComponent from 'helpers/vue_mount_component_helper';
|
2019-12-06 04:06:39 -05:00
|
|
|
import DeprecatedModal from '~/vue_shared/components/deprecated_modal.vue';
|
2017-12-08 07:26:39 -05:00
|
|
|
|
2018-02-28 16:47:44 -05:00
|
|
|
const modalComponent = Vue.extend(DeprecatedModal);
|
2018-01-03 04:21:17 -05:00
|
|
|
|
2018-02-28 16:47:44 -05:00
|
|
|
describe('DeprecatedModal', () => {
|
2018-01-03 04:21:17 -05:00
|
|
|
let vm;
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('props', () => {
|
|
|
|
describe('without primaryButtonLabel', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
vm = mountComponent(modalComponent, {
|
|
|
|
primaryButtonLabel: null,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render a primary button', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-primary-button')).toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with id', () => {
|
2018-01-23 10:19:56 -05:00
|
|
|
describe('does not render a primary button', () => {
|
2018-01-03 04:21:17 -05:00
|
|
|
beforeEach(() => {
|
|
|
|
vm = mountComponent(modalComponent, {
|
|
|
|
id: 'my-modal',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('assigns the id to the modal', () => {
|
|
|
|
expect(vm.$el.querySelector('#my-modal.modal')).not.toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show the modal immediately', () => {
|
|
|
|
expect(vm.$el.querySelector('#my-modal.modal')).not.toHaveClass('show');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show a backdrop', () => {
|
|
|
|
expect(vm.$el.querySelector('modal-backdrop')).toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-08 08:08:26 -04:00
|
|
|
it('works with data-toggle="modal"', () => {
|
2018-01-03 04:21:17 -05:00
|
|
|
setFixtures(`
|
|
|
|
<button id="modal-button" data-toggle="modal" data-target="#my-modal"></button>
|
|
|
|
<div id="modal-container"></div>
|
|
|
|
`);
|
|
|
|
|
|
|
|
const modalContainer = document.getElementById('modal-container');
|
|
|
|
const modalButton = document.getElementById('modal-button');
|
2018-10-17 03:13:26 -04:00
|
|
|
vm = mountComponent(
|
|
|
|
modalComponent,
|
|
|
|
{
|
|
|
|
id: 'my-modal',
|
|
|
|
},
|
|
|
|
modalContainer,
|
|
|
|
);
|
2018-01-03 04:21:17 -05:00
|
|
|
const modalElement = vm.$el.querySelector('#my-modal');
|
2020-06-08 08:08:26 -04:00
|
|
|
|
|
|
|
expect(modalElement).not.toHaveClass('show');
|
2017-12-08 07:26:39 -05:00
|
|
|
|
2018-01-03 04:21:17 -05:00
|
|
|
modalButton.click();
|
2020-06-08 08:08:26 -04:00
|
|
|
|
|
|
|
expect(modalElement).toHaveClass('show');
|
2018-01-03 04:21:17 -05:00
|
|
|
});
|
2017-12-08 07:26:39 -05:00
|
|
|
});
|
|
|
|
});
|