wix-style-react
Version:
wix-style-react
134 lines (113 loc) • 4.23 kB
JavaScript
import React from 'react';
import { createDriverFactory } from 'wix-ui-test-utils/driver-factory';
import sideMenuDriverFactory from './SideMenu.driver';
import SideMenu from '../index';
describe('SideMenu', function () {
var createDriver = createDriverFactory(sideMenuDriverFactory);
function createComponent(_ref) {
var header = _ref.header,
navigation = _ref.navigation,
promotion = _ref.promotion,
footer = _ref.footer;
return createDriver(React.createElement(
SideMenu,
null,
header && React.createElement(
SideMenu.Header,
null,
header
),
navigation && React.createElement(
SideMenu.Navigation,
null,
navigation
),
promotion && React.createElement(
SideMenu.Promotion,
null,
promotion
),
footer && React.createElement(
SideMenu.Footer,
null,
footer
)
));
}
it('should render empty menu', function () {
var driver = createComponent({});
expect(driver.exists()).toBe(true);
expect(driver.hasHeader()).toBe(false);
expect(driver.hasNavigation()).toBe(false);
expect(driver.hasPromotion()).toBe(false);
expect(driver.hasFooter()).toBe(false);
});
it('should render full menu', function () {
var menu = {
header: 'Hello Header',
navigation: [React.createElement(SideMenu.NavigationLink, { key: '0', href: '//wix.com' }), React.createElement(SideMenu.NavigationSeparator, { key: '1' }), React.createElement(SideMenu.NavigationLink, { key: '2', href: '//wix.com' })],
promotion: 'Hello Promotion',
footer: 'Hello Footer'
};
var driver = createComponent(menu);
expect(driver.exists()).toBe(true);
expect(driver.hasHeader()).toBe(true);
expect(driver.headerContent()).toBe(menu.header);
expect(driver.hasNavigation()).toBe(true);
expect(driver.navigationLinks()).toHaveLength(2);
expect(driver.navigationSeparators()).toHaveLength(1);
expect(driver.hasPromotion()).toBe(true);
expect(driver.promotionContent()).toBe(menu.promotion);
expect(driver.hasFooter()).toBe(true);
expect(driver.footerContent()).toBe(menu.footer);
});
it('should render a sub menu', function () {
var menu = {
navigation: [React.createElement(
SideMenu.NavigationBackLink,
{ key: '0' },
'Back'
), React.createElement(
SideMenu.NavigationCategory,
{ key: '1' },
'Category 1'
), React.createElement(SideMenu.NavigationLink, { key: '2', href: '//wix.com' })]
};
var driver = createComponent(menu);
expect(driver.hasBackLink()).toBe(true);
expect(driver.navigationCategories()).toHaveLength(1);
expect(driver.navigationLinks()).toHaveLength(1);
});
it('should allow to click on a back menu', function () {
var spy = jest.fn();
var menu = {
navigation: [React.createElement(
SideMenu.NavigationBackLink,
{ key: '0', onBackHandler: spy },
'Back'
)]
};
var driver = createComponent(menu);
driver.clickBackLink();
expect(spy).toHaveBeenCalled();
});
it('should allow to select a menu navigation link', function () {
var spy = jest.fn();
var menu = {
navigation: [React.createElement(SideMenu.NavigationLink, { key: '0' }), React.createElement(SideMenu.NavigationLink, { key: '1', onClick: spy }), React.createElement(SideMenu.NavigationLink, { key: '2' })]
};
var driver = createComponent(menu);
driver.clickLinkByIndex(1);
expect(spy).toHaveBeenCalled();
});
it('should allow to have a badge', function () {
var badge = React.createElement(SideMenu.NavigationBadge, null);
var menu = {
navigation: [React.createElement(SideMenu.NavigationLink, { key: '0' }), React.createElement(SideMenu.NavigationLink, { key: '1', badge: badge }), React.createElement(SideMenu.NavigationLink, { key: '2' })]
};
var driver = createComponent(menu);
expect(driver.isLinkBadgeVisibleByIndex(0)).toBe(false);
expect(driver.isLinkBadgeVisibleByIndex(1)).toBe(true);
expect(driver.isLinkBadgeVisibleByIndex(2)).toBe(false);
});
});