2017-06-08 01:39:11 +05:30
|
|
|
import React from 'react';
|
|
|
|
import sinon from 'sinon';
|
2019-12-08 00:32:00 +05:30
|
|
|
import expect from 'app/test/unexpected';
|
2019-11-27 14:33:32 +05:30
|
|
|
import { shallow } from 'enzyme';
|
2017-06-08 01:39:11 +05:30
|
|
|
|
|
|
|
import RulesPage from './RulesPage';
|
|
|
|
|
|
|
|
describe('RulesPage', () => {
|
2019-11-27 14:33:32 +05:30
|
|
|
describe('#onRuleClick()', () => {
|
|
|
|
const id = 'rule-1-2';
|
|
|
|
const pathname = '/foo';
|
|
|
|
const search = '?bar';
|
|
|
|
let page;
|
|
|
|
let replace;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
replace = sinon.stub().named('history.replace');
|
|
|
|
|
|
|
|
page = shallow(
|
2019-12-07 16:58:52 +05:30
|
|
|
<RulesPage
|
|
|
|
location={{ pathname, search } as any}
|
|
|
|
history={{ replace }}
|
|
|
|
/>,
|
2019-11-27 14:33:32 +05:30
|
|
|
);
|
2017-06-08 01:39:11 +05:30
|
|
|
});
|
2019-11-27 14:33:32 +05:30
|
|
|
|
|
|
|
it('should update location on rule click', () => {
|
|
|
|
const expectedUrl = `/foo?bar#${id}`;
|
|
|
|
|
|
|
|
page.find(`#${id}`).simulate('click', {
|
|
|
|
target: document.createElement('li'),
|
|
|
|
|
|
|
|
currentTarget: {
|
|
|
|
id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(replace, 'to have a call satisfying', [expectedUrl]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not update location if link was clicked', () => {
|
|
|
|
page.find(`#${id}`).simulate('click', {
|
|
|
|
target: document.createElement('a'),
|
|
|
|
|
|
|
|
currentTarget: {
|
|
|
|
id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(replace, 'was not called');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not update location if defaultPrevented', () => {
|
|
|
|
page.find(`#${id}`).simulate('click', {
|
|
|
|
defaultPrevented: true,
|
|
|
|
|
|
|
|
target: {
|
|
|
|
tagName: 'li',
|
|
|
|
},
|
|
|
|
|
|
|
|
currentTarget: {
|
|
|
|
id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(replace, 'was not called');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not update location if no id', () => {
|
|
|
|
page.find(`#${id}`).simulate('click', {
|
|
|
|
target: {
|
|
|
|
tagName: 'li',
|
|
|
|
},
|
|
|
|
|
|
|
|
currentTarget: {},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(replace, 'was not called');
|
|
|
|
});
|
|
|
|
});
|
2017-06-08 01:39:11 +05:30
|
|
|
});
|