UNPKG

optimizely-oui

Version:

Optimizely's Component Library.

89 lines (84 loc) 3.41 kB
"use strict"; var _react = _interopRequireDefault(require("react")); var _navigation = require("../navigation"); var _enzyme = require("enzyme"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } describe("components/Navigation", function () { var component; it("should render correctly", function () { component = (0, _enzyme.shallow)(_react["default"].createElement(_navigation.Navigation, { title: "Test navigation" })); expect(component).toMatchSnapshot(); }); describe("when a logo url is passed", function () { var homeUrl = "/test-url"; beforeEach(function () { component = (0, _enzyme.mount)(_react["default"].createElement(_navigation.Navigation, { homeUrl: homeUrl, logoUrl: "/", title: "Test navigation" })); }); it("should render the logo with the home url provided", function () { var navigationLogo = component.find('[data-test-section="navigation--brand-logo"]'); expect(navigationLogo.exists()).toBeTruthy(); expect(navigationLogo.props()).toHaveProperty("href", homeUrl); }); }); describe("when a logo url is not passed", function () { var homeUrl = "/test-url"; beforeEach(function () { component = (0, _enzyme.mount)(_react["default"].createElement(_navigation.Navigation, { homeUrl: homeUrl, title: "Test navigation" })); }); it("shouldn't render the brand logo", function () { var navigationLogo = component.find('[data-test-section="navigation--brand-logo"]'); expect(navigationLogo.exists()).toBeFalsy(); }); }); describe("when a help url is passed", function () { var helpUrl = "/test-url"; beforeEach(function () { component = (0, _enzyme.mount)(_react["default"].createElement(_navigation.Navigation, { helpUrl: helpUrl, title: "Test navigation" })); }); it("should render the help icon with the help url provided", function () { var navigationHelpIcon = component.find('[data-test-section="navigation--help-icon"]'); expect(navigationHelpIcon.exists()).toBeTruthy(); expect(navigationHelpIcon.props()).toHaveProperty("href", helpUrl); var icon = navigationHelpIcon.find('Memo(Icon)'); expect(icon.exists()).toBeTruthy(); expect(icon.props()).toHaveProperty("name", "help"); expect(icon.props()).toHaveProperty("size", "large"); }); describe("when the help icon is clicked", function () { var onHelpClick = jest.fn(); beforeEach(function () { component.setProps({ onHelpClick: onHelpClick }); var navigationHelpIcon = component.find('[data-test-section="navigation--help-icon"]'); navigationHelpIcon.simulate("click"); }); it("should call the onHelpClick CB", function () { expect(onHelpClick).toHaveBeenCalledTimes(1); }); }); }); describe("when a help url is not passed", function () { beforeEach(function () { component = (0, _enzyme.mount)(_react["default"].createElement(_navigation.Navigation, { title: "Test navigation" })); }); it("shouldn't render the help icon", function () { var navigationHelpIcon = component.find('[data-test-section="navigation--help-icon"]'); expect(navigationHelpIcon.exists()).toBeFalsy(); }); }); });