@salesforce/design-system-react 0.10.50-alpha.1 → 0.10.50-alpha.2

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.
Files changed (69) hide show
  1. package/components/accordion/__tests__/accordion.browser-test.jsx +302 -0
  2. package/components/alert/__tests__/alert.browser-test.jsx +100 -0
  3. package/components/app-launcher/__tests__/app-launcher.browser-test.jsx +228 -0
  4. package/components/app-launcher/__tests__/expandable-section.browser-test.jsx +144 -0
  5. package/components/app-launcher/__tests__/link.browser-test.jsx +107 -0
  6. package/components/app-launcher/__tests__/tile.browser-test.jsx +267 -0
  7. package/components/avatar/__tests__/avatar.browser-test.jsx +207 -0
  8. package/components/builder-header/__tests__/builder-header.browser-test.jsx +53 -0
  9. package/components/button/__tests__/button.browser-test.jsx +226 -0
  10. package/components/button-group/__tests__/button-group.browser-test.jsx +144 -0
  11. package/components/button-stateful/__tests__/button-stateful.browser-test.jsx +125 -0
  12. package/components/card/__tests__/card.browser-test.jsx +255 -0
  13. package/components/carousel/__tests__/carousel.browser-test.jsx +527 -0
  14. package/components/color-picker/__tests__/color-picker.browser-test.jsx +767 -0
  15. package/components/combobox/__tests__/combobox.browser-test.jsx +654 -0
  16. package/components/data-table/__tests__/data-table.browser-test.jsx +1051 -0
  17. package/components/date-picker/__tests__/__snapshots__/datepicker.dom-snapshot-test.jsx.snap +4429 -0
  18. package/components/date-picker/__tests__/date-picker.browser-test.jsx +497 -0
  19. package/components/date-picker/__tests__/datepicker.dom-snapshot-test.jsx +109 -0
  20. package/components/docked-composer/__tests__/docked-composer.browser-test.jsx +83 -0
  21. package/components/expandable-section/__tests__/expandable-section.browser-test.jsx +133 -0
  22. package/components/expression/__tests__/expression.browser-test.jsx +255 -0
  23. package/components/filter/__tests__/filter.browser-test.jsx +147 -0
  24. package/components/forms/input/__tests__/inline.browser-test.jsx +164 -0
  25. package/components/global-header/__tests__/global-header.browser-test.jsx +177 -0
  26. package/components/global-navigation-bar/__tests__/global-navigation-bar.browser-test.jsx +464 -0
  27. package/components/icon/__tests__/icon.browser-test.jsx +214 -0
  28. package/components/illustration/__tests__/illustration.browser-test.jsx +177 -0
  29. package/components/input/__tests__/input.browser-test.jsx +612 -0
  30. package/components/location-map/__tests__/location-map.browser-test.jsx +158 -0
  31. package/components/lookup/__tests__/lookup.browser-test.jsx +353 -0
  32. package/components/media-object/__tests__/media-object.browser-test.jsx +87 -0
  33. package/components/menu-dropdown/__tests__/dropdown.browser-test.jsx +588 -0
  34. package/components/menu-picklist/__tests__/menupicklist.snapshot-old-test.jsx +41 -0
  35. package/components/menu-picklist/__tests__/picklist-base.browser-test.jsx +275 -0
  36. package/components/modal/__tests__/modal.browser-test.jsx +333 -0
  37. package/components/notification/__tests__/notification.browser-test.jsx +113 -0
  38. package/components/page-header/__tests__/page-header.browser-test.jsx +161 -0
  39. package/components/panel/__tests__/__snapshots__/filtering.dom-snapshot-test.jsx.snap +298 -0
  40. package/components/panel/__tests__/filtering.dom-snapshot-test.jsx +9 -0
  41. package/components/pill/__tests__/pill.browser-test.jsx +308 -0
  42. package/components/pill-container/__tests__/pill-container.browser-test.jsx +186 -0
  43. package/components/popover/__tests__/popover.browser-test.jsx +327 -0
  44. package/components/progress-indicator/__tests__/progress-indicator.browser-test.jsx +335 -0
  45. package/components/radio-button-group/__tests__/radio-button-group.browser-test.jsx +122 -0
  46. package/components/radio-group/__tests__/radio-group.browser-test.jsx +119 -0
  47. package/components/setup-assistant/__tests__/setup-assistant.browser-test.jsx +77 -0
  48. package/components/slider/__tests__/slider.browser-test.jsx +389 -0
  49. package/components/spinner/__tests__/spinner.browser-test.jsx +57 -0
  50. package/components/split-view/__tests__/split-view.listbox.browser-test.jsx +225 -0
  51. package/components/split-view/__tests__/split-view.listbox.header.browser-test.jsx +158 -0
  52. package/components/split-view/__tests__/split-view.listbox.unread.browser-test.jsx +114 -0
  53. package/components/tabs/__tests__/tabs.browser-test.jsx +458 -0
  54. package/components/textarea/__tests__/textarea.browser-test.jsx +175 -0
  55. package/components/time-picker/__tests__/time-picker.browser-test.jsx +46 -0
  56. package/components/toast/__tests__/toast.browser-test.jsx +118 -0
  57. package/components/tooltip/__tests__/tooltip.browser-test.jsx +214 -0
  58. package/components/tree/__tests__/tree.browser-test.jsx +303 -0
  59. package/components/vertical-navigation/__tests__/navigation.browser-test.jsx +117 -0
  60. package/components/visual-picker/__tests__/visual-picker.browser-test.jsx +288 -0
  61. package/components/welcome-mat/__tests__/welcome-mat.browser-test.jsx +358 -0
  62. package/design-system-react-components.js +1 -1
  63. package/design-system-react-components.min.js.LICENSE.txt +1 -1
  64. package/design-system-react.js +1 -1
  65. package/design-system-react.min.js.LICENSE.txt +1 -1
  66. package/lib/design-system-react-components.min.js.LICENSE.txt +1 -1
  67. package/lib/design-system-react.min.js.LICENSE.txt +1 -1
  68. package/lib/package.json +1 -1
  69. package/package.json +1 -1
@@ -0,0 +1,275 @@
1
+ /* eslint-disable react/no-render-return-value */
2
+
3
+ import React from 'react';
4
+ import ReactDOM from 'react-dom';
5
+ import assign from 'lodash.assign';
6
+ import TestUtils from 'react-dom/test-utils';
7
+ import { expect } from 'chai';
8
+
9
+ import SLDSMenuPicklist from '../../menu-picklist';
10
+ import IconSettings from '../../icon-settings';
11
+
12
+ const { Simulate } = TestUtils;
13
+
14
+ describe('SLDSMenuPicklist: ', function () {
15
+ let body;
16
+
17
+ const options = [
18
+ {
19
+ label: 'A Option Option Super Super Long',
20
+ value: 'A0',
21
+ title: 'Greg',
22
+ },
23
+ {
24
+ label: 'B Option',
25
+ value: 'B0',
26
+ },
27
+ ];
28
+
29
+ const renderPicklist = (inst) => {
30
+ body = document.createElement('div');
31
+ document.body.appendChild(body);
32
+ /* deepscan-disable REACT_ASYNC_RENDER_RETURN_VALUE */
33
+ return ReactDOM.render(
34
+ <div>
35
+ <IconSettings iconPath="/assets/icons">{inst}</IconSettings>
36
+ </div>,
37
+ body
38
+ );
39
+ /* deepscan-enable REACT_ASYNC_RENDER_RETURN_VALUE */
40
+ };
41
+
42
+ function removePicklist() {
43
+ ReactDOM.unmountComponentAtNode(body);
44
+ document.body.removeChild(body);
45
+ }
46
+
47
+ const defaultProps = {
48
+ modal: false,
49
+ options,
50
+ placeholder: 'Select a contact',
51
+ value: 'C0',
52
+ silenceDeprecationWarning: true,
53
+ };
54
+
55
+ const createPicklist = (props) =>
56
+ React.createElement(SLDSMenuPicklist, assign({}, defaultProps, props));
57
+
58
+ const getPicklist = (props) => renderPicklist(createPicklist(props));
59
+ const getMenu = (dom) => dom.querySelector('.slds-dropdown');
60
+
61
+ describe('in modal mode', () => {
62
+ let cmp;
63
+ let btn;
64
+
65
+ beforeEach(() => {
66
+ cmp = getPicklist({ modal: true });
67
+ [btn] = cmp.getElementsByClassName('slds-button');
68
+ });
69
+
70
+ afterEach(() => {
71
+ removePicklist();
72
+ });
73
+
74
+ it('expands/contracts the dropdown on click', () => {
75
+ expect(getMenu(document.body)).to.equal(null);
76
+ Simulate.click(btn, {});
77
+ expect(getMenu(document.body).className).to.include('slds-dropdown_left');
78
+ Simulate.click(btn, {});
79
+ expect(getMenu(document.body)).to.equal(null);
80
+ });
81
+ });
82
+
83
+ describe('with click handler', () => {
84
+ let cmp;
85
+ let btn;
86
+ let clicked;
87
+
88
+ beforeEach(() => {
89
+ clicked = false;
90
+ cmp = getPicklist({
91
+ onClick: () => {
92
+ clicked = true;
93
+ },
94
+ });
95
+ [btn] = cmp.getElementsByClassName('slds-button');
96
+ });
97
+
98
+ afterEach(() => {
99
+ removePicklist();
100
+ });
101
+
102
+ it('gives the button correct aria properties', () => {
103
+ expect(btn.getAttribute('aria-haspopup')).to.equal('true');
104
+ });
105
+
106
+ it('sets the placeholder', () => {
107
+ expect(btn.textContent).to.equal('Select a contact');
108
+ });
109
+
110
+ it('expands/contracts the dropdown on click', () => {
111
+ expect(getMenu(body)).to.equal(null);
112
+ Simulate.click(btn, {});
113
+ expect(getMenu(body).className).to.include('slds-dropdown');
114
+ Simulate.click(btn, {});
115
+ expect(getMenu(body)).to.equal(null);
116
+ });
117
+
118
+ it('preserves click behavior', () => {
119
+ expect(clicked).to.be.false;
120
+ Simulate.click(btn, {});
121
+ expect(clicked).to.be.true;
122
+ });
123
+ });
124
+
125
+ describe('expanded with onSelect', () => {
126
+ let cmp;
127
+ let btn;
128
+ let selected;
129
+
130
+ beforeEach(() => {
131
+ selected = false;
132
+ cmp = getPicklist({
133
+ onSelect: (i) => {
134
+ selected = i;
135
+ },
136
+ });
137
+ [btn] = cmp.getElementsByClassName('slds-button');
138
+ Simulate.click(btn, {});
139
+ });
140
+
141
+ afterEach(() => {
142
+ removePicklist();
143
+ });
144
+
145
+ it('selects an item', () => {
146
+ expect(selected).to.be.false;
147
+ const items = getMenu(body).querySelectorAll('.slds-dropdown__item');
148
+ Simulate.click(items[1].querySelector('a'), {});
149
+ expect(selected.value).to.equal('B0');
150
+ });
151
+ });
152
+
153
+ describe('disabled', () => {
154
+ let cmp;
155
+ let btn;
156
+ let clicked;
157
+
158
+ beforeEach(() => {
159
+ clicked = false;
160
+ cmp = getPicklist({
161
+ disabled: true,
162
+ onClick: () => {
163
+ clicked = true;
164
+ },
165
+ });
166
+ [btn] = cmp.getElementsByClassName('slds-button');
167
+ });
168
+
169
+ afterEach(() => {
170
+ removePicklist();
171
+ });
172
+
173
+ it("doesn't open", () => {
174
+ Simulate.click(btn, {});
175
+ expect(getMenu(body)).to.equal(null);
176
+ });
177
+
178
+ it('prevents click behavior', () => {
179
+ expect(clicked).to.be.false;
180
+ Simulate.click(btn, {});
181
+ expect(clicked).to.be.false;
182
+ });
183
+ });
184
+
185
+ describe('accessible markup', () => {
186
+ let cmp;
187
+ let btn;
188
+
189
+ beforeEach(() => {
190
+ cmp = getPicklist({});
191
+ [btn] = cmp.getElementsByClassName('slds-button');
192
+ });
193
+
194
+ afterEach(() => {
195
+ removePicklist();
196
+ });
197
+
198
+ it('<ul> has role menu & aria-labelledby', () => {
199
+ Simulate.click(btn, {});
200
+ const ulRole = getMenu(body).querySelector('ul').getAttribute('role');
201
+ const ulAria = getMenu(body)
202
+ .querySelector('ul')
203
+ .getAttribute('aria-labelledby');
204
+ expect(ulRole).to.equal('menu');
205
+ expect(ulAria).to.equal(btn.getAttribute('id'));
206
+ });
207
+
208
+ it('<a> inside <li> has role menuitem', () => {
209
+ Simulate.click(btn, {});
210
+ const items = getMenu(body).querySelectorAll('.slds-dropdown__item a');
211
+ const anchorRole = items[1].getAttribute('role');
212
+ const match =
213
+ anchorRole === 'menuitem' ||
214
+ anchorRole === 'menuitemradio' ||
215
+ anchorRole === 'menuitemcheckbox';
216
+ expect(match).to.be.true;
217
+ });
218
+ });
219
+
220
+ describe('Keyboard behavior', () => {
221
+ let cmp;
222
+ let btn;
223
+ let selected;
224
+
225
+ beforeEach(() => {
226
+ selected = false;
227
+ cmp = getPicklist({
228
+ onSelect: (i) => {
229
+ selected = i;
230
+ },
231
+ });
232
+ [btn] = cmp.getElementsByClassName('slds-button');
233
+ });
234
+
235
+ afterEach(() => {
236
+ removePicklist();
237
+ });
238
+
239
+ it('opens menu with enter', () => {
240
+ expect(getMenu(body)).to.equal(null);
241
+ Simulate.keyDown(btn, { key: 'Enter', keyCode: 13, which: 13 });
242
+ expect(getMenu(body)).to.not.equal(null);
243
+ });
244
+
245
+ it('opens menu with down arrow key', () => {
246
+ expect(getMenu(body)).to.equal(null);
247
+ Simulate.keyDown(btn, { key: 'Down', keyCode: 40, which: 40 });
248
+ expect(getMenu(body)).to.not.equal(null);
249
+ });
250
+
251
+ it('selects an item with keyboard', () => {
252
+ Simulate.click(btn, {});
253
+ expect(selected).to.be.false;
254
+
255
+ const menu = getMenu(body);
256
+ Simulate.keyDown(menu, { key: 'Down', keyCode: 40, which: 40 });
257
+ Simulate.keyDown(menu, { key: 'Down', keyCode: 40, which: 40 });
258
+ Simulate.keyDown(menu, { key: 'Enter', keyCode: 13, which: 13 });
259
+ expect(selected.value).to.equal('B0');
260
+ });
261
+
262
+ it('closes Menu on esc', () => {
263
+ expect(getMenu(body)).to.equal(null);
264
+ Simulate.click(btn, {});
265
+ expect(getMenu(body)).to.not.equal(null);
266
+ const menuItems = getMenu(body).querySelectorAll('.slds-dropdown__item');
267
+ Simulate.keyDown(menuItems[1].querySelector('a'), {
268
+ key: 'Esc',
269
+ keyCode: 27,
270
+ which: 27,
271
+ });
272
+ expect(getMenu(body)).to.equal(null);
273
+ });
274
+ });
275
+ });
@@ -0,0 +1,333 @@
1
+ /* eslint-disable no-unused-vars */
2
+ /* eslint-disable react/no-find-dom-node */
3
+
4
+ import React from 'react';
5
+ import ReactDOM from 'react-dom';
6
+ import assign from 'lodash.assign';
7
+ import TestUtils from 'react-dom/test-utils';
8
+ import { expect } from 'chai';
9
+
10
+ import SLDSModal from '../../modal';
11
+ import IconSettings from '../../icon-settings';
12
+ import Settings from '../../settings';
13
+
14
+ const { Simulate } = TestUtils;
15
+
16
+ describe('SLDSModal: ', function () {
17
+ let container;
18
+ let renderedNode;
19
+
20
+ // set "app node" fixture, so no warnings are triggered.
21
+ let appNode = document.createElement('span');
22
+ appNode.id = 'app';
23
+ document.body.appendChild(appNode);
24
+ Settings.setAppElement('#app');
25
+
26
+ after(() => {
27
+ document.body.removeChild(appNode);
28
+ appNode = null;
29
+ });
30
+
31
+ afterEach(() => {
32
+ ReactDOM.unmountComponentAtNode(container);
33
+ document.body.removeChild(container);
34
+ container = null;
35
+ });
36
+
37
+ const defaultProps = {
38
+ align: 'top',
39
+ children: <div key>hello</div>,
40
+ };
41
+
42
+ const renderModal = (modalInstance) => {
43
+ container = document.createElement('div');
44
+
45
+ const opener = (
46
+ <button type="button">
47
+ <IconSettings iconPath="/assets/icons">{modalInstance}</IconSettings>
48
+ </button>
49
+ );
50
+ document.body.appendChild(container);
51
+ // eslint-disable-next-line react/no-render-return-value
52
+ renderedNode = ReactDOM.render(opener, container); // deepscan-disable-line REACT_ASYNC_RENDER_RETURN_VALUE
53
+ return renderedNode;
54
+ };
55
+
56
+ const createModal = (props) =>
57
+ React.createElement(SLDSModal, assign({}, defaultProps, props));
58
+
59
+ const getModal = (props) => renderModal(createModal(props));
60
+
61
+ const getModalContainerNode = (dom) =>
62
+ dom.querySelector('[role="dialog"]') ||
63
+ dom.querySelector('[role="alertdialog"]');
64
+ const getModalNode = (dom) => dom.querySelector('.slds-modal');
65
+
66
+ describe('Styling', () => {
67
+ beforeEach(() => {
68
+ getModal({
69
+ containerClassName: 'container-class-name-test',
70
+ contentClassName: 'content-class-name-test',
71
+ contentStyle: { height: '500px' },
72
+ isOpen: true,
73
+ portalClassName: 'portal-class-name-test',
74
+ });
75
+ });
76
+ it('has correct containerClassName, contentClassName, contentStyle, and portalClassName', () => {
77
+ const modalContainer = getModalNode(document.body).querySelector(
78
+ '.slds-modal__container.container-class-name-test'
79
+ );
80
+ expect(modalContainer).to.exist;
81
+ const modalContent = getModalNode(document.body).querySelector(
82
+ '.slds-modal__content.content-class-name-test'
83
+ );
84
+ expect(modalContent).to.exist;
85
+ expect(modalContent.style.height).to.equal('500px');
86
+ const modalPortal = document.querySelector(
87
+ 'body > .portal-class-name-test'
88
+ );
89
+ expect(modalPortal).to.exist;
90
+ });
91
+ });
92
+
93
+ describe('Sizing', () => {
94
+ it('size is set to small', () => {
95
+ const cmp = getModal({
96
+ isOpen: true,
97
+ size: 'small',
98
+ });
99
+ const modal = getModalNode(document.body);
100
+ expect(modal.className).to.include('slds-modal_small');
101
+ });
102
+ it('size is set to medium', () => {
103
+ const cmp = getModal({
104
+ isOpen: true,
105
+ size: 'medium',
106
+ });
107
+ const modal = getModalNode(document.body);
108
+ expect(modal.className).to.include('slds-modal_medium');
109
+ });
110
+ it('size is set to large', () => {
111
+ const cmp = getModal({
112
+ isOpen: true,
113
+ size: 'large',
114
+ });
115
+ const modal = getModalNode(document.body);
116
+ expect(modal.className).to.include('slds-modal_large');
117
+ });
118
+ });
119
+
120
+ describe('Closed modal', () => {
121
+ beforeEach(() => {
122
+ getModal({ isOpen: false });
123
+ });
124
+
125
+ it('updates the overflow', () => {
126
+ expect(document.body.style.overflow).to.equal('inherit');
127
+ });
128
+
129
+ it('does not render to the body', () => {
130
+ expect(getModalNode(document.body)).to.be.null;
131
+ });
132
+ });
133
+
134
+ describe('Open modal', () => {
135
+ let cmp;
136
+ let closed;
137
+ let modal;
138
+
139
+ beforeEach(() => {
140
+ closed = false;
141
+ cmp = getModal({
142
+ assistiveText: {
143
+ closeButton: 'Exit',
144
+ },
145
+ isOpen: true,
146
+ size: 'large',
147
+ containerClassName: 'my-custom-class',
148
+ onRequestClose: () => {
149
+ closed = true;
150
+ },
151
+ });
152
+ modal = getModalNode(document.body);
153
+ });
154
+
155
+ it('size is set to large', () => {
156
+ expect(modal.className).to.include('slds-modal_large');
157
+ });
158
+
159
+ it('adds custom classname from modal container prop', () => {
160
+ expect(modal.firstChild.className).to.include('my-custom-class');
161
+ });
162
+
163
+ it('renders correct assistive text/title for close button', () => {
164
+ const closeBtn = modal.querySelector('.slds-modal__close');
165
+ expect(closeBtn.title).to.equal('Exit');
166
+ });
167
+
168
+ it('calls onRequestClose', () => {
169
+ const closeBtn = modal.querySelector('.slds-modal__close');
170
+ expect(closed).to.be.false;
171
+ Simulate.click(closeBtn, {});
172
+ expect(closed).to.be.true;
173
+ });
174
+ });
175
+
176
+ describe('Proper HTML markup', () => {
177
+ it('dismissible modal has role=dialog', () => {
178
+ // eslint-disable-next-line no-unused-vars
179
+ const cmp = getModal({
180
+ isOpen: true,
181
+ size: 'medium',
182
+ });
183
+ const modal = getModalContainerNode(document.body);
184
+ const role = modal.getAttribute('role');
185
+ expect(role).to.equal('dialog');
186
+ });
187
+
188
+ it('non-dismissible modal has role=alertdialog', () => {
189
+ const cmp = getModal({
190
+ isOpen: true,
191
+ disableClose: true,
192
+ });
193
+ const modal = getModalContainerNode(document.body);
194
+ const role = modal.getAttribute('role');
195
+ expect(role).to.equal('alertdialog');
196
+ });
197
+ });
198
+
199
+ describe('Open with custom header and header className', () => {
200
+ let modal;
201
+
202
+ beforeEach(() => {
203
+ getModal({
204
+ header: <div id="art-vandelay">Art vandelay</div>,
205
+ headerClassName: 'art-vandelay',
206
+ isOpen: true,
207
+ });
208
+ modal = getModalNode(document.body);
209
+ });
210
+
211
+ it('adds the header', () => {
212
+ const customHeader = modal.querySelector('#art-vandelay');
213
+ expect(customHeader).to.not.be.null;
214
+ });
215
+
216
+ it('adds the custom header class', () => {
217
+ expect(modal.querySelector('.slds-modal__header').className).to.include(
218
+ 'art-vandelay'
219
+ );
220
+ });
221
+ });
222
+
223
+ describe('Open with Prompt and Footer', () => {
224
+ let modal;
225
+
226
+ beforeEach(() => {
227
+ const feet = <div className="toes">Toes</div>;
228
+ getModal({
229
+ isOpen: true,
230
+ prompt: 'warning',
231
+ heading: 'are you sure?',
232
+ footer: feet,
233
+ });
234
+ modal = getModalNode(document.body);
235
+ });
236
+
237
+ it('adds the default h1 heading element', () => {
238
+ const header = modal.querySelector('section .slds-modal__header h1');
239
+ expect(header).to.not.be.null;
240
+ });
241
+
242
+ it('adds the footer', () => {
243
+ const footer = modal.querySelector('.slds-modal__footer');
244
+ expect(footer.className).to.include('slds-theme_default');
245
+ });
246
+
247
+ it('adds the prompt class', () => {
248
+ expect(modal.className).to.include('slds-modal_prompt');
249
+ });
250
+
251
+ it('adds the prompt theme class', () => {
252
+ expect(modal.querySelector('.slds-modal__header').className).to.include(
253
+ 'slds-theme_warning'
254
+ );
255
+ });
256
+
257
+ it('adds the footer html content', () => {
258
+ expect(modal.querySelector('.toes').innerHTML).to.equal('Toes');
259
+ });
260
+ });
261
+
262
+ describe('Open Directional', () => {
263
+ let modal;
264
+
265
+ beforeEach(() => {
266
+ const feet = [
267
+ <div key="test-content1" className="toes">
268
+ Toe 1
269
+ </div>,
270
+ <div key="test-content2" className="toes">
271
+ Toe 2
272
+ </div>,
273
+ ];
274
+ getModal({
275
+ isOpen: true,
276
+ directional: true,
277
+ footer: feet,
278
+ });
279
+ modal = getModalNode(document.body);
280
+ });
281
+
282
+ it('adds the footer', () => {
283
+ const footer = modal.querySelector('.slds-modal__footer_directional');
284
+ expect(footer.className).to.include('slds-modal__footer');
285
+ });
286
+ });
287
+
288
+ describe('Keyboard behavior', () => {
289
+ let modal;
290
+
291
+ beforeEach(() => {
292
+ const feet = [
293
+ <button type="button" key="test-content1" className="cancel">
294
+ Cancel
295
+ </button>,
296
+ <button type="button" key="test-content2" className="save">
297
+ Save
298
+ </button>,
299
+ ];
300
+ getModal({
301
+ isOpen: true,
302
+ directional: true,
303
+ footer: feet,
304
+ });
305
+ modal = getModalNode(document.body);
306
+ });
307
+
308
+ it('first tab focuses close button', () => {
309
+ // There an issue with this test, functionality works fine.
310
+ // setTimeout(() => {
311
+ // Simulate.keyDown(modal, {
312
+ // key: 'Tab',
313
+ // keyCode: 9,
314
+ // which: 9,
315
+ // });
316
+ // setTimeout(() => {
317
+ // expect(document.activeElement.className).to.include(
318
+ // 'slds-modal__close'
319
+ // );
320
+ // done();
321
+ // }, 200);
322
+ // }, 200);
323
+ });
324
+
325
+ it('enter on close button works', () => {
326
+ // TODO: simulate enter on close button and modal is undefined
327
+ });
328
+
329
+ it('traps focus inside Modal', () => {
330
+ // TODO: simulate tabbing around inside of Modal
331
+ });
332
+ });
333
+ });
@@ -0,0 +1,113 @@
1
+ /* eslint-disable react/no-render-return-value */
2
+ /* eslint-disable react/no-find-dom-node */
3
+
4
+ import React from 'react';
5
+ import ReactDOM from 'react-dom';
6
+
7
+ import TestUtils from 'react-dom/test-utils';
8
+ import { expect } from 'chai';
9
+
10
+ import SLDSNotification from '../../notification';
11
+ import IconSettings from '../../icon-settings';
12
+
13
+ describe('SLDSNotification: ', () => {
14
+ const generateNotification = function (notificationInstance) {
15
+ const reactCmp = TestUtils.renderIntoDocument(
16
+ <div>
17
+ <IconSettings iconPath="/assets/icons">
18
+ {notificationInstance}
19
+ </IconSettings>
20
+ </div>
21
+ );
22
+ return ReactDOM.findDOMNode(reactCmp);
23
+ };
24
+
25
+ describe('component renders', () => {
26
+ it('notification renders', () => {
27
+ const notification = generateNotification(
28
+ <SLDSNotification
29
+ variant="toast"
30
+ theme="success"
31
+ isOpen
32
+ content="hi"
33
+ silenceDeprecationWarning
34
+ />
35
+ );
36
+ expect(notification).to.not.equal(undefined);
37
+ });
38
+ });
39
+
40
+ describe('component basic props render', () => {
41
+ it('renders variant', () => {
42
+ const notification = generateNotification(
43
+ <SLDSNotification
44
+ variant="toast"
45
+ theme="success"
46
+ icon="notification"
47
+ isOpen
48
+ texture
49
+ animated
50
+ content="hi"
51
+ silenceDeprecationWarning
52
+ />
53
+ );
54
+ const alert = notification.getElementsByTagName('div')[1];
55
+ expect(alert.className).to.include('slds-notify_toast');
56
+ });
57
+
58
+ it('renders theme', () => {
59
+ const notification = generateNotification(
60
+ <SLDSNotification
61
+ variant="toast"
62
+ theme="error"
63
+ isOpen
64
+ content="hi"
65
+ silenceDeprecationWarning
66
+ />
67
+ );
68
+ const alert = notification.getElementsByTagName('div')[1];
69
+ expect(alert.className).to.include('slds-theme_error');
70
+ });
71
+
72
+ it('renders icon', () => {
73
+ const notification = generateNotification(
74
+ <SLDSNotification
75
+ variant="alert"
76
+ theme="success"
77
+ iconName="notification"
78
+ isOpen
79
+ texture
80
+ content="hi"
81
+ silenceDeprecationWarning
82
+ />
83
+ );
84
+
85
+ const close = notification.querySelectorAll('button');
86
+ const svgs = notification.querySelectorAll(
87
+ '[*|href="/assets/icons/utility-sprite/svg/symbols.svg#notification"]'
88
+ );
89
+ expect(close[0].className).to.include('slds-notify__close');
90
+ expect(svgs[0]).to.exist;
91
+ });
92
+ });
93
+
94
+ describe('dismiss notification click', () => {
95
+ it('button onClick invokes method from props', () => {
96
+ const onClick = sinon.spy();
97
+ const notification = generateNotification(
98
+ <SLDSNotification
99
+ variant="toast"
100
+ theme="success"
101
+ iconName="notification"
102
+ onDismiss={onClick}
103
+ isOpen
104
+ content="hi"
105
+ silenceDeprecationWarning
106
+ />
107
+ );
108
+ const dismissBtn = notification.getElementsByTagName('button')[0];
109
+ TestUtils.Simulate.click(dismissBtn);
110
+ expect(onClick.calledOnce).to.be.true;
111
+ });
112
+ });
113
+ });