Skip to content

Commit 0cf7e1e

Browse files
committed
Add stories to test detail views themes.
1 parent 88749f5 commit 0cf7e1e

File tree

6 files changed

+112
-3
lines changed

6 files changed

+112
-3
lines changed

packages/ra-ui-materialui/src/detail/Create.spec.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
TitleElement,
1212
NotificationDefault,
1313
NotificationTranslated,
14+
Themed,
1415
} from './Create.stories';
1516

1617
describe('<Create />', () => {
@@ -49,6 +50,13 @@ describe('<Create />', () => {
4950
expect(screen.queryAllByText('help')).toHaveLength(1);
5051
});
5152

53+
it('should be customized by a theme', async () => {
54+
render(<Themed />);
55+
expect(screen.queryByTestId('themed-view').classList).toContain(
56+
'custom-class'
57+
);
58+
});
59+
5260
describe('title', () => {
5361
it('should display by default the title of the resource', async () => {
5462
render(<Basic />);

packages/ra-ui-materialui/src/detail/Create.stories.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import {
99
} from 'ra-core';
1010
import polyglotI18nProvider from 'ra-i18n-polyglot';
1111
import englishMessages from 'ra-language-english';
12-
import { Box, Card, Stack } from '@mui/material';
12+
import { Box, Card, Stack, ThemeOptions } from '@mui/material';
1313

1414
import { TextInput } from '../input';
1515
import { SimpleForm } from '../form/SimpleForm';
1616
import { ListButton, SaveButton } from '../button';
1717
import TopToolbar from '../layout/TopToolbar';
1818
import { Create } from './Create';
19+
import { deepmerge } from '@mui/utils';
20+
import { defaultLightTheme } from '../theme';
1921

2022
export default { title: 'ra-ui-materialui/detail/Create' };
2123

@@ -270,3 +272,29 @@ export const Default = () => (
270272
</Admin>
271273
</TestMemoryRouter>
272274
);
275+
276+
export const Themed = () => (
277+
<TestMemoryRouter initialEntries={['/books/create']}>
278+
<Admin
279+
dataProvider={dataProvider}
280+
theme={deepmerge(defaultLightTheme, {
281+
components: {
282+
RaCreate: {
283+
defaultProps: {
284+
className: 'custom-class',
285+
},
286+
},
287+
},
288+
} as ThemeOptions)}
289+
>
290+
<Resource
291+
name="books"
292+
create={() => (
293+
<Create data-testid={'themed-view'}>
294+
<Content />
295+
</Create>
296+
)}
297+
/>
298+
</Admin>
299+
</TestMemoryRouter>
300+
);

packages/ra-ui-materialui/src/detail/Edit.spec.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
NotificationDefault,
2929
NotificationTranslated,
3030
EmptyWhileLoading,
31+
Themed,
3132
} from './Edit.stories';
3233

3334
describe('<Edit />', () => {
@@ -140,6 +141,13 @@ describe('<Edit />', () => {
140141
expect(screen.queryByText('Something went wrong')).toBeNull();
141142
});
142143

144+
it('should be customized by a theme', async () => {
145+
render(<Themed />);
146+
expect(screen.queryByTestId('themed-view').classList).toContain(
147+
'custom-class'
148+
);
149+
});
150+
143151
describe('mutationMode prop', () => {
144152
it('should be undoable by default', async () => {
145153
let post = { id: 1234, title: 'lorem' };

packages/ra-ui-materialui/src/detail/Edit.stories.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import {
99
} from 'ra-core';
1010
import polyglotI18nProvider from 'ra-i18n-polyglot';
1111
import englishMessages from 'ra-language-english';
12-
import { Box, Card, Stack, Typography } from '@mui/material';
12+
import { Box, Card, Stack, ThemeOptions, Typography } from '@mui/material';
1313

1414
import { TextInput } from '../input';
1515
import { SimpleForm } from '../form/SimpleForm';
1616
import { ShowButton, SaveButton } from '../button';
1717
import TopToolbar from '../layout/TopToolbar';
1818
import { Edit } from './Edit';
19+
import { deepmerge } from '@mui/utils';
20+
import { defaultLightTheme } from '../theme';
1921

2022
export default { title: 'ra-ui-materialui/detail/Edit' };
2123

@@ -362,3 +364,29 @@ const AsideComponentWithRecord = () => {
362364
</Typography>
363365
);
364366
};
367+
368+
export const Themed = () => (
369+
<TestMemoryRouter initialEntries={['/books/1/Edit']}>
370+
<Admin
371+
dataProvider={dataProvider}
372+
theme={deepmerge(defaultLightTheme, {
373+
components: {
374+
RaEdit: {
375+
defaultProps: {
376+
className: 'custom-class',
377+
},
378+
},
379+
},
380+
} as ThemeOptions)}
381+
>
382+
<Resource
383+
name="books"
384+
edit={() => (
385+
<Edit data-testid={'themed-view'}>
386+
<BookTitle />
387+
</Edit>
388+
)}
389+
/>
390+
</Admin>
391+
</TestMemoryRouter>
392+
);

packages/ra-ui-materialui/src/detail/Show.spec.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
Title,
2525
TitleFalse,
2626
TitleElement,
27+
Themed,
2728
} from './Show.stories';
2829
import { Show } from './Show';
2930

@@ -129,6 +130,13 @@ describe('<Show />', () => {
129130
expect(screen.getByTestId('custom-component')).toBeDefined();
130131
});
131132

133+
it('should be customized by a theme', async () => {
134+
render(<Themed />);
135+
expect(screen.queryByTestId('themed-view').classList).toContain(
136+
'custom-class'
137+
);
138+
});
139+
132140
describe('title', () => {
133141
it('should display by default the title of the resource', async () => {
134142
render(<Basic />);

packages/ra-ui-materialui/src/detail/Show.stories.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import * as React from 'react';
22
import { Admin } from 'react-admin';
33
import { Resource, useRecordContext, TestMemoryRouter } from 'ra-core';
4-
import { Box, Card, Stack } from '@mui/material';
4+
import { Box, Card, Stack, ThemeOptions } from '@mui/material';
5+
56
import { TextField } from '../field';
67
import { Labeled } from '../Labeled';
78
import { SimpleShowLayout } from './SimpleShowLayout';
89
import { EditButton } from '../button';
910
import TopToolbar from '../layout/TopToolbar';
1011
import { Show } from './Show';
12+
import { deepmerge } from '@mui/utils';
13+
import { defaultLightTheme } from '../theme';
1114

1215
export default { title: 'ra-ui-materialui/detail/Show' };
1316

@@ -244,3 +247,29 @@ export const Default = () => (
244247
</Admin>
245248
</TestMemoryRouter>
246249
);
250+
251+
export const Themed = () => (
252+
<TestMemoryRouter initialEntries={['/books/1/show']}>
253+
<Admin
254+
dataProvider={dataProvider}
255+
theme={deepmerge(defaultLightTheme, {
256+
components: {
257+
RaShow: {
258+
defaultProps: {
259+
className: 'custom-class',
260+
},
261+
},
262+
},
263+
} as ThemeOptions)}
264+
>
265+
<Resource
266+
name="books"
267+
show={() => (
268+
<Show data-testid={'themed-view'}>
269+
<BookTitle />
270+
</Show>
271+
)}
272+
/>
273+
</Admin>
274+
</TestMemoryRouter>
275+
);

0 commit comments

Comments
 (0)