lucid-ui
Version:
A UI component library from AppNexus.
90 lines • 3.28 kB
JavaScript
import React from 'react';
import { mount, shallow } from 'enzyme';
import { common, functionalComponents } from '../../util/generic-tests';
import assert from 'assert';
import Dialog from './Dialog';
import Overlay from '../Overlay/Overlay';
describe('Dialog', function () {
common(Dialog, {
getDefaultProps: function getDefaultProps() {
return {
isShown: true
};
},
selectRoot: function selectRoot(wrapper) {
return wrapper.find('.lucid-Dialog');
}
});
functionalComponents(Dialog);
it('should pass `isModal` to underlying Overlay', function () {
var wrapper = shallow( /*#__PURE__*/React.createElement(Dialog, {
isModal: false
}));
assert.equal(wrapper.find(Overlay).prop('isModal'), false);
});
it('should render a Header', function () {
var wrapper = shallow( /*#__PURE__*/React.createElement(Dialog, {
isShown: true
}, /*#__PURE__*/React.createElement(Dialog.Header, null, "Mobius")));
assert.equal(wrapper.find('.lucid-Dialog-header').text().startsWith('Mobius'), true);
});
it('should render a Footer', function () {
var wrapper = shallow( /*#__PURE__*/React.createElement(Dialog, {
isShown: true
}, /*#__PURE__*/React.createElement(Dialog.Footer, null, "Groober")));
assert.equal(wrapper.find('.lucid-Dialog-footer').text(), 'Groober');
});
it('should not render a Footer', function () {
var wrapper = shallow( /*#__PURE__*/React.createElement(Dialog, {
isShown: true
}));
assert(!wrapper.contains('.lucid-Dialog-footer'));
});
it('should render body content', function () {
var wrapper = shallow( /*#__PURE__*/React.createElement(Dialog, {
isShown: true
}, "Flux Capacitor"));
assert.equal(wrapper.find('.lucid-Dialog-body').text(), 'Flux Capacitor');
});
it('should respect size = "small"', function () {
var wrapper = shallow( /*#__PURE__*/React.createElement(Dialog, {
isShown: true,
size: "small"
}));
assert.equal(wrapper.find('.lucid-Dialog-window-is-small').length, 1);
});
it('should respect size = "medium"', function () {
var wrapper = shallow( /*#__PURE__*/React.createElement(Dialog, {
isShown: true,
size: "medium"
}));
assert.equal(wrapper.find('.lucid-Dialog-window-is-medium').length, 1);
});
it('should respect size = "large"', function () {
var wrapper = shallow( /*#__PURE__*/React.createElement(Dialog, {
isShown: true,
size: "large"
}));
assert.equal(wrapper.find('.lucid-Dialog-window-is-large').length, 1);
});
});
describe('Dialog', function () {
it('should render when isShown', function () {
var wrapper = mount( /*#__PURE__*/React.createElement(Dialog, {
isShown: true
}, /*#__PURE__*/React.createElement("div", {
id: "holler"
}, "bro")));
assert.equal(document.querySelectorAll('#holler').length, 1);
wrapper.unmount();
});
it('should not render when not isShown', function () {
var wrapper = mount( /*#__PURE__*/React.createElement(Dialog, {
isShown: false
}, /*#__PURE__*/React.createElement("div", {
id: "flux"
}, "Flux Capacitor")));
assert.equal(document.querySelectorAll('#flux').length, 0);
wrapper.unmount();
});
});