From c72a0e0f66c038faca8bb9d3a53b85c8faa2d165 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Sat, 26 Feb 2022 21:36:47 +0800 Subject: [PATCH] test: add test case. --- test/index.test.tsx | 74 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 5 deletions(-) diff --git a/test/index.test.tsx b/test/index.test.tsx index 18e978e0..102cb590 100644 --- a/test/index.test.tsx +++ b/test/index.test.tsx @@ -1,13 +1,77 @@ /** * @jest-environment jsdom */ -import { render, screen } from '@testing-library/react'; +import { render, screen, fireEvent } from '@testing-library/react'; import '@testing-library/jest-dom'; import React from 'react'; -import MonorepoTemplate from '../core/src'; +import Layout from '../core/src'; -test('renders learn react link', () => { - render(learn react); - const linkElement = screen.getByText(/learn react/i); +test('renders react-layout', () => { + const { Header, Footer, Sider, Content } = Layout; + render( + +
Header
+ + Sider + learn @uiw/react-layout + + +
+ ); + const linkElement = screen.getByText(/learn @uiw\/react-layout/i); + expect(linkElement.className).toEqual('w-layout-content') expect(linkElement).toBeInTheDocument(); + + const footerElement = screen.getByText(/Footer/i); + expect(footerElement.className).toEqual('w-layout-footer') + expect(footerElement).toBeInTheDocument(); + + const headerElement = screen.getByText(/Header/i); + expect(headerElement.className).toEqual('w-layout-header') + expect(headerElement).toBeInTheDocument(); + + const siderElement = screen.getByText(/Sider/i); + expect(siderElement.className).toEqual('w-layout-sider') + expect(siderElement).toBeInTheDocument(); +}); + + +test('renders react-layout', () => { + const { Header, Footer, Sider, Content } = Layout; + const Demo = () => { + const [collapsed, setCollapsed] = React.useState(false) + return ( + + Sider Menu + +
+ +
+ Content + +
+
+ ) + } + render(); + const siderElement = screen.getByText(/Sider Menu/i); + expect(siderElement.className).toEqual('w-layout-sider'); + expect(siderElement.style.width).toEqual('200px'); + expect(siderElement.style.minWidth).toEqual('200px'); + expect(siderElement.style.maxWidth).toEqual('200px'); + + fireEvent.click(screen.getByText(/ClickSiderButton/i)); + expect(siderElement.style.width).toEqual('80px'); + expect(siderElement.style.minWidth).toEqual('80px'); + expect(siderElement.style.maxWidth).toEqual('80px'); + expect(siderElement).toBeInTheDocument(); + + const element = screen.getByTestId('layout'); + expect(element.className).toEqual('w-layout w-layout-has-sider'); +}); + +test('renders react-layout hasSider props', () => { + render(); + const element = screen.getByTestId('layout'); + expect(element.className).toEqual('w-layout w-layout-has-sider'); });