accounts-frontend/src/pages/rules/RulesPage.test.js

82 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-06-08 01:39:11 +05:30
import React from 'react';
import sinon from 'sinon';
import expect from 'unexpected';
import {shallow} from 'enzyme';
import RulesPage from './RulesPage';
describe('RulesPage', () => {
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(<RulesPage
location={{pathname, search}}
history={{replace}}
/>);
});
it('should update location on rule click', () => {
const expectedUrl = `/foo?bar#${id}`;
page.find(`#${id}`).simulate('click', {
2017-09-09 19:52:19 +05:30
target: document.createElement('li'),
2017-06-08 01:39:11 +05:30
currentTarget: {
id
}
});
expect(replace, 'to have a call satisfying', [expectedUrl]);
});
it('should not update location if link was clicked', () => {
page.find(`#${id}`).simulate('click', {
2017-09-09 19:52:19 +05:30
target: document.createElement('a'),
2017-06-08 01:39:11 +05:30
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');
});
});
});