2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2017-01-05 12:06:46 +01:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import { shallow } from 'enzyme';
|
2017-02-20 16:40:01 +01:00
|
|
|
import React from 'react';
|
2017-01-05 12:06:46 +01:00
|
|
|
import sinon from 'sinon';
|
|
|
|
|
|
|
|
import ConfirmDialog from './';
|
|
|
|
|
|
|
|
let component;
|
|
|
|
let onConfirm;
|
|
|
|
let onDeny;
|
|
|
|
|
|
|
|
function render (props = {}) {
|
|
|
|
onConfirm = sinon.stub();
|
|
|
|
onDeny = sinon.stub();
|
|
|
|
|
2017-02-20 16:40:01 +01:00
|
|
|
if (props.open === undefined) {
|
|
|
|
props.open = true;
|
2017-01-05 12:06:46 +01:00
|
|
|
}
|
|
|
|
|
2017-02-20 16:40:01 +01:00
|
|
|
component = shallow(
|
2017-01-05 12:06:46 +01:00
|
|
|
<ConfirmDialog
|
|
|
|
{ ...props }
|
|
|
|
title='test title'
|
|
|
|
onConfirm={ onConfirm }
|
2017-01-18 13:05:01 +01:00
|
|
|
onDeny={ onDeny }
|
|
|
|
>
|
2017-01-05 12:06:46 +01:00
|
|
|
<div id='testContent'>
|
|
|
|
some test content
|
|
|
|
</div>
|
|
|
|
</ConfirmDialog>
|
|
|
|
);
|
|
|
|
|
|
|
|
return component;
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('ui/ConfirmDialog', () => {
|
2017-02-20 16:40:01 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
render();
|
|
|
|
});
|
|
|
|
|
2017-01-05 12:06:46 +01:00
|
|
|
it('renders defaults', () => {
|
2017-02-20 16:40:01 +01:00
|
|
|
expect(component).to.be.ok;
|
2017-01-05 12:06:46 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the body as provided', () => {
|
2017-02-20 16:40:01 +01:00
|
|
|
expect(component.find('div[id="testContent"]').text()).to.equal('some test content');
|
2017-01-05 12:06:46 +01:00
|
|
|
});
|
|
|
|
|
2017-02-20 16:40:01 +01:00
|
|
|
describe('Portal properties', () => {
|
2017-01-05 12:06:46 +01:00
|
|
|
let props;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-02-20 16:40:01 +01:00
|
|
|
props = component.find('Portal').props();
|
2017-01-05 12:06:46 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('passes title', () => {
|
|
|
|
expect(props.title).to.equal('test title');
|
|
|
|
});
|
|
|
|
|
2017-02-20 16:40:01 +01:00
|
|
|
it('passes open flag', () => {
|
|
|
|
expect(props.open).to.be.true;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('passes the small flag', () => {
|
|
|
|
expect(props.isSmallModal).to.be.true;
|
2017-01-05 12:06:46 +01:00
|
|
|
});
|
|
|
|
|
2017-02-20 16:40:01 +01:00
|
|
|
it('maps onClose to onDeny', () => {
|
|
|
|
expect(props.onClose).to.equal(onDeny);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('buttons', () => {
|
2017-01-05 12:06:46 +01:00
|
|
|
let buttons;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-02-20 16:40:01 +01:00
|
|
|
buttons = component.props().buttons;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('passes the buttons', () => {
|
|
|
|
expect(buttons.length).to.equal(2);
|
2017-01-05 12:06:46 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders with supplied onConfim/onDeny callbacks', () => {
|
|
|
|
expect(buttons[0].props.onClick).to.deep.equal(onDeny);
|
|
|
|
expect(buttons[1].props.onClick).to.deep.equal(onConfirm);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders default labels', () => {
|
|
|
|
expect(buttons[0].props.label.props.id).to.equal('ui.confirmDialog.no');
|
|
|
|
expect(buttons[1].props.label.props.id).to.equal('ui.confirmDialog.yes');
|
|
|
|
});
|
|
|
|
|
2017-02-20 16:40:01 +01:00
|
|
|
describe('overrides', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
render({
|
|
|
|
labelConfirm: 'labelConfirm',
|
|
|
|
labelDeny: 'labelDeny',
|
|
|
|
iconConfirm: 'iconConfirm',
|
|
|
|
iconDeny: 'iconDeny'
|
|
|
|
});
|
|
|
|
buttons = component.props().buttons;
|
2017-01-05 12:06:46 +01:00
|
|
|
});
|
|
|
|
|
2017-02-20 16:40:01 +01:00
|
|
|
it('renders supplied labels', () => {
|
|
|
|
expect(buttons[0].props.label).to.equal('labelDeny');
|
|
|
|
expect(buttons[1].props.label).to.equal('labelConfirm');
|
|
|
|
});
|
2017-01-05 12:06:46 +01:00
|
|
|
|
2017-02-20 16:40:01 +01:00
|
|
|
it('renders supplied icons', () => {
|
|
|
|
expect(buttons[0].props.icon).to.equal('iconDeny');
|
|
|
|
expect(buttons[1].props.icon).to.equal('iconConfirm');
|
|
|
|
});
|
2017-01-05 12:06:46 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|