2017-06-08 01:39:11 +05:30
|
|
|
import React from 'react';
|
|
|
|
import sinon from 'sinon';
|
2019-06-30 19:02:50 +05:30
|
|
|
import expect from '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
|
|
|
});
|