auth0-lock
Version:
Auth0 Lock
109 lines (107 loc) • 4.81 kB
JavaScript
"use strict";
var _react = _interopRequireDefault(require("react"));
var _enzyme = require("enzyme");
var _testUtils = require("../../testUtils");
var _global_message = _interopRequireDefault(require("ui/box/global_message"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
describe('GlobalMessage', function () {
it('renders correctly given a success type', function () {
(0, _testUtils.expectComponent)(/*#__PURE__*/_react.default.createElement(_global_message.default, {
type: "success",
message: "Success!"
})).toMatchSnapshot();
});
it('renders correctly given an error type', function () {
(0, _testUtils.expectComponent)(/*#__PURE__*/_react.default.createElement(_global_message.default, {
type: "error",
message: "An error occurred."
})).toMatchSnapshot();
});
it('renders correctly given an info type', function () {
(0, _testUtils.expectComponent)(/*#__PURE__*/_react.default.createElement(_global_message.default, {
type: "info",
message: "Some additional information."
})).toMatchSnapshot();
});
it('should call scrollIntoView if parameter is set and top < 0', function () {
var wrapper = (0, _enzyme.mount)(/*#__PURE__*/_react.default.createElement(_global_message.default, {
type: "success",
message: "foo",
scrollIntoView: true
}));
var getBoundingClientRectSpy = jest.fn().mockReturnValue({
top: -1
});
var scrollIntoViewSpy = jest.fn();
wrapper.getDOMNode().getBoundingClientRect = getBoundingClientRectSpy;
wrapper.getDOMNode().scrollIntoView = scrollIntoViewSpy;
wrapper.instance().componentDidMount();
expect(getBoundingClientRectSpy).toHaveBeenCalled();
expect(scrollIntoViewSpy).toHaveBeenCalledWith(true);
});
it('should not call scrollIntoView if parameter is set and top >= 0', function () {
var wrapper = (0, _enzyme.mount)(/*#__PURE__*/_react.default.createElement(_global_message.default, {
type: "success",
message: "foo",
scrollIntoView: true
}));
var getBoundingClientRectSpy = jest.fn().mockReturnValue({
top: 0
});
var scrollIntoViewSpy = jest.fn();
wrapper.getDOMNode().getBoundingClientRect = getBoundingClientRectSpy;
wrapper.getDOMNode().scrollIntoView = scrollIntoViewSpy;
wrapper.instance().componentDidMount();
expect(getBoundingClientRectSpy).toHaveBeenCalled();
expect(scrollIntoViewSpy).not.toHaveBeenCalled();
});
it('should call scrollIntoView if parameter is not set (default is true)', function () {
var wrapper = (0, _enzyme.mount)(/*#__PURE__*/_react.default.createElement(_global_message.default, {
type: "success",
message: "foo"
}));
var getBoundingClientRectSpy = jest.fn().mockReturnValue({
top: -1
});
var scrollIntoViewSpy = jest.fn();
wrapper.getDOMNode().getBoundingClientRect = getBoundingClientRectSpy;
wrapper.getDOMNode().scrollIntoView = scrollIntoViewSpy;
wrapper.instance().componentDidMount();
expect(getBoundingClientRectSpy).toHaveBeenCalled();
expect(scrollIntoViewSpy).toHaveBeenCalledWith(true);
});
it('should not call scrollIntoView if parameter is set to false', function () {
var wrapper = (0, _enzyme.mount)(/*#__PURE__*/_react.default.createElement(_global_message.default, {
type: "success",
message: "foo",
scrollIntoView: false
}));
var getBoundingClientRectSpy = jest.fn().mockReturnValue({
top: -1
});
var scrollIntoViewSpy = jest.fn();
wrapper.getDOMNode().getBoundingClientRect = getBoundingClientRectSpy;
wrapper.getDOMNode().scrollIntoView = scrollIntoViewSpy;
wrapper.instance().componentDidMount();
expect(scrollIntoViewSpy).not.toHaveBeenCalled();
});
it('should NOT strip out HTML tags if given a React node', function () {
var message = /*#__PURE__*/_react.default.createElement('span', {
dangerouslySetInnerHTML: {
__html: '<b>Success!</b>'
}
});
var wrapper = (0, _enzyme.mount)(/*#__PURE__*/_react.default.createElement(_global_message.default, {
type: "success",
message: message
}));
expect(wrapper.html()).toBe('<div class="auth0-global-message auth0-global-message-success"><span class="animated fadeInUp">' + '<span><b>Success!</b></span></span></div>');
});
it('should strip out HTML tags if given a string', function () {
var wrapper = (0, _enzyme.mount)(/*#__PURE__*/_react.default.createElement(_global_message.default, {
type: "success",
message: "<b>Success!</b>"
}));
expect(wrapper.html()).toBe('<div class="auth0-global-message auth0-global-message-success"><span class="animated fadeInUp">' + '<b>Success!</b></span></div>');
});
});