Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/breadcrumbs #35

Merged
merged 6 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
- name: Installing modules
id: install_modules
run: |
yarn cache clean
rm -rf node_modules
yarn install
- name: Build test
id: build_test
Expand Down
83 changes: 83 additions & 0 deletions __tests__/breadcrumbs.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { act, fireEvent, render } from '@testing-library/react';
import React from 'react';
import {
ReqoreBreadcrumbs,
ReqoreLayoutContent,
ReqoreUIProvider,
} from '../src';

test('Renders full <Breadcrumbs /> properly', () => {
render(
<div style={{ width: '1000px' }}>
<ReqoreUIProvider>
<ReqoreLayoutContent>
<ReqoreBreadcrumbs
items={[
{ label: 'Page 1', icon: 'home' },
{ label: 'Page 2', icon: 'home' },
{ label: 'Page 3', icon: 'home' },
{ label: 'Page 4', icon: 'home' },
{ label: 'Page 5', icon: 'home' },
]}
/>
</ReqoreLayoutContent>
</ReqoreUIProvider>
</div>
);

expect(document.querySelectorAll('.reqore-breadcrumbs-wrapper').length).toBe(
1
);
expect(document.querySelectorAll('.reqore-breadcrumbs-item').length).toBe(5);
});

test('Renders shortened <Breadcrumbs /> properly', () => {
act(() => {
render(
<ReqoreUIProvider>
<ReqoreLayoutContent>
<ReqoreBreadcrumbs
_testWidth={300}
items={[
{ label: 'Page 1', icon: 'home' },
{ label: 'Page 2', icon: 'home' },
{ label: 'Page 3', icon: 'home' },
{ label: 'Page 4', icon: 'home' },
{ label: 'Page 5', icon: 'home' },
]}
/>
</ReqoreLayoutContent>
</ReqoreUIProvider>
);
});

expect(document.querySelectorAll('.reqore-breadcrumbs-wrapper').length).toBe(
1
);
expect(document.querySelectorAll('.reqore-breadcrumbs-item').length).toBe(3);
});

test('Shows hidden <Breadcrumbs /> items on click', () => {
act(() => {
render(
<ReqoreUIProvider>
<ReqoreLayoutContent>
<ReqoreBreadcrumbs
_testWidth={300}
items={[
{ label: 'Page 1', icon: 'home' },
{ label: 'Page 2', icon: 'home' },
{ label: 'Page 3', icon: 'home' },
{ label: 'Page 4', icon: 'home' },
{ label: 'Page 5', icon: 'home' },
]}
/>
</ReqoreLayoutContent>
</ReqoreUIProvider>
);

fireEvent.click(document.querySelectorAll('.reqore-breadcrumbs-item')[1]);
});

expect(document.querySelectorAll('.reqore-breadcrumbs-item').length).toBe(3);
});
57 changes: 48 additions & 9 deletions __tests__/sidebar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { fireEvent, render, screen } from '@testing-library/react';
import React from 'react';
import { ReqoreUIProvider } from '../src';
import QorusSidebar from '../src/components/Sidebar';
import ReqoreSidebar from '../src/components/Sidebar';
import { qorusSidebarItems } from '../src/mock/menu';

test('Renders sidebar', () => {
render(
<ReqoreUIProvider>
<QorusSidebar items={qorusSidebarItems} path='/' />
<ReqoreSidebar items={qorusSidebarItems} path='/' />
</ReqoreUIProvider>
);

Expand All @@ -20,7 +20,7 @@ test('Sidebar can be collapsed', () => {

render(
<ReqoreUIProvider>
<QorusSidebar
<ReqoreSidebar
items={qorusSidebarItems}
path='/'
onCollapseChange={handleClick}
Expand All @@ -40,7 +40,7 @@ test('Sidebar can be collapsed', () => {
test('Can open submenu manually', () => {
render(
<ReqoreUIProvider>
<QorusSidebar items={qorusSidebarItems} path='/' />
<ReqoreSidebar items={qorusSidebarItems} path='/' />
</ReqoreUIProvider>
);

Expand All @@ -53,7 +53,7 @@ test('Can open submenu manually', () => {
test('Submenu opens automatically if path matches', () => {
render(
<ReqoreUIProvider>
<QorusSidebar items={qorusSidebarItems} path='/item-3/item-1' />
<ReqoreSidebar items={qorusSidebarItems} path='/item-3/item-1' />
</ReqoreUIProvider>
);

Expand All @@ -67,7 +67,7 @@ test('Bookmarks can be added and removed', () => {

render(
<ReqoreUIProvider>
<QorusSidebar
<ReqoreSidebar
items={qorusSidebarItems}
path='/'
onBookmarksChange={handleBookmarksChange}
Expand All @@ -93,12 +93,49 @@ test('Bookmarks can be added and removed', () => {
expect(document.querySelectorAll('.sidebarSection').length).toBe(3);
});

test('Bookmarks clicks are not propagated through', () => {
const handleBookmarksChange = jest.fn();
const handleClick = jest.fn();

render(
<ReqoreUIProvider>
<ReqoreSidebar
items={{
Menu: {
title: 'Menu',
items: [
{
name: 'Menu item 1',
as: 'p',
icon: 'home',
id: 'menu-item-1',
props: {
onClick: handleClick,
},
},
],
},
}}
path='/'
onBookmarksChange={handleBookmarksChange}
/>
</ReqoreUIProvider>
);

const addBookmarkButton = document.querySelector('.favorite');

fireEvent.click(addBookmarkButton);

expect(handleBookmarksChange).toHaveBeenCalledWith(['menu-item-1']);
expect(handleClick).toHaveBeenCalledTimes(0);
});

test('Renders item as <p> element with onClick', () => {
const handleItemClick = jest.fn();

render(
<ReqoreUIProvider>
<QorusSidebar
<ReqoreSidebar
items={{
...qorusSidebarItems,
TestItems: {
Expand All @@ -107,7 +144,9 @@ test('Renders item as <p> element with onClick', () => {
{
name: 'Test',
as: 'p',
onClick: handleItemClick,
props: {
onClick: handleItemClick,
},
id: 'test-item-1',
icon: 'add',
},
Expand All @@ -134,7 +173,7 @@ test('Renders item as <p> element with onClick', () => {
test('Renders custom item at the top', () => {
render(
<ReqoreUIProvider>
<QorusSidebar
<ReqoreSidebar
items={qorusSidebarItems}
path='/'
customItems={[
Expand Down
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module.exports = {
// `<rootDir>` is a token Jest substitutes
roots: ['<rootDir>/__tests__'],

testMatch: ['<rootDir>/__tests__/**/*.test.(ts|tsx)'],

// Jest transformations -- this adds support for TypeScript
// using ts-jest
transform: {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@qoretechnologies/reqore",
"version": "0.2.5",
"version": "0.2.6",
"description": "ReQore is a UI library of components for Qorus connected apps",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -54,6 +54,7 @@
"react-test-renderer": "^17.0.1",
"styled-components": "^5.2.1",
"ts-jest": "^26.4.4",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
},
"peerDependencies": {
Expand Down
Loading