From a76d88cf9f6dfce4989d781bcf5efdc05331d3ed Mon Sep 17 00:00:00 2001 From: jamaljsr Date: Fri, 23 Aug 2019 03:20:48 -0400 Subject: [PATCH] feat(network): remove unnecessary elements from AppLayout --- TODO.md | 1 + src/components/layouts/AppLayout.module.less | 18 ------- src/components/layouts/AppLayout.spec.tsx | 22 -------- src/components/layouts/AppLayout.tsx | 56 +++----------------- src/components/network/NetworkList.spec.tsx | 14 ++++- 5 files changed, 21 insertions(+), 90 deletions(-) diff --git a/TODO.md b/TODO.md index 4469214..7edddbf 100644 --- a/TODO.md +++ b/TODO.md @@ -5,3 +5,4 @@ - POC for styled-components (https://www.styled-components.com) (https://emotion.sh) - better UI design (https://material.io/design/color/dark-theme.html) - add network designer (https://github.com/projectstorm/react-diagrams) +- POC testing-library for testcafe (https://testing-library.com/docs/testcafe-testing-library/intro) diff --git a/src/components/layouts/AppLayout.module.less b/src/components/layouts/AppLayout.module.less index 79e5d72..3798687 100644 --- a/src/components/layouts/AppLayout.module.less +++ b/src/components/layouts/AppLayout.module.less @@ -29,19 +29,6 @@ .header { padding: 0; background-color: #fff; - - .trigger { - color: rgba(0, 0, 0, 0.65); - font-size: 18px; - line-height: 64px; - padding: 0 24px; - cursor: pointer; - transition: color 0.3s; - } - - .trigger:hover { - color: @primary-color; - } } .content { @@ -61,8 +48,3 @@ padding: 0 5px; } } - -// Ant overrides -.ant-layout-header { - border-left: 1px solid #000c17; -} diff --git a/src/components/layouts/AppLayout.spec.tsx b/src/components/layouts/AppLayout.spec.tsx index 0155cc4..415d2d8 100644 --- a/src/components/layouts/AppLayout.spec.tsx +++ b/src/components/layouts/AppLayout.spec.tsx @@ -28,22 +28,6 @@ describe('AppLayout component', () => { expect(getByTestId('hello')).toHaveTextContent('Hello World!'); }); - it('should contain a collapse trigger', () => { - const { getByTestId } = renderComponent(); - expect(getByTestId('trigger')).toBeTruthy(); - }); - - it('should be colappsed by default', () => { - const { getByTestId } = renderComponent(); - expect(getByTestId('sider')).toHaveClass('ant-layout-sider-collapsed'); - }); - - it('should expand menu when trigger clicked', () => { - const { getByTestId } = renderComponent(); - fireEvent.click(getByTestId('trigger')); - expect(getByTestId('sider')).not.toHaveClass('ant-layout-sider-collapsed'); - }); - it('should set language to English', () => { const { getByTestId } = renderComponent(); const changeLanguage = changeLanguageMock(); @@ -62,12 +46,6 @@ describe('AppLayout component', () => { changeLanguage.mockClear(); }); - it('should navigate to counter page when Counter link clicked', () => { - const { getByTestId, history } = renderComponent(); - fireEvent.click(getByTestId('nav-counter')); - expect(history.location.pathname).toEqual('/counter'); - }); - it('should navigate to home page when logo clicked', () => { const { getByTestId, history } = renderComponent('/counter'); fireEvent.click(getByTestId('logo')); diff --git a/src/components/layouts/AppLayout.tsx b/src/components/layouts/AppLayout.tsx index 8fe5c6e..aec175a 100644 --- a/src/components/layouts/AppLayout.tsx +++ b/src/components/layouts/AppLayout.tsx @@ -1,78 +1,36 @@ -import React, { useState } from 'react'; -import { Layout, Menu, Icon, Button } from 'antd'; +import React from 'react'; +import { Layout, Button } from 'antd'; import { Link } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; -import { HOME, COUNTER, NETWORK } from 'components/Routes'; +import { HOME } from 'components/Routes'; import logo from 'resources/logo.png'; import NetworkList from '../network/NetworkList'; import styles from './AppLayout.module.less'; const { Header, Content, Footer, Sider } = Layout; -const { SubMenu } = Menu; interface Props { children: React.ReactNode; } const AppLayout: React.FC = (props: Props) => { - const { t, i18n } = useTranslation(); - const [collapsed, setCollapsed] = useState(true); - const toggle = () => setCollapsed(!collapsed); + const { i18n } = useTranslation(); const setEnglish = () => i18n.changeLanguage('en-US'); const setSpanish = () => i18n.changeLanguage('es'); return ( - +
logo - {!collapsed && Polar} + Polar
- - - - - {t('cmps.app-layout.home', 'Home')} - - - - - - {t('cmps.app-layout.counter', 'Counter')} - - - - - {t('cmps.app-layout.menu', 'Menu')} - - } - > - {t('cmps.app-layout.item1', 'Item 1')} - {t('cmps.app-layout.item2', 'Item 2')} - {t('cmps.app-layout.item3', 'Item 3')} - -
-
- - - - -
+
{props.children}
diff --git a/src/components/network/NetworkList.spec.tsx b/src/components/network/NetworkList.spec.tsx index 41162f6..511095b 100644 --- a/src/components/network/NetworkList.spec.tsx +++ b/src/components/network/NetworkList.spec.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { fireEvent } from '@testing-library/react'; +import { fireEvent, wait } from '@testing-library/react'; import { renderWithProviders, getNetwork } from 'utils/tests'; import { NETWORK } from 'components/Routes'; import NetworkList from './NetworkList'; @@ -83,4 +83,16 @@ describe('NetworkList Component', () => { expect(queryByText('cmps.network-list.edit')).toBeTruthy(); expect(queryByText('cmps.network-list.delete')).toBeTruthy(); }); + + it('should toggle a selected network closed when clicked again', () => { + const { queryByText, getByText } = renderComponent(); + expect(queryByText('cmps.network-list.start')).toBeNull(); + fireEvent.click(getByText('my network 1')); + expect(queryByText('cmps.network-list.start')).toBeVisible(); + fireEvent.click(getByText('my network 1')); + wait(() => { + // wait for the menu animation to complete + expect(queryByText('cmps.network-list.start')).not.toBeVisible(); + }); + }); });