Skip to content

Commit 69ae736

Browse files
author
Hidetaka Okamoto
committedJul 7, 2021
feat: layout update to support admin area
1 parent 60d4e32 commit 69ae736

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed
 

‎jest-setup.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('@testing-library/jest-dom')

‎jest.config.js

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
const {createJestConfig} = require('tsdx/dist/createJestConfig');
22
const {paths} = require('tsdx/dist/constants');
33

4+
/**
5+
* To support svg import
6+
* @see https://www.npmjs.com/package/jest-svg-transformer
7+
*/
48
const config = createJestConfig(undefined, paths.appRoot)
59
config.transform["^.+\\.svg$"] = "jest-svg-transformer"
10+
11+
/**
12+
* For @testing-library/react
13+
*
14+
* @see https://github.com/testing-library/jest-dom#usage
15+
**/
16+
if (config.setupFilesAfterEnv) {
17+
config.setupFilesAfterEnv.push('<rootDir>/jest-setup.js')
18+
} else {
19+
config.setupFilesAfterEnv = ['<rootDir>/jest-setup.js']
20+
}
621
module.exports = config;
+11-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import { render } from '@testing-library/react';
22
import React from 'react';
3-
import { Default as Layouts } from './Layouts.stories';
3+
import { Layouts } from './Layouts';
4+
import { Default as LayoutsStory } from './Layouts.stories';
45

56
describe('Layouts', () => {
67
it('to match snapshot', () => {
7-
const { asFragment } = render(<Layouts {...(Layouts.args as any)} />);
8+
const { asFragment } = render(<LayoutsStory {...(LayoutsStory.args as any)} />);
89
expect(asFragment()).toMatchSnapshot();
910
});
11+
it.each([
12+
[undefined, 'shifter-dashboard'],
13+
['login' as const, 'shifter-dashboard-login'],
14+
['signup' as const, 'shifter-dashboard-signup'],
15+
])('variant is %p, should add the %p class name', (variant, expectedClassName) => {
16+
const {container} = render(<Layouts variant={variant}>Dummy content</Layouts>)
17+
expect(container.firstChild).toHaveClass(expectedClassName)
18+
})
1019
});

‎src/components/Layouts/Layouts.stories.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ const meta: Meta = {
88
parameters: {
99
controls: { expanded: true },
1010
},
11+
argTypes: {
12+
variant: {
13+
options: ['default', 'login', 'signup'],
14+
control: {type: 'radio'}
15+
}
16+
}
1117
};
1218

1319
export default meta;

‎src/components/Layouts/Layouts.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { FC, PropsWithChildren, ReactNode } from 'react';
22

33
export type LayoutsProps = PropsWithChildren<{
4-
variant: 'login' | 'signup';
4+
variant?: 'login' | 'signup';
55
footer?: ReactNode;
66
}>;
77
export const Layouts: FC<LayoutsProps> = ({ children, variant, footer }) => {
@@ -14,6 +14,7 @@ export const Layouts: FC<LayoutsProps> = ({ children, variant, footer }) => {
1414
classNames.push('shifter-dashboard-login');
1515
break;
1616
default:
17+
classNames.push('shifter-dashboard')
1718
break;
1819
}
1920
const className = classNames.join(' ');

0 commit comments

Comments
 (0)