2017-06-07 15:34:19 -04:00
|
|
|
import CloseReopenReportToggle from '~/close_reopen_report_toggle';
|
2017-06-08 12:15:34 -04:00
|
|
|
import DropLab from '~/droplab/drop_lab';
|
2017-06-07 15:34:19 -04:00
|
|
|
|
|
|
|
describe('CloseReopenReportToggle', () => {
|
|
|
|
describe('class constructor', () => {
|
|
|
|
const dropdownTrigger = {};
|
|
|
|
const dropdownList = {};
|
|
|
|
const button = {};
|
|
|
|
let commentTypeToggle;
|
|
|
|
|
2020-05-11 11:09:37 -04:00
|
|
|
beforeEach(() => {
|
2017-06-07 15:34:19 -04:00
|
|
|
commentTypeToggle = new CloseReopenReportToggle({
|
|
|
|
dropdownTrigger,
|
|
|
|
dropdownList,
|
|
|
|
button,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-11 11:09:37 -04:00
|
|
|
it('sets .dropdownTrigger', () => {
|
2017-06-07 15:34:19 -04:00
|
|
|
expect(commentTypeToggle.dropdownTrigger).toBe(dropdownTrigger);
|
|
|
|
});
|
|
|
|
|
2020-05-11 11:09:37 -04:00
|
|
|
it('sets .dropdownList', () => {
|
2017-06-07 15:34:19 -04:00
|
|
|
expect(commentTypeToggle.dropdownList).toBe(dropdownList);
|
|
|
|
});
|
|
|
|
|
2020-05-11 11:09:37 -04:00
|
|
|
it('sets .button', () => {
|
2017-06-07 15:34:19 -04:00
|
|
|
expect(commentTypeToggle.button).toBe(button);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('initDroplab', () => {
|
|
|
|
let closeReopenReportToggle;
|
2020-05-11 11:09:37 -04:00
|
|
|
const dropdownList = {
|
|
|
|
querySelector: jest.fn(),
|
|
|
|
};
|
2017-06-07 15:34:19 -04:00
|
|
|
const dropdownTrigger = {};
|
|
|
|
const button = {};
|
|
|
|
const reopenItem = {};
|
|
|
|
const closeItem = {};
|
|
|
|
const config = {};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-05-11 11:09:37 -04:00
|
|
|
jest.spyOn(DropLab.prototype, 'init').mockImplementation(() => {});
|
|
|
|
dropdownList.querySelector.mockReturnValueOnce(reopenItem).mockReturnValueOnce(closeItem);
|
2017-06-07 15:34:19 -04:00
|
|
|
|
|
|
|
closeReopenReportToggle = new CloseReopenReportToggle({
|
|
|
|
dropdownTrigger,
|
|
|
|
dropdownList,
|
|
|
|
button,
|
|
|
|
});
|
|
|
|
|
2020-05-11 11:09:37 -04:00
|
|
|
jest.spyOn(closeReopenReportToggle, 'setConfig').mockReturnValue(config);
|
2017-06-07 15:34:19 -04:00
|
|
|
|
|
|
|
closeReopenReportToggle.initDroplab();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets .reopenItem and .closeItem', () => {
|
|
|
|
expect(dropdownList.querySelector).toHaveBeenCalledWith('.reopen-item');
|
|
|
|
expect(dropdownList.querySelector).toHaveBeenCalledWith('.close-item');
|
|
|
|
expect(closeReopenReportToggle.reopenItem).toBe(reopenItem);
|
|
|
|
expect(closeReopenReportToggle.closeItem).toBe(closeItem);
|
|
|
|
});
|
|
|
|
|
2017-06-08 12:15:34 -04:00
|
|
|
it('sets .droplab', () => {
|
2020-05-11 11:09:37 -04:00
|
|
|
expect(closeReopenReportToggle.droplab).toEqual(expect.any(Object));
|
2017-06-07 15:34:19 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('calls .setConfig', () => {
|
|
|
|
expect(closeReopenReportToggle.setConfig).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2017-06-08 12:15:34 -04:00
|
|
|
it('calls droplab.init', () => {
|
|
|
|
expect(DropLab.prototype.init).toHaveBeenCalledWith(
|
2017-06-07 15:34:19 -04:00
|
|
|
dropdownTrigger,
|
|
|
|
dropdownList,
|
2020-05-11 11:09:37 -04:00
|
|
|
expect.any(Array),
|
2017-06-07 15:34:19 -04:00
|
|
|
config,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateButton', () => {
|
|
|
|
let closeReopenReportToggle;
|
|
|
|
const dropdownList = {};
|
|
|
|
const dropdownTrigger = {};
|
2020-05-11 11:09:37 -04:00
|
|
|
const button = {
|
|
|
|
blur: jest.fn(),
|
|
|
|
};
|
2017-06-07 15:34:19 -04:00
|
|
|
const isClosed = true;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
closeReopenReportToggle = new CloseReopenReportToggle({
|
|
|
|
dropdownTrigger,
|
|
|
|
dropdownList,
|
|
|
|
button,
|
|
|
|
});
|
|
|
|
|
2020-05-11 11:09:37 -04:00
|
|
|
jest.spyOn(closeReopenReportToggle, 'toggleButtonType').mockImplementation(() => {});
|
2017-06-07 15:34:19 -04:00
|
|
|
|
|
|
|
closeReopenReportToggle.updateButton(isClosed);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls .toggleButtonType', () => {
|
|
|
|
expect(closeReopenReportToggle.toggleButtonType).toHaveBeenCalledWith(isClosed);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls .button.blur', () => {
|
|
|
|
expect(closeReopenReportToggle.button.blur).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('toggleButtonType', () => {
|
|
|
|
let closeReopenReportToggle;
|
|
|
|
const dropdownList = {};
|
|
|
|
const dropdownTrigger = {};
|
|
|
|
const button = {};
|
|
|
|
const isClosed = true;
|
2020-05-11 11:09:37 -04:00
|
|
|
const showItem = {
|
|
|
|
click: jest.fn(),
|
|
|
|
};
|
2017-06-07 15:34:19 -04:00
|
|
|
const hideItem = {};
|
2020-05-11 11:09:37 -04:00
|
|
|
showItem.classList = {
|
|
|
|
add: jest.fn(),
|
|
|
|
remove: jest.fn(),
|
|
|
|
};
|
|
|
|
hideItem.classList = {
|
|
|
|
add: jest.fn(),
|
|
|
|
remove: jest.fn(),
|
|
|
|
};
|
2017-06-07 15:34:19 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
closeReopenReportToggle = new CloseReopenReportToggle({
|
|
|
|
dropdownTrigger,
|
|
|
|
dropdownList,
|
|
|
|
button,
|
|
|
|
});
|
|
|
|
|
2020-05-11 11:09:37 -04:00
|
|
|
jest.spyOn(closeReopenReportToggle, 'getButtonTypes').mockReturnValue([showItem, hideItem]);
|
2017-06-07 15:34:19 -04:00
|
|
|
|
|
|
|
closeReopenReportToggle.toggleButtonType(isClosed);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls .getButtonTypes', () => {
|
|
|
|
expect(closeReopenReportToggle.getButtonTypes).toHaveBeenCalledWith(isClosed);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes hide class and add selected class to showItem, opposite for hideItem', () => {
|
|
|
|
expect(showItem.classList.remove).toHaveBeenCalledWith('hidden');
|
|
|
|
expect(showItem.classList.add).toHaveBeenCalledWith('droplab-item-selected');
|
|
|
|
expect(hideItem.classList.add).toHaveBeenCalledWith('hidden');
|
|
|
|
expect(hideItem.classList.remove).toHaveBeenCalledWith('droplab-item-selected');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('clicks the showItem', () => {
|
|
|
|
expect(showItem.click).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getButtonTypes', () => {
|
|
|
|
let closeReopenReportToggle;
|
|
|
|
const dropdownList = {};
|
|
|
|
const dropdownTrigger = {};
|
|
|
|
const button = {};
|
|
|
|
const reopenItem = {};
|
|
|
|
const closeItem = {};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
closeReopenReportToggle = new CloseReopenReportToggle({
|
|
|
|
dropdownTrigger,
|
|
|
|
dropdownList,
|
|
|
|
button,
|
|
|
|
});
|
|
|
|
|
|
|
|
closeReopenReportToggle.reopenItem = reopenItem;
|
|
|
|
closeReopenReportToggle.closeItem = closeItem;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns reopenItem, closeItem if isClosed is true', () => {
|
|
|
|
const buttonTypes = closeReopenReportToggle.getButtonTypes(true);
|
|
|
|
|
|
|
|
expect(buttonTypes).toEqual([reopenItem, closeItem]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns closeItem, reopenItem if isClosed is false', () => {
|
|
|
|
const buttonTypes = closeReopenReportToggle.getButtonTypes(false);
|
|
|
|
|
|
|
|
expect(buttonTypes).toEqual([closeItem, reopenItem]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setDisable', () => {
|
|
|
|
let closeReopenReportToggle;
|
|
|
|
const dropdownList = {};
|
2020-05-11 11:09:37 -04:00
|
|
|
const dropdownTrigger = {
|
|
|
|
setAttribute: jest.fn(),
|
|
|
|
removeAttribute: jest.fn(),
|
|
|
|
};
|
|
|
|
const button = {
|
|
|
|
setAttribute: jest.fn(),
|
|
|
|
removeAttribute: jest.fn(),
|
|
|
|
};
|
2017-06-07 15:34:19 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
closeReopenReportToggle = new CloseReopenReportToggle({
|
|
|
|
dropdownTrigger,
|
|
|
|
dropdownList,
|
|
|
|
button,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('disable .button and .dropdownTrigger if shouldDisable is true', () => {
|
|
|
|
closeReopenReportToggle.setDisable(true);
|
|
|
|
|
|
|
|
expect(button.setAttribute).toHaveBeenCalledWith('disabled', 'true');
|
|
|
|
expect(dropdownTrigger.setAttribute).toHaveBeenCalledWith('disabled', 'true');
|
|
|
|
});
|
|
|
|
|
2017-07-04 09:41:26 -04:00
|
|
|
it('disable .button and .dropdownTrigger if shouldDisable is undefined', () => {
|
|
|
|
closeReopenReportToggle.setDisable();
|
|
|
|
|
|
|
|
expect(button.setAttribute).toHaveBeenCalledWith('disabled', 'true');
|
|
|
|
expect(dropdownTrigger.setAttribute).toHaveBeenCalledWith('disabled', 'true');
|
|
|
|
});
|
|
|
|
|
2017-06-07 15:34:19 -04:00
|
|
|
it('enable .button and .dropdownTrigger if shouldDisable is false', () => {
|
|
|
|
closeReopenReportToggle.setDisable(false);
|
|
|
|
|
|
|
|
expect(button.removeAttribute).toHaveBeenCalledWith('disabled');
|
|
|
|
expect(dropdownTrigger.removeAttribute).toHaveBeenCalledWith('disabled');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setConfig', () => {
|
|
|
|
let closeReopenReportToggle;
|
|
|
|
const dropdownList = {};
|
|
|
|
const dropdownTrigger = {};
|
|
|
|
const button = {};
|
|
|
|
let config;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
closeReopenReportToggle = new CloseReopenReportToggle({
|
|
|
|
dropdownTrigger,
|
|
|
|
dropdownList,
|
|
|
|
button,
|
|
|
|
});
|
|
|
|
|
|
|
|
config = closeReopenReportToggle.setConfig();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns a config object', () => {
|
|
|
|
expect(config).toEqual({
|
|
|
|
InputSetter: [
|
|
|
|
{
|
|
|
|
input: button,
|
|
|
|
valueAttribute: 'data-text',
|
|
|
|
inputAttribute: 'data-value',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: button,
|
|
|
|
valueAttribute: 'data-text',
|
|
|
|
inputAttribute: 'title',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: button,
|
|
|
|
valueAttribute: 'data-button-class',
|
|
|
|
inputAttribute: 'class',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: dropdownTrigger,
|
|
|
|
valueAttribute: 'data-toggle-class',
|
|
|
|
inputAttribute: 'class',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: button,
|
|
|
|
valueAttribute: 'data-url',
|
2020-06-23 05:08:47 -04:00
|
|
|
inputAttribute: 'data-endpoint',
|
2017-06-07 15:34:19 -04:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|