@atlaskit/editor-plugin-table 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 0.0.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [`b519be31909`](https://bitbucket.org/atlassian/atlassian-frontend/commits/b519be31909) - Improve FloatingDeleteButton accessibility and update tests
8
+
3
9
  ## 0.0.9
4
10
 
5
11
  ### Patch Changes
@@ -27,7 +27,7 @@ var DeleteButton = function DeleteButton(_ref) {
27
27
  onMouseLeave: onMouseLeave
28
28
  }, /*#__PURE__*/_react.default.createElement("button", {
29
29
  type: "button",
30
- title: formatMessage(removeLabel, {
30
+ "aria-label": formatMessage(removeLabel, {
31
31
  0: 1
32
32
  }),
33
33
  className: _types.TableCssClassName.CONTROLS_DELETE_BUTTON,
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "0.0.9"
3
+ "version": "0.0.10"
4
4
  }
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
- import { injectIntl } from 'react-intl-next'; // import { MessageDescriptor } from '../../../../types/i18n';
3
-
2
+ import { injectIntl } from 'react-intl-next';
4
3
  import { TableCssClassName as ClassName } from '../../types';
5
4
 
6
5
  const DeleteButton = ({
@@ -19,7 +18,7 @@ const DeleteButton = ({
19
18
  onMouseLeave: onMouseLeave
20
19
  }, /*#__PURE__*/React.createElement("button", {
21
20
  type: "button",
22
- title: formatMessage(removeLabel, {
21
+ "aria-label": formatMessage(removeLabel, {
23
22
  0: 1
24
23
  }),
25
24
  className: ClassName.CONTROLS_DELETE_BUTTON,
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "0.0.9"
3
+ "version": "0.0.10"
4
4
  }
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
- import { injectIntl } from 'react-intl-next'; // import { MessageDescriptor } from '../../../../types/i18n';
3
-
2
+ import { injectIntl } from 'react-intl-next';
4
3
  import { TableCssClassName as ClassName } from '../../types';
5
4
 
6
5
  var DeleteButton = function DeleteButton(_ref) {
@@ -17,7 +16,7 @@ var DeleteButton = function DeleteButton(_ref) {
17
16
  onMouseLeave: onMouseLeave
18
17
  }, /*#__PURE__*/React.createElement("button", {
19
18
  type: "button",
20
- title: formatMessage(removeLabel, {
19
+ "aria-label": formatMessage(removeLabel, {
21
20
  0: 1
22
21
  }),
23
22
  className: ClassName.CONTROLS_DELETE_BUTTON,
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "0.0.9"
3
+ "version": "0.0.10"
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ import { render, screen, fireEvent } from '@testing-library/react';
3
+ import { IntlProvider } from 'react-intl-next';
4
+ import DeleteButton from '../../../plugins/table/ui/FloatingDeleteButton/DeleteButton';
5
+ import tableMessages from '../../../plugins/table/ui/messages';
6
+
7
+ describe('<DeleteButton />', () => {
8
+ it('should fire the onMouseEnter callback', () => {
9
+ const onMouseEnter = jest.fn();
10
+ render(
11
+ <IntlProvider locale="en">
12
+ <DeleteButton
13
+ removeLabel={tableMessages.removeColumns}
14
+ onMouseEnter={onMouseEnter}
15
+ />
16
+ </IntlProvider>,
17
+ );
18
+ fireEvent.mouseEnter(screen.getByLabelText('Delete column'));
19
+ expect(onMouseEnter).toHaveBeenCalled();
20
+ });
21
+
22
+ it('should fire the onMouseLeave callback', () => {
23
+ const onMouseLeave = jest.fn();
24
+ render(
25
+ <IntlProvider locale="en">
26
+ <DeleteButton
27
+ removeLabel={tableMessages.removeColumns}
28
+ onMouseLeave={onMouseLeave}
29
+ />
30
+ </IntlProvider>,
31
+ );
32
+ fireEvent.mouseLeave(screen.getByLabelText('Delete column'));
33
+ expect(onMouseLeave).toHaveBeenCalled();
34
+ });
35
+ });
@@ -1,5 +1,4 @@
1
1
  import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
2
- import { mountWithIntl } from '@atlaskit/editor-test-helpers/enzyme';
3
2
  import {
4
3
  doc,
5
4
  table,
@@ -10,10 +9,11 @@ import {
10
9
  DocBuilder,
11
10
  } from '@atlaskit/editor-test-helpers/doc-builder';
12
11
  import { selectColumns, selectRows } from '@atlaskit/editor-test-helpers/table';
13
- import { ReactWrapper } from 'enzyme';
14
12
  import { selectTable } from '@atlaskit/editor-tables/utils';
15
13
  import { EditorView } from 'prosemirror-view';
16
14
  import React from 'react';
15
+ import { render, screen } from '@testing-library/react';
16
+ import { IntlProvider } from 'react-intl-next';
17
17
  import {
18
18
  TablePluginState,
19
19
  TableCssClassName,
@@ -21,8 +21,6 @@ import {
21
21
  import FloatingDeleteButton, {
22
22
  Props as FloatingDeleteButtonProps,
23
23
  } from '../../../plugins/table/ui/FloatingDeleteButton';
24
- import DeleteButton from '../../../plugins/table/ui/FloatingDeleteButton/DeleteButton';
25
- import tableMessages from '../../../plugins/table/ui/messages';
26
24
  import * as tableColumnControlsUtils from '../../../plugins/table/utils/column-controls';
27
25
  import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
28
26
  import tablePlugin from '../../../plugins/table-plugin';
@@ -40,7 +38,6 @@ describe('Floating Delete Button', () => {
40
38
  pluginKey,
41
39
  });
42
40
 
43
- let wrapper: ReactWrapper<FloatingDeleteButtonProps>;
44
41
  let editorView: EditorView;
45
42
 
46
43
  beforeEach(() => {
@@ -53,34 +50,31 @@ describe('Floating Delete Button', () => {
53
50
  ),
54
51
  ),
55
52
  ));
56
-
57
- wrapper = (mountWithIntl(
58
- <FloatingDeleteButton
59
- tableRef={document.querySelector('table')!}
60
- editorView={editorView}
61
- selection={editorView.state.selection}
62
- />,
63
- ) as unknown) as ReactWrapper<FloatingDeleteButtonProps>;
64
53
  });
65
54
 
66
- afterEach(() => {
67
- if (wrapper) {
68
- wrapper.unmount();
69
- }
70
- });
55
+ const component = (props: FloatingDeleteButtonProps) =>
56
+ render(
57
+ <IntlProvider locale="en">
58
+ <FloatingDeleteButton
59
+ tableRef={editorView.dom.querySelector('table')!}
60
+ {...props}
61
+ />
62
+ </IntlProvider>,
63
+ );
71
64
 
72
65
  it('should not render a delete button with no selection', () => {
73
- expect(wrapper.find(DeleteButton).length).toBe(0);
66
+ component({ selection: editorView.state.selection, editorView });
67
+
68
+ expect(screen.queryByLabelText('Popup')).toBeFalsy();
74
69
  });
75
70
 
76
71
  it('should not render a delete button with whole table selected', () => {
77
- // select the whole table
72
+ // selects the whole table
78
73
  editorView.dispatch(selectTable(editorView.state.tr));
79
74
 
80
- // We need to force renderer
81
- wrapper.setProps({ selection: editorView.state.selection });
82
- // set numberOfColumns prop to trick shouldComponentUpdate and force re-render
83
- expect(wrapper.find(DeleteButton).length).toBe(0);
75
+ component({ selection: editorView.state.selection, editorView });
76
+
77
+ expect(screen.queryByLabelText('Popup')).toBeFalsy();
84
78
  });
85
79
 
86
80
  describe('Columns', () => {
@@ -104,21 +98,18 @@ describe('Floating Delete Button', () => {
104
98
  // Select columns start from 0
105
99
  selectColumns([column - 1])(editorView.state, editorView.dispatch);
106
100
 
107
- // We need to force renderer
108
- wrapper.setProps({ selection: editorView.state.selection });
101
+ component({ selection: editorView.state.selection, editorView });
109
102
 
110
- // we should now have a delete button
111
- expect(wrapper.find(DeleteButton).length).toBe(1);
103
+ expect(screen.getAllByLabelText('Delete column').length).toBe(1);
112
104
  },
113
105
  );
114
106
 
115
107
  it('should render a single delete button over multiple column selections', () => {
116
108
  selectColumns([0, 1])(editorView.state, editorView.dispatch);
117
109
 
118
- // We need to force renderer
119
- wrapper.setProps({ selection: editorView.state.selection });
110
+ component({ selection: editorView.state.selection, editorView });
120
111
 
121
- expect(wrapper.find(DeleteButton).length).toBe(1);
112
+ expect(screen.getAllByLabelText('Delete column').length).toBe(1);
122
113
  });
123
114
  });
124
115
 
@@ -128,9 +119,9 @@ describe('Floating Delete Button', () => {
128
119
  (row) => {
129
120
  selectRows([row - 1])(editorView.state, editorView.dispatch);
130
121
 
131
- wrapper.setProps({ selection: editorView.state.selection });
122
+ component({ selection: editorView.state.selection, editorView });
132
123
 
133
- expect(wrapper.find(DeleteButton).length).toBe(1);
124
+ expect(screen.getAllByLabelText('Delete row').length).toBe(1);
134
125
  },
135
126
  );
136
127
 
@@ -138,38 +129,9 @@ describe('Floating Delete Button', () => {
138
129
  selectRows([0, 1])(editorView.state, editorView.dispatch);
139
130
 
140
131
  // selecting the row mutates the editor state (which is inside editorView)
141
- // we set tableHeight prop to trick shouldComponentUpdate and force re-render
142
- wrapper.setProps({ selection: editorView.state.selection });
143
-
144
- expect(wrapper.find(DeleteButton).length).toBe(1);
145
- });
146
- });
147
-
148
- describe('<DeleteButton />', () => {
149
- it('should fire the onMouseEnter callback', () => {
150
- const onMouseEnter = jest.fn();
151
- const button = mountWithIntl(
152
- <DeleteButton
153
- removeLabel={tableMessages.removeColumns}
154
- onMouseEnter={onMouseEnter}
155
- />,
156
- );
157
- button.simulate('mouseenter');
158
- expect(onMouseEnter).toBeCalled();
159
- button.unmount();
160
- });
132
+ component({ selection: editorView.state.selection, editorView });
161
133
 
162
- it('should fire the onMouseLeave callback', () => {
163
- const onMouseLeave = jest.fn();
164
- const button = mountWithIntl(
165
- <DeleteButton
166
- removeLabel={tableMessages.removeRows}
167
- onMouseLeave={onMouseLeave}
168
- />,
169
- );
170
- button.simulate('mouseleave');
171
- expect(onMouseLeave).toBeCalled();
172
- button.unmount();
134
+ expect(screen.getAllByLabelText('Delete row').length).toBe(1);
173
135
  });
174
136
  });
175
137
  });
@@ -2,7 +2,6 @@ import React, { SyntheticEvent } from 'react';
2
2
 
3
3
  import { WrappedComponentProps, injectIntl } from 'react-intl-next';
4
4
 
5
- // import { MessageDescriptor } from '../../../../types/i18n';
6
5
  import { MessageDescriptor } from 'react-intl-next';
7
6
  import { TableCssClassName as ClassName } from '../../types';
8
7
 
@@ -30,7 +29,7 @@ const DeleteButton = ({
30
29
  >
31
30
  <button
32
31
  type="button"
33
- title={formatMessage(removeLabel, { 0: 1 })}
32
+ aria-label={formatMessage(removeLabel, { 0: 1 })}
34
33
  className={ClassName.CONTROLS_DELETE_BUTTON}
35
34
  onMouseDown={onClick}
36
35
  onMouseMove={(e) => e.preventDefault()}