Skip to content

Commit

Permalink
Rebased to master
Browse files Browse the repository at this point in the history
  • Loading branch information
ranbena committed Jan 13, 2019
1 parent a746c6f commit 8b25d8a
Showing 1 changed file with 12 additions and 64 deletions.
76 changes: 12 additions & 64 deletions client/app/components/queries/ScheduleDialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,6 @@ function findByTestID(wrapper, id) {
return wrapper.find(`[data-testid="${id}"]`);
}

function getSelectOptions(wrapper) {
jest.useFakeTimers();

// click select
wrapper.find('.ant-select').simulate('click');

// run timers
jest.runAllTimers();
jest.useRealTimers();

// get dropdown menu
const dropdown = mount(wrapper
.find('Trigger')
.instance()
.getComponent());

// get menu items
return dropdown.find('MenuItem');
}

describe('ScheduleDialog', () => {
describe('Sets correct schedule settings', () => {
test('Sets to "Never"', () => {
Expand Down Expand Up @@ -134,62 +114,30 @@ describe('ScheduleDialog', () => {

describe('Adheres to user permissions', () => {
test('Shows correct interval options', () => {
const refreshOptions = [60, 3600]; // 1 min, 1 hour
const refreshOptions = [60, 300, 3600, 7200]; // 1 min, 1 hour
const [wrapper] = getWrapper(null, { refreshOptions });
const selectWrapper = findByTestID(wrapper, 'select-interval');
const options = getSelectOptions(selectWrapper);

const texts = options.map(node => node.text());
const expected = ['Never', 'minute(s)', 'hour(s)'];

// eslint-disable-next-line jest/prefer-to-have-length
expect(options.length).toEqual(expected.length);
expect(texts).toEqual(expected);
});
// click select
findByTestID(wrapper, 'interval')
.find('.ant-select')
.simulate('click');

// skipped due to issue #3263 https://git.io/fhZcG
// eslint-disable-next-line jest/no-disabled-tests
test.skip('Shows correct count options', () => {
const [wrapper] = getWrapper({ interval: 300 });
const selectWrapper = findByTestID(wrapper, 'select-count');
const options = getSelectOptions(selectWrapper);
// get dropdown menu items
const options = mount(wrapper
.find('Trigger')
.instance()
.getComponent())
.find('MenuItem');

const texts = options.map(node => node.text());
const expected = ['1', '5', '10'];
const expected = ['Never', '1 minute', '5 minutes', '1 hour', '2 hours'];

// eslint-disable-next-line jest/prefer-to-have-length
expect(options.length).toEqual(expected.length);
expect(texts).toEqual(expected);
});
});

test('Resets selected count value if out-of-range', () => {
// init
const initProps = { interval: 600 };
const [wrapper] = getWrapper(initProps);

const intervalWrapper = findByTestID(wrapper, 'select-interval');
const options = getSelectOptions(intervalWrapper);

// change to 'hours(s)'
options
.filterWhere(node => node.text() === 'hour(s)')
.simulate('click');
wrapper.update();

// should stay '10'
expect(wrapper.state('count')).toBe('10');

// change to 'week(s)'
options
.filterWhere(node => node.text() === 'week(s)')
.simulate('click');
wrapper.update();

// should have changed to '1'
expect(wrapper.state('count')).toBe('1');
});

describe('Modal Confirm/Cancel feature', () => {
const confirmCb = jest.fn().mockName('confirmCb');
const closeCb = jest.fn().mockName('closeCb');
Expand Down

0 comments on commit 8b25d8a

Please sign in to comment.