Skip to content

Commit

Permalink
perf: use alertdialog role (#23)
Browse files Browse the repository at this point in the history
* build: upgrade rsuite 5

* chore(deps): upgrdade @testing-library/jest-dom

* perf: use alertdialog role
  • Loading branch information
SevenOutman authored Oct 10, 2021
1 parent 3a8a2ab commit f17fd60
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 38 deletions.
2 changes: 1 addition & 1 deletion docs/styles.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import '~rsuite5/lib/styles/index.less';
@import '~rsuite5/styles/index.less';

.page {
padding: 50px;
Expand Down
176 changes: 156 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@babel/polyfill": "^7.6.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^11.0.4",
"@testing-library/user-event": "^12.1.7",
"@types/webpack": "^4.41.22",
Expand Down Expand Up @@ -98,13 +98,13 @@
"react-hot-loader": "^3.1.3",
"rsuite": "^3.8.13",
"rsuite4": "npm:rsuite@^4.9.3",
"rsuite5": "npm:rsuite@^5.0.0-alpha.5",
"rsuite5": "npm:rsuite@^5.0.1",
"semantic-release": "^17.4.3",
"style-loader": "^0.18.2",
"url-loader": "^2.2.0",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0",
"semantic-release": "^17.4.3"
"webpack-dev-server": "^3.11.0"
},
"browserslist": [
"> 1%",
Expand Down
9 changes: 7 additions & 2 deletions src/InteractionModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,13 @@ function InteractionModal({
};

return (
<Modal size="xs" {...modalProps}>
<Modal.Body>{children}</Modal.Body>
<Modal
role="alertdialog"
size="xs"
aria-describedby="alertdialog-description"
{...modalProps}
>
<Modal.Body id="alertdialog-description">{children}</Modal.Body>
<Modal.Footer>
{showCancelButton && (
<Button
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/InteractionModal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {
import userEvent from '@testing-library/user-event';
import InteractionModal from '../InteractionModal';

it('shows a dialog with message text and buttons', () => {
it('shows an alert dialog with message text and buttons', () => {
const message = 'Hey';
const { getByRole } = render(<InteractionModal>{message}</InteractionModal>);

const dialog = getByRole('dialog');
const dialog = getByRole('alertdialog');
expect(dialog).toBeVisible();
expect(dialog).toHaveTextContent(message);

Expand Down Expand Up @@ -60,14 +60,14 @@ it('hides dialog on clicking ok button', async () => {
const { getByRole } = render(<InteractionModal></InteractionModal>);

userEvent.click(getByRole('button', { name: '确定' }));
await waitForElementToBeRemoved(getByRole('dialog'));
await waitForElementToBeRemoved(getByRole('alertdialog'));
});

it('hides dialog on clicking cancel button', async () => {
const { getByRole } = render(<InteractionModal></InteractionModal>);

userEvent.click(getByRole('button', { name: '取消' }));
await waitForElementToBeRemoved(getByRole('dialog'));
await waitForElementToBeRemoved(getByRole('alertdialog'));
});

it('calls onOk on clicking ok button', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/alert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ it('shows dialog with given message and an ok button', () => {
const message = 'Message';

alert(message);
const dialog = screen.getByRole('dialog');
const dialog = screen.getByRole('alertdialog');
expect(dialog).toBeVisible();
expect(dialog).toHaveTextContent(message);

Expand All @@ -30,7 +30,7 @@ it('closes on clicking ok button', async () => {

userEvent.click(screen.getByRole('button', { name: '确定' }));

await waitForElementToBeRemoved(screen.getByRole('dialog'));
await waitForElementToBeRemoved(screen.getByRole('alertdialog'));
});

it('renders custom ok button text', () => {
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('triggers callbacks', () => {

it('closes after Promise finishes', async () => {
jest.advanceTimersByTime(1000);
await waitForElementToBeRemoved(screen.getByRole('dialog'));
await waitForElementToBeRemoved(screen.getByRole('alertdialog'));
});
});
});
4 changes: 2 additions & 2 deletions src/__tests__/confirm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ it('shows dialog with given message and two buttons', async () => {
const message = 'Message';

confirm(message);
const dialog = screen.getByRole('dialog');
const dialog = screen.getByRole('alertdialog');
expect(dialog).toBeVisible();
expect(dialog).toHaveTextContent(message);

Expand Down Expand Up @@ -221,7 +221,7 @@ describe('triggers callbacks', () => {
act(() => {
jest.advanceTimersByTime(1000);
});
await waitForElementToBeRemoved(screen.getByRole('dialog'));
await waitForElementToBeRemoved(screen.getByRole('alertdialog'));
jest.useRealTimers();
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/prompt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ it('shows dialog with given message and an text input and two buttons', async ()
const message = 'Message';
prompt(message);

const dialog = screen.getByRole('dialog');
const dialog = screen.getByRole('alertdialog');
expect(dialog).toBeVisible();
expect(dialog).toHaveTextContent(message);

Expand Down Expand Up @@ -231,7 +231,7 @@ describe('triggers callbacks', () => {
act(() => {
jest.advanceTimersByTime(1000);
});
await waitForElementToBeRemoved(screen.getByRole('dialog'));
await waitForElementToBeRemoved(screen.getByRole('alertdialog'));
jest.useRealTimers();
});
});
Expand Down
8 changes: 8 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ if (process.env.NODE_ENV === 'production') {
);
}

/**
* @type import('webpack').Configuration
*/
const common = {
entry: path.resolve(__dirname, 'docs/index.js'),
devServer: {
Expand Down Expand Up @@ -83,6 +86,11 @@ const common = {
},
],
},
resolve: {
alias: {
rsuite: path.resolve(__dirname, './node_modules/rsuite5'),
},
},
};

module.exports = () => {
Expand Down

0 comments on commit f17fd60

Please sign in to comment.