Skip to content

Commit 6643cd2

Browse files
committed
Setup Jest test providers
Setup AppSidebar test
1 parent 4776a3b commit 6643cd2

16 files changed

+80
-169
lines changed

src/App.test.tsxl

-9
This file was deleted.

src/App.test.tsxr

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react'
2+
import { render } from '_tests'
3+
import App from './App'
4+
5+
test('renders without crashing', () => {
6+
render(<App />)
7+
})

src/Dashboard/Dashboard.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import BasePageContainer from '../_common/BasePageContainer'
66
import BasePageToolbar from '../_common/BasePageToolbar'
77

88
import DashboardActions from './DashboardActions'
9-
import SubscriptionsHistory from './SubscriptionsHistory'
10-
import KeyMetrics from './KeyMetrics'
11-
import SubscriptionsRecent from './SubscriptionsRecent'
12-
import SubscriptionsBreakdown from './SubscriptionsBreakdown'
9+
import SubscriptionsHistory from './SubscriptionsHistory/'
10+
import KeyMetrics from './KeyMetrics/'
11+
import SubscriptionsRecent from './SubscriptionsRecent/'
12+
import SubscriptionsBreakdown from './SubscriptionsBreakdown/'
1313

1414
const Dashboard = () => {
1515
return (

src/Dashboard/KeyMetrics/KeyMetrics.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { render, screen } from '@testing-library/react'
2+
import { render, screen } from '_tests/'
33
import KeyMetrics from './KeyMetrics'
44

55
test('renders without crashing', () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react'
2+
import { render, screen } from '_tests'
3+
import AppSidebar from './AppSidebar'
4+
5+
test('renders learn react link', () => {
6+
render(<AppSidebar />)
7+
expect(screen.getByLabelText('Modular Admin link')).toBeInTheDocument()
8+
})

src/_common/AppSidebar/AppSidebar.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { Link } from 'react-router-dom'
55
import Typography from '@material-ui/core/Typography'
66

77
// import AppSidebarBg from './AppSidebarBg.jpg'
8-
import Logo from '_common/BaseLogo/BaseLogo'
8+
import { ITheme } from '_theme/'
9+
import BaseLogo from '_common/BaseLogo'
910
import SidebarNav from './SidebarNav'
1011

1112
export interface ISidebarProps {
@@ -22,8 +23,13 @@ const Sidebar: React.FC<ISidebarProps> = (props) => {
2223
<div className={classes.sidebarBackground} />
2324
<div className={classes.sidebarBody}>
2425
<div className={classes.sidebarHeader}>
25-
<Link to="/" className={classes.sidebarTitleLink}>
26-
<Logo size={30} isInversed={true} className={classes.logo} />
26+
<Link
27+
to="/"
28+
className={classes.sidebarTitleLink}
29+
role="link"
30+
aria-label="Modular Admin link"
31+
>
32+
<BaseLogo size={30} isInversed={true} className={classes.logo} role="img" />
2733
<Typography
2834
component="h2"
2935
variant="h5"
@@ -50,7 +56,7 @@ Sidebar.defaultProps = {
5056
// isCollapsed: PropTypes.bool,
5157
// }
5258

53-
const useStyles = makeStyles((theme) => ({
59+
const useStyles = makeStyles<ITheme>((theme) => ({
5460
sidebar: {
5561
position: 'absolute',
5662
top: 0,

src/_common/AppSidebar/SidebarNav/SidebarNav.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { makeStyles, createStyles } from '@material-ui/core/styles'
33
import List from '@material-ui/core/List'
44
import ListSubheader from '@material-ui/core/ListSubheader'
55

6-
import { itemsCore, itemsTheme } from './SidebarNavService'
6+
import { ITheme } from '_theme'
7+
import { itemsCore /*, itemsTheme */ } from './SidebarNavService'
78
import SidebarNavListItem, { ISidebarNavListItem } from './SidebarNavListItem'
89

910
export interface ISidebarNavProps {
@@ -35,7 +36,7 @@ const SidebarNav: React.FC<ISidebarNavProps> = (props) => {
3536
)
3637
}
3738

38-
const useStyles = makeStyles((theme) =>
39+
const useStyles = makeStyles<ITheme>((theme) =>
3940
createStyles({
4041
navList: {
4142
width: theme.sidebar.width,

src/_common/AppSidebar/SidebarNav/SidebarNavListItem.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import List from '@material-ui/core/List'
44
import ListItem from '@material-ui/core/ListItem'
55
import Collapse from '@material-ui/core/Collapse'
66

7-
import { makeStyles, createStyles } from '@material-ui/core/styles'
7+
// import { makeStyles, createStyles } from '@material-ui/core/styles'
88

99
export interface ISidebarNavListItem {
1010
name: string

src/_common/BasePageContainer/BasePageContainer.js renamed to src/_common/BasePageContainer/BasePageContainer.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ import React from 'react'
22

33
import { makeStyles } from '@material-ui/core/styles'
44

5-
const PageContainer = ({ children }) => {
5+
const BasePageContainer: React.FC = ({ children }) => {
66
const classes = useStyles()
77

8-
return <article className={classes.container}>{children}</article>
8+
return (
9+
<main className={classes.container} role="main">
10+
{children}
11+
</main>
12+
)
913
}
1014

1115
const useStyles = makeStyles((theme) => ({
@@ -18,4 +22,4 @@ const useStyles = makeStyles((theme) => ({
1822
},
1923
}))
2024

21-
export default PageContainer
25+
export default BasePageContainer

src/_tests/index.tsx

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// jest-dom adds custom jest matchers for asserting on DOM nodes.
2+
// allows you to do things like:
3+
// expect(element).toHaveTextContent(/react/i)
4+
// learn more: https://github.com/testing-library/jest-dom
5+
import 'jest-canvas-mock'
6+
import '@testing-library/jest-dom'
7+
8+
import React, { ReactElement } from 'react'
9+
import { render, RenderOptions } from '@testing-library/react'
10+
import { MemoryRouter } from 'react-router-dom'
11+
import { ThemeProvider } from '@material-ui/styles'
12+
import { IntlProvider } from 'react-intl'
13+
14+
import theme from '../_theme'
15+
16+
const AllTheProviders: React.FC = ({ children }) => {
17+
return (
18+
<IntlProvider locale={'en-US'}>
19+
<ThemeProvider theme={theme}>
20+
<MemoryRouter>{children}</MemoryRouter>
21+
</ThemeProvider>
22+
</IntlProvider>
23+
)
24+
}
25+
26+
const customRender = (ui: ReactElement, options?: Omit<RenderOptions, 'queries'>) =>
27+
render(ui, { wrapper: AllTheProviders, ...options })
28+
29+
jest.mock('react-chartjs-2', () => ({
30+
Bar: () => null,
31+
Line: () => null,
32+
}))
33+
34+
export * from '@testing-library/react'
35+
36+
export { customRender as render }

src/_theme/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ declare module '@material-ui/core/styles/createMuiTheme' {
1818
interface ThemeOptions {}
1919
}
2020

21+
export interface ITheme extends Theme {}
22+
2123
const baseTheme = createMuiTheme({
2224
props: {
2325
MuiPaper: {

src/serviceWorker.js

-133
This file was deleted.

src/setupTests.ts

-11
This file was deleted.

tsconfig.custom.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"paths": {
4-
"@/*": ["./*"],
4+
"@/*": ["./src/*"],
55
"$/*": [
66
"./src/*"
77
],

0 commit comments

Comments
 (0)