Skip to content

Commit fc4abb7

Browse files
authored
Merge branch 'develop' into dewanshmobile/FAB
2 parents 11f696d + f398e76 commit fc4abb7

File tree

6 files changed

+105
-7
lines changed

6 files changed

+105
-7
lines changed

.storybook/preview-head.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
// https://github.com/pmmmwh/react-refresh-webpack-plugin/issues/176#issuecomment-683150213
3+
window.$RefreshReg$ = () => {};
4+
window.$RefreshSig$ = () => () => {};
5+
</script>

client/common/ButtonOrLink.test.jsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { render, screen, fireEvent } from '../test-utils';
2+
import { render, screen, fireEvent, waitFor, history } from '../test-utils';
33
import ButtonOrLink from './ButtonOrLink';
44

55
describe('ButtonOrLink', () => {
@@ -25,8 +25,12 @@ describe('ButtonOrLink', () => {
2525
expect(link).toHaveAttribute('href', 'https://p5js.org');
2626
});
2727

28-
it('can render an internal link with react-router', () => {
28+
it('can render an internal link with react-router', async () => {
2929
render(<ButtonOrLink href="/about">About</ButtonOrLink>);
30-
// TODO: how can this be tested? Needs a router provider?
30+
31+
const link = screen.getByText('About');
32+
fireEvent.click(link);
33+
34+
await waitFor(() => expect(history.location.pathname).toEqual('/about'));
3135
});
3236
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import Modal from './Modal';
3+
4+
export default {
5+
title: 'IDE/Modal',
6+
component: Modal,
7+
argTypes: {
8+
onClose: { action: 'onClose' }
9+
}
10+
};
11+
12+
export const ModalDefault = {
13+
args: {
14+
title: 'Example Modal Title',
15+
children: <p>Example modal body</p>
16+
}
17+
};
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React from 'react';
2+
import { fireEvent, render, screen } from '../../../test-utils';
3+
import Modal from './Modal';
4+
5+
describe('Modal', () => {
6+
it('can render title', () => {
7+
render(
8+
<Modal title="Foo" closeAriaLabel="Foo" onClose={jest.fn()}>
9+
Bar
10+
</Modal>
11+
);
12+
13+
expect(screen.getByRole('heading', { name: 'Foo' })).toBeVisible();
14+
});
15+
16+
it('can render child content', () => {
17+
render(
18+
<Modal title="Foo" closeAriaLabel="Foo" onClose={jest.fn()}>
19+
Bar
20+
</Modal>
21+
);
22+
23+
expect(screen.getByText('Bar')).toBeVisible();
24+
});
25+
26+
it('can call onClose when close button clicked', () => {
27+
const handleClose = jest.fn();
28+
render(
29+
<Modal title="Foo" closeAriaLabel="Foo" onClose={handleClose}>
30+
Bar
31+
</Modal>
32+
);
33+
34+
const buttonEl = screen.getByRole('button');
35+
fireEvent.click(buttonEl);
36+
37+
expect(handleClose).toHaveBeenCalledTimes(1);
38+
});
39+
40+
it('can call onClose when click event occurs in a parent node', () => {
41+
const handleClose = jest.fn();
42+
render(
43+
<div>
44+
<h1>Parent</h1>
45+
<Modal title="Foo" closeAriaLabel="Foo" onClose={handleClose}>
46+
Bar
47+
</Modal>
48+
</div>
49+
);
50+
51+
const headingEl = screen.getByRole('heading', { name: 'Parent' });
52+
fireEvent.click(headingEl);
53+
54+
expect(handleClose).toHaveBeenCalledTimes(1);
55+
});
56+
57+
it('can ignore click event for closing when it occurs inside component', () => {
58+
const handleClose = jest.fn();
59+
render(
60+
<Modal title="Foo" closeAriaLabel="Foo" onClose={handleClose}>
61+
Bar
62+
</Modal>
63+
);
64+
65+
const headingEl = screen.getByRole('heading', { name: 'Foo' });
66+
fireEvent.click(headingEl);
67+
68+
expect(handleClose).not.toHaveBeenCalled();
69+
});
70+
});

client/test-utils.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ import React from 'react';
1616
import PropTypes from 'prop-types';
1717
import { Provider } from 'react-redux';
1818
import { Router } from 'react-router-dom';
19+
import { createMemoryHistory } from 'history';
1920
import { I18nextProvider } from 'react-i18next';
2021
import { ThemeProvider as StyledThemeProvider } from 'styled-components';
2122

22-
import browserHistory from './browserHistory';
2323
import i18n from './i18n-test';
2424
import ThemeProvider from './modules/App/components/ThemeProvider';
2525
import configureStore from './store';
2626
import theme, { Theme } from './theme';
2727

28+
export const history = createMemoryHistory();
29+
2830
// re-export everything
2931
// eslint-disable-next-line import/no-extraneous-dependencies
3032
export * from '@testing-library/react';
@@ -33,7 +35,7 @@ const Providers = ({ children }) => (
3335
// eslint-disable-next-line react/jsx-filename-extension
3436
<StyledThemeProvider theme={{ ...theme[Theme.light] }}>
3537
<I18nextProvider i18n={i18n}>
36-
<Router history={browserHistory}>{children}</Router>
38+
<Router history={history}>{children}</Router>
3739
</I18nextProvider>
3840
</StyledThemeProvider>
3941
);
@@ -51,7 +53,7 @@ function reduxRender(
5153
<I18nextProvider i18n={i18n}>
5254
<Provider store={store}>
5355
<ThemeProvider>
54-
<Router history={browserHistory}>{children}</Router>
56+
<Router history={history}>{children}</Router>
5557
</ThemeProvider>
5658
</Provider>
5759
</I18nextProvider>

server/views/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function renderIndex() {
1212
${process.env.NODE_ENV === 'production' ? `<link rel='stylesheet' href='${assetsManifest['/app.css']}' />` : ''}
1313
<link href='https://fonts.googleapis.com/css?family=Inconsolata' rel='stylesheet' type='text/css'>
1414
<link href='https://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
15-
<link rel='shortcut icon' href='favicon.ico' type='image/x-icon' / >
15+
<link rel='shortcut icon' href='/favicon.ico' type='image/x-icon' / >
1616
<script>
1717
if (!window.process) {
1818
window.process = {};

0 commit comments

Comments
 (0)