@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.
- package/components/accordion/__tests__/accordion.browser-test.jsx +302 -0
- package/components/alert/__tests__/alert.browser-test.jsx +100 -0
- package/components/app-launcher/__tests__/app-launcher.browser-test.jsx +228 -0
- package/components/app-launcher/__tests__/expandable-section.browser-test.jsx +144 -0
- package/components/app-launcher/__tests__/link.browser-test.jsx +107 -0
- package/components/app-launcher/__tests__/tile.browser-test.jsx +267 -0
- package/components/avatar/__tests__/avatar.browser-test.jsx +207 -0
- package/components/builder-header/__tests__/builder-header.browser-test.jsx +53 -0
- package/components/button/__tests__/button.browser-test.jsx +226 -0
- package/components/button-group/__tests__/button-group.browser-test.jsx +144 -0
- package/components/button-stateful/__tests__/button-stateful.browser-test.jsx +125 -0
- package/components/card/__tests__/card.browser-test.jsx +255 -0
- package/components/carousel/__tests__/carousel.browser-test.jsx +527 -0
- package/components/color-picker/__tests__/color-picker.browser-test.jsx +767 -0
- package/components/combobox/__tests__/combobox.browser-test.jsx +654 -0
- package/components/data-table/__tests__/data-table.browser-test.jsx +1051 -0
- package/components/date-picker/__tests__/__snapshots__/datepicker.dom-snapshot-test.jsx.snap +4429 -0
- package/components/date-picker/__tests__/date-picker.browser-test.jsx +497 -0
- package/components/date-picker/__tests__/datepicker.dom-snapshot-test.jsx +109 -0
- package/components/docked-composer/__tests__/docked-composer.browser-test.jsx +83 -0
- package/components/expandable-section/__tests__/expandable-section.browser-test.jsx +133 -0
- package/components/expression/__tests__/expression.browser-test.jsx +255 -0
- package/components/filter/__tests__/filter.browser-test.jsx +147 -0
- package/components/forms/input/__tests__/inline.browser-test.jsx +164 -0
- package/components/global-header/__tests__/global-header.browser-test.jsx +177 -0
- package/components/global-navigation-bar/__tests__/global-navigation-bar.browser-test.jsx +464 -0
- package/components/icon/__tests__/icon.browser-test.jsx +214 -0
- package/components/illustration/__tests__/illustration.browser-test.jsx +177 -0
- package/components/input/__tests__/input.browser-test.jsx +612 -0
- package/components/location-map/__tests__/location-map.browser-test.jsx +158 -0
- package/components/lookup/__tests__/lookup.browser-test.jsx +353 -0
- package/components/media-object/__tests__/media-object.browser-test.jsx +87 -0
- package/components/menu-dropdown/__tests__/dropdown.browser-test.jsx +588 -0
- package/components/menu-picklist/__tests__/menupicklist.snapshot-old-test.jsx +41 -0
- package/components/menu-picklist/__tests__/picklist-base.browser-test.jsx +275 -0
- package/components/modal/__tests__/modal.browser-test.jsx +333 -0
- package/components/notification/__tests__/notification.browser-test.jsx +113 -0
- package/components/page-header/__tests__/page-header.browser-test.jsx +161 -0
- package/components/panel/__tests__/__snapshots__/filtering.dom-snapshot-test.jsx.snap +298 -0
- package/components/panel/__tests__/filtering.dom-snapshot-test.jsx +9 -0
- package/components/pill/__tests__/pill.browser-test.jsx +308 -0
- package/components/pill-container/__tests__/pill-container.browser-test.jsx +186 -0
- package/components/popover/__tests__/popover.browser-test.jsx +327 -0
- package/components/progress-indicator/__tests__/progress-indicator.browser-test.jsx +335 -0
- package/components/radio-button-group/__tests__/radio-button-group.browser-test.jsx +122 -0
- package/components/radio-group/__tests__/radio-group.browser-test.jsx +119 -0
- package/components/setup-assistant/__tests__/setup-assistant.browser-test.jsx +77 -0
- package/components/slider/__tests__/slider.browser-test.jsx +389 -0
- package/components/spinner/__tests__/spinner.browser-test.jsx +57 -0
- package/components/split-view/__tests__/split-view.listbox.browser-test.jsx +225 -0
- package/components/split-view/__tests__/split-view.listbox.header.browser-test.jsx +158 -0
- package/components/split-view/__tests__/split-view.listbox.unread.browser-test.jsx +114 -0
- package/components/tabs/__tests__/tabs.browser-test.jsx +458 -0
- package/components/textarea/__tests__/textarea.browser-test.jsx +175 -0
- package/components/time-picker/__tests__/time-picker.browser-test.jsx +46 -0
- package/components/toast/__tests__/toast.browser-test.jsx +118 -0
- package/components/tooltip/__tests__/tooltip.browser-test.jsx +214 -0
- package/components/tree/__tests__/tree.browser-test.jsx +303 -0
- package/components/vertical-navigation/__tests__/navigation.browser-test.jsx +117 -0
- package/components/visual-picker/__tests__/visual-picker.browser-test.jsx +288 -0
- package/components/welcome-mat/__tests__/welcome-mat.browser-test.jsx +358 -0
- package/design-system-react-components.js +1 -1
- package/design-system-react-components.min.js.LICENSE.txt +1 -1
- package/design-system-react.js +1 -1
- package/design-system-react.min.js.LICENSE.txt +1 -1
- package/lib/design-system-react-components.min.js.LICENSE.txt +1 -1
- package/lib/design-system-react.min.js.LICENSE.txt +1 -1
- package/lib/package.json +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import assign from 'lodash.assign';
|
|
4
|
+
import chai, { expect } from 'chai';
|
|
5
|
+
import chaiEnzyme from 'chai-enzyme';
|
|
6
|
+
|
|
7
|
+
import IconSettings from '../../icon-settings';
|
|
8
|
+
import Settings from '../../settings';
|
|
9
|
+
import SLDSLocationMap from '../../location-map';
|
|
10
|
+
|
|
11
|
+
chai.use(chaiEnzyme());
|
|
12
|
+
|
|
13
|
+
describe('SLDSLocationMap: ', function () {
|
|
14
|
+
let container;
|
|
15
|
+
let renderedNode;
|
|
16
|
+
|
|
17
|
+
// set "app node" fixture, so no warnings are triggered.
|
|
18
|
+
let appNode = document.createElement('span');
|
|
19
|
+
appNode.id = 'app';
|
|
20
|
+
document.body.appendChild(appNode);
|
|
21
|
+
Settings.setAppElement('#app');
|
|
22
|
+
|
|
23
|
+
after(() => {
|
|
24
|
+
document.body.removeChild(appNode);
|
|
25
|
+
appNode = null;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
ReactDOM.unmountComponentAtNode(container);
|
|
30
|
+
document.body.removeChild(container);
|
|
31
|
+
container = null;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const renderLocationMap = (locationMapInstance) => {
|
|
35
|
+
container = document.createElement('div');
|
|
36
|
+
|
|
37
|
+
const opener = (
|
|
38
|
+
<IconSettings iconPath="/assets/icons">
|
|
39
|
+
{locationMapInstance}
|
|
40
|
+
</IconSettings>
|
|
41
|
+
);
|
|
42
|
+
document.body.appendChild(container);
|
|
43
|
+
// eslint-disable-next-line react/no-render-return-value
|
|
44
|
+
renderedNode = ReactDOM.render(opener, container); // deepscan-disable-line REACT_ASYNC_RENDER_RETURN_VALUE
|
|
45
|
+
return renderedNode;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const defaultProps = {
|
|
49
|
+
googleAPIKey: 'AIzaSyDliLquGXGts9S8YtkWVolSQEJdBL1ZuWc',
|
|
50
|
+
};
|
|
51
|
+
const createLocationMap = (props) =>
|
|
52
|
+
React.createElement(SLDSLocationMap, assign({}, defaultProps, props));
|
|
53
|
+
|
|
54
|
+
const getLocationMap = (props) => renderLocationMap(createLocationMap(props));
|
|
55
|
+
|
|
56
|
+
const getLocationMapNode = (dom) => dom.querySelector('.slds-grid');
|
|
57
|
+
|
|
58
|
+
describe('Single Location', () => {
|
|
59
|
+
beforeEach(() => {
|
|
60
|
+
const locations = [
|
|
61
|
+
{
|
|
62
|
+
id: '1',
|
|
63
|
+
name: 'Worldwide Corporate Headquarters',
|
|
64
|
+
address: 'The Landmark @ One Market, San Francisco, CA',
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
getLocationMap({
|
|
69
|
+
defaultLocation: locations[0],
|
|
70
|
+
locations,
|
|
71
|
+
labels: {
|
|
72
|
+
title: 'Geo Code: 37°48'08.3"N 122°15'55.2W',
|
|
73
|
+
},
|
|
74
|
+
id: 'map-test',
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
it('renders map correctly', () => {
|
|
78
|
+
const Container = getLocationMapNode(document.body);
|
|
79
|
+
expect(Container.childElementCount).to.equal(1);
|
|
80
|
+
const MapContainer = Container.querySelector('.slds-map');
|
|
81
|
+
expect(MapContainer).to.exist;
|
|
82
|
+
expect(MapContainer.querySelector('iframe').title).to.equal(
|
|
83
|
+
'Geo Code: 37°48'08.3"N 122°15'55.2W'
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('Multiple Locations', () => {
|
|
89
|
+
const locations = [
|
|
90
|
+
{
|
|
91
|
+
id: '1',
|
|
92
|
+
name: 'Worldwide Corporate Headquarters',
|
|
93
|
+
address: 'The Landmark @ One Market, San Francisco, CA',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: '2',
|
|
97
|
+
name: 'salesforce.com inc Atlanta',
|
|
98
|
+
address: '950 East Paces Ferry Road NE, Atlanta, GA',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: '3',
|
|
102
|
+
name: 'salesforce.com inc Bellevue',
|
|
103
|
+
address: '929 108th Ave NE, Bellevue, WA',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: '4',
|
|
107
|
+
name: 'salesforce.com inc Boston',
|
|
108
|
+
address: '500 Boylston Street 19th Floor, Boston, MA',
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
id: '5',
|
|
112
|
+
name: 'salesforce.com inc Chicago',
|
|
113
|
+
address: '111 West Illinois Street, Chicago, IL',
|
|
114
|
+
},
|
|
115
|
+
];
|
|
116
|
+
|
|
117
|
+
beforeEach(() => {
|
|
118
|
+
getLocationMap({
|
|
119
|
+
defaultLocation: locations[0],
|
|
120
|
+
locations,
|
|
121
|
+
labels: {
|
|
122
|
+
title: 'Salesforce Locations In United States',
|
|
123
|
+
},
|
|
124
|
+
selection: locations[2],
|
|
125
|
+
id: 'map-test',
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
it('renders map correctly', () => {
|
|
129
|
+
const LocationMapContainer = getLocationMapNode(
|
|
130
|
+
document.body
|
|
131
|
+
).querySelector('.slds-map');
|
|
132
|
+
expect(LocationMapContainer).to.exist;
|
|
133
|
+
expect(LocationMapContainer.querySelector('iframe').title).to.equal(
|
|
134
|
+
'Salesforce Locations In United States'
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
it('renders map coordinates correctly', () => {
|
|
138
|
+
const LocationMapCoordinates = getLocationMapNode(
|
|
139
|
+
document.body
|
|
140
|
+
).querySelector('.slds-coordinates');
|
|
141
|
+
expect(LocationMapCoordinates).to.exist;
|
|
142
|
+
expect(
|
|
143
|
+
LocationMapCoordinates.querySelector('.slds-coordinates__title')
|
|
144
|
+
.textContent
|
|
145
|
+
).to.equal('Salesforce Locations In United States (5)');
|
|
146
|
+
const loc = LocationMapCoordinates.querySelector(
|
|
147
|
+
'.slds-coordinates__list'
|
|
148
|
+
).children;
|
|
149
|
+
expect(loc.length).to.equal(5);
|
|
150
|
+
expect(loc[0].querySelector('.slds-text-link').textContent).to.equal(
|
|
151
|
+
'Worldwide Corporate Headquarters'
|
|
152
|
+
);
|
|
153
|
+
expect(
|
|
154
|
+
loc[0].querySelectorAll('.slds-media__body span')[1].textContent
|
|
155
|
+
).to.equal('The Landmark @ One Market, San Francisco, CA');
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
});
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
/* eslint-disable prefer-destructuring */
|
|
2
|
+
/* eslint-disable no-unused-vars */
|
|
3
|
+
/* eslint-disable react/no-render-return-value */
|
|
4
|
+
/* eslint-disable react/no-find-dom-node */
|
|
5
|
+
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import ReactDOM from 'react-dom';
|
|
8
|
+
|
|
9
|
+
import assign from 'lodash.assign';
|
|
10
|
+
import TestUtils from 'react-dom/test-utils';
|
|
11
|
+
import { expect } from 'chai';
|
|
12
|
+
|
|
13
|
+
import SLDSLookup from '../../lookup';
|
|
14
|
+
import IconSettings from '../../icon-settings';
|
|
15
|
+
|
|
16
|
+
import Header from '../../lookup/header';
|
|
17
|
+
import Footer from '../../lookup/footer';
|
|
18
|
+
|
|
19
|
+
const { Simulate } = TestUtils;
|
|
20
|
+
|
|
21
|
+
describe('SLDSLookup: ', () => {
|
|
22
|
+
const generateLookup = function (lookupInstance) {
|
|
23
|
+
const reactCmp = TestUtils.renderIntoDocument(
|
|
24
|
+
<div>
|
|
25
|
+
<IconSettings iconPath="/assets/icons">{lookupInstance}</IconSettings>
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
return ReactDOM.findDOMNode(reactCmp);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const defaultProps = {
|
|
32
|
+
emptyMessage: 'No items found',
|
|
33
|
+
footerRenderer: Footer,
|
|
34
|
+
iconCategory: 'standard',
|
|
35
|
+
iconName: 'account',
|
|
36
|
+
isInline: true,
|
|
37
|
+
label: 'Account',
|
|
38
|
+
onChange(newValue) {
|
|
39
|
+
// console.log('New search term: ', newValue);
|
|
40
|
+
},
|
|
41
|
+
onSelect(item) {
|
|
42
|
+
// console.log(item, ' Selected');
|
|
43
|
+
},
|
|
44
|
+
options: [
|
|
45
|
+
{ label: 'Paddy"s Pub' },
|
|
46
|
+
{ label: 'Tyrell Corp' },
|
|
47
|
+
{ label: 'Paper St. Soap Company' },
|
|
48
|
+
{ label: 'Nakatomi Investments' },
|
|
49
|
+
{ label: 'Acme Landscaping' },
|
|
50
|
+
{ label: 'Acme Construction' },
|
|
51
|
+
],
|
|
52
|
+
silenceDeprecationWarning: true,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const getLookup = (props = {}) =>
|
|
56
|
+
React.createElement(SLDSLookup, assign({}, defaultProps, props));
|
|
57
|
+
const getLookupWithHeader = (props = { headerRenderer: Header }) =>
|
|
58
|
+
React.createElement(SLDSLookup, assign({}, defaultProps, props));
|
|
59
|
+
const getLookupWithSelection = (props = { selectedItem: 1 }) =>
|
|
60
|
+
React.createElement(SLDSLookup, assign({}, defaultProps, props));
|
|
61
|
+
|
|
62
|
+
const getItems = (lookup) =>
|
|
63
|
+
lookup.getElementsByClassName('js-slds-lookup__item');
|
|
64
|
+
|
|
65
|
+
describe('component renders', () => {
|
|
66
|
+
it('lookup renders', () => {
|
|
67
|
+
const lookup = generateLookup(getLookup());
|
|
68
|
+
expect(lookup).to.not.equal(undefined);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('component basic props render', () => {
|
|
73
|
+
it('renders label', () => {
|
|
74
|
+
const lookup = generateLookup(getLookup());
|
|
75
|
+
const label = lookup.getElementsByTagName('label')[0];
|
|
76
|
+
expect(label.textContent).to.equal('Account');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('LookupWithSelection - renders label', () => {
|
|
80
|
+
const lookup = generateLookup(getLookupWithSelection());
|
|
81
|
+
const label = lookup.getElementsByTagName('span')[0];
|
|
82
|
+
expect(label.textContent).to.equal('Account');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('isOpen=true renders open dropdown', () => {
|
|
86
|
+
const lookup = generateLookup(getLookup({ isOpen: true }));
|
|
87
|
+
const input = lookup.getElementsByTagName('input')[0];
|
|
88
|
+
const ariaExpanded = input.getAttribute('aria-expanded');
|
|
89
|
+
expect(ariaExpanded).to.equal('true');
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('accessibility markup passes', () => {
|
|
94
|
+
it('label for matches input id', () => {
|
|
95
|
+
const lookup = generateLookup(getLookup());
|
|
96
|
+
const labelFor = lookup
|
|
97
|
+
.getElementsByTagName('label')[0]
|
|
98
|
+
.getAttribute('for');
|
|
99
|
+
const inputId = lookup
|
|
100
|
+
.getElementsByTagName('input')[0]
|
|
101
|
+
.getAttribute('id');
|
|
102
|
+
expect(labelFor).to.equal(inputId);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('accessibility aria attributes pass', () => {
|
|
107
|
+
it('aria-expanded is false initally', () => {
|
|
108
|
+
const lookup = generateLookup(getLookup());
|
|
109
|
+
const ariaExpanded = lookup
|
|
110
|
+
.getElementsByTagName('input')[0]
|
|
111
|
+
.getAttribute('aria-expanded');
|
|
112
|
+
expect(ariaExpanded).to.equal('false');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('aria-expanded is true when clicking on input field', () => {
|
|
116
|
+
const lookup = generateLookup(getLookup());
|
|
117
|
+
const input = lookup.getElementsByTagName('input')[0];
|
|
118
|
+
TestUtils.Simulate.click(input);
|
|
119
|
+
const ariaExpanded = lookup
|
|
120
|
+
.getElementsByTagName('input')[0]
|
|
121
|
+
.getAttribute('aria-expanded');
|
|
122
|
+
expect(ariaExpanded).to.equal('true');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('LookupWithSelection - aria-expanded is true when deleting selection', () => {
|
|
126
|
+
const lookup = generateLookup(getLookupWithSelection());
|
|
127
|
+
const deleteBtn = lookup.getElementsByTagName('button')[0];
|
|
128
|
+
TestUtils.Simulate.keyDown(deleteBtn, {
|
|
129
|
+
key: 'Down',
|
|
130
|
+
keyCode: 46,
|
|
131
|
+
which: 46,
|
|
132
|
+
});
|
|
133
|
+
const ariaExpanded = lookup
|
|
134
|
+
.getElementsByTagName('input')[0]
|
|
135
|
+
.getAttribute('aria-expanded');
|
|
136
|
+
expect(ariaExpanded).to.equal('true');
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
describe('selecting item works', () => {
|
|
141
|
+
it('no fixed header: focuses correct item', () => {
|
|
142
|
+
const lookup = generateLookup(getLookup());
|
|
143
|
+
const input = lookup.getElementsByTagName('input')[0];
|
|
144
|
+
TestUtils.Simulate.click(input);
|
|
145
|
+
TestUtils.Simulate.keyDown(input, {
|
|
146
|
+
key: 'Down',
|
|
147
|
+
keyCode: 40,
|
|
148
|
+
which: 40,
|
|
149
|
+
});
|
|
150
|
+
TestUtils.Simulate.keyDown(input, {
|
|
151
|
+
key: 'Down',
|
|
152
|
+
keyCode: 40,
|
|
153
|
+
which: 40,
|
|
154
|
+
});
|
|
155
|
+
const ariaActiveDescendant = lookup
|
|
156
|
+
.getElementsByTagName('input')[0]
|
|
157
|
+
.getAttribute('aria-activedescendant');
|
|
158
|
+
expect(ariaActiveDescendant).to.equal('item-1');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('with fixed header: focuses correct item', () => {
|
|
162
|
+
const lookup = generateLookup(getLookupWithHeader());
|
|
163
|
+
const input = lookup.getElementsByTagName('input')[0];
|
|
164
|
+
TestUtils.Simulate.click(input);
|
|
165
|
+
TestUtils.Simulate.keyDown(input, {
|
|
166
|
+
key: 'Down',
|
|
167
|
+
keyCode: 40,
|
|
168
|
+
which: 40,
|
|
169
|
+
});
|
|
170
|
+
TestUtils.Simulate.keyDown(input, {
|
|
171
|
+
key: 'Down',
|
|
172
|
+
keyCode: 40,
|
|
173
|
+
which: 40,
|
|
174
|
+
});
|
|
175
|
+
const ariaActiveDescendant = lookup
|
|
176
|
+
.getElementsByTagName('input')[0]
|
|
177
|
+
.getAttribute('aria-activedescendant');
|
|
178
|
+
expect(ariaActiveDescendant).to.equal('item-0');
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('no header: selects correct item', () => {
|
|
182
|
+
const lookup = generateLookup(getLookup());
|
|
183
|
+
const input = lookup.getElementsByTagName('input')[0];
|
|
184
|
+
TestUtils.Simulate.click(input);
|
|
185
|
+
TestUtils.Simulate.keyDown(input, {
|
|
186
|
+
key: 'Down',
|
|
187
|
+
keyCode: 40,
|
|
188
|
+
which: 40,
|
|
189
|
+
});
|
|
190
|
+
TestUtils.Simulate.keyDown(input, {
|
|
191
|
+
key: 'Down',
|
|
192
|
+
keyCode: 40,
|
|
193
|
+
which: 40,
|
|
194
|
+
});
|
|
195
|
+
TestUtils.Simulate.keyDown(input, {
|
|
196
|
+
key: 'Down',
|
|
197
|
+
keyCode: 40,
|
|
198
|
+
which: 40,
|
|
199
|
+
});
|
|
200
|
+
TestUtils.Simulate.keyDown(input, {
|
|
201
|
+
key: 'Enter',
|
|
202
|
+
keyCode: 13,
|
|
203
|
+
which: 13,
|
|
204
|
+
});
|
|
205
|
+
const selected = lookup
|
|
206
|
+
.getElementsByTagName('a')[0]
|
|
207
|
+
.getElementsByClassName('slds-pill__label')[0].textContent;
|
|
208
|
+
expect(selected).to.equal('Paper St. Soap Company');
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('with header: selects correct item', () => {
|
|
212
|
+
const lookup = generateLookup(getLookupWithHeader());
|
|
213
|
+
const input = lookup.getElementsByTagName('input')[0];
|
|
214
|
+
TestUtils.Simulate.click(input);
|
|
215
|
+
TestUtils.Simulate.keyDown(input, {
|
|
216
|
+
key: 'Down',
|
|
217
|
+
keyCode: 40,
|
|
218
|
+
which: 40,
|
|
219
|
+
});
|
|
220
|
+
TestUtils.Simulate.keyDown(input, {
|
|
221
|
+
key: 'Down',
|
|
222
|
+
keyCode: 40,
|
|
223
|
+
which: 40,
|
|
224
|
+
});
|
|
225
|
+
TestUtils.Simulate.keyDown(input, {
|
|
226
|
+
key: 'Down',
|
|
227
|
+
keyCode: 40,
|
|
228
|
+
which: 40,
|
|
229
|
+
});
|
|
230
|
+
TestUtils.Simulate.keyDown(input, {
|
|
231
|
+
key: 'Enter',
|
|
232
|
+
keyCode: 13,
|
|
233
|
+
which: 13,
|
|
234
|
+
});
|
|
235
|
+
const selected = lookup
|
|
236
|
+
.getElementsByTagName('a')[0]
|
|
237
|
+
.getElementsByClassName('slds-pill__label')[0].textContent;
|
|
238
|
+
expect(selected).to.equal('Tyrell Corp');
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('closes lookup menu on esc', () => {
|
|
242
|
+
const lookup = generateLookup(getLookup());
|
|
243
|
+
const input = lookup.getElementsByTagName('input')[0];
|
|
244
|
+
TestUtils.Simulate.click(input);
|
|
245
|
+
TestUtils.Simulate.keyDown(input, {
|
|
246
|
+
key: 'Down',
|
|
247
|
+
keyCode: 40,
|
|
248
|
+
which: 40,
|
|
249
|
+
});
|
|
250
|
+
TestUtils.Simulate.keyDown(input, { key: 'Esc', keyCode: 27, which: 27 });
|
|
251
|
+
const ariaExpanded = input.getAttribute('aria-expanded');
|
|
252
|
+
expect(ariaExpanded).to.equal('false');
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('aria-expanded is false after selecting item', () => {
|
|
256
|
+
const lookup = generateLookup(getLookup());
|
|
257
|
+
const input = lookup.getElementsByTagName('input')[0];
|
|
258
|
+
TestUtils.Simulate.click(input);
|
|
259
|
+
TestUtils.Simulate.keyDown(input, {
|
|
260
|
+
key: 'Down',
|
|
261
|
+
keyCode: 40,
|
|
262
|
+
which: 40,
|
|
263
|
+
});
|
|
264
|
+
TestUtils.Simulate.keyDown(input, {
|
|
265
|
+
key: 'Enter',
|
|
266
|
+
keyCode: 13,
|
|
267
|
+
which: 13,
|
|
268
|
+
});
|
|
269
|
+
const menu = lookup.getElementsByTagName('ul');
|
|
270
|
+
expect(menu.length).to.equal(0);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('focusedItem has correct style', () => {
|
|
274
|
+
const lookup = generateLookup(getLookup());
|
|
275
|
+
const input = lookup.getElementsByTagName('input')[0];
|
|
276
|
+
TestUtils.Simulate.click(input);
|
|
277
|
+
TestUtils.Simulate.keyDown(input, {
|
|
278
|
+
key: 'Down',
|
|
279
|
+
keyCode: 40,
|
|
280
|
+
which: 40,
|
|
281
|
+
});
|
|
282
|
+
const focusedItem = lookup
|
|
283
|
+
.getElementsByTagName('ul')[0]
|
|
284
|
+
.getElementsByTagName('li')[0];
|
|
285
|
+
expect(focusedItem.className).to.have.string('slds-theme_shade');
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it('isOpen=false prevents dropdown from opening', () => {
|
|
289
|
+
const lookup = generateLookup(getLookup({ isOpen: false }));
|
|
290
|
+
const input = lookup.getElementsByTagName('input')[0];
|
|
291
|
+
expect(input.getAttribute('aria-expanded')).to.equal('false');
|
|
292
|
+
Simulate.click(input);
|
|
293
|
+
expect(input.getAttribute('aria-expanded')).to.equal('false');
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
describe('expanded', () => {
|
|
298
|
+
let lookup;
|
|
299
|
+
let input;
|
|
300
|
+
|
|
301
|
+
beforeEach(() => {
|
|
302
|
+
lookup = generateLookup(getLookup());
|
|
303
|
+
input = lookup.getElementsByTagName('input')[0];
|
|
304
|
+
Simulate.click(input);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('filters its items', () => {
|
|
308
|
+
Simulate.change(input, { target: { value: 'Pa' } });
|
|
309
|
+
expect(getItems(lookup).length).to.equal(3);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('filters its items all the way!', () => {
|
|
313
|
+
Simulate.change(input, { target: { value: 'Poof!' } });
|
|
314
|
+
expect(getItems(lookup).length).to.equal(1); // 1 cause of add-item
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it('unfilters its items if no val', () => {
|
|
318
|
+
Simulate.change(input, { target: { value: '' } });
|
|
319
|
+
expect(getItems(lookup).length).to.equal(7);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it('displays no items when item count is 0', () => {
|
|
323
|
+
expect(
|
|
324
|
+
lookup.getElementsByClassName('slds-lookup__message').length
|
|
325
|
+
).to.equal(0);
|
|
326
|
+
Simulate.change(input, { target: { value: 'kdjfksjdf' } });
|
|
327
|
+
expect(getItems(lookup).length).to.equal(1); // add item
|
|
328
|
+
expect(
|
|
329
|
+
lookup.getElementsByClassName('slds-lookup__message').length
|
|
330
|
+
).to.equal(1);
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
describe('custom filter', () => {
|
|
335
|
+
let lookup;
|
|
336
|
+
let input;
|
|
337
|
+
|
|
338
|
+
beforeEach(() => {
|
|
339
|
+
lookup = generateLookup(
|
|
340
|
+
getLookup({ filterWith: (text, i) => text === i.label[0] })
|
|
341
|
+
);
|
|
342
|
+
input = lookup.getElementsByTagName('input')[0];
|
|
343
|
+
Simulate.click(input);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it('filters its items by case sensitive first letter', () => {
|
|
347
|
+
Simulate.change(input, { target: { value: 'P' } });
|
|
348
|
+
expect(getItems(lookup).length).to.equal(3);
|
|
349
|
+
Simulate.change(input, { target: { value: 'p' } });
|
|
350
|
+
expect(getItems(lookup).length).to.equal(1);
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import chai, { expect } from 'chai';
|
|
3
|
+
import chaiEnzyme from 'chai-enzyme';
|
|
4
|
+
// `this.wrapper` and `this.dom` is set in the helpers file
|
|
5
|
+
import {
|
|
6
|
+
mountComponent,
|
|
7
|
+
unmountComponent,
|
|
8
|
+
} from '../../../tests/enzyme-helpers';
|
|
9
|
+
|
|
10
|
+
import MediaObject from '../../media-object';
|
|
11
|
+
import Icon from '../../icon';
|
|
12
|
+
import IconSettings from '../../icon-settings';
|
|
13
|
+
|
|
14
|
+
import { MEDIA_OBJECT } from '../../../utilities/constants';
|
|
15
|
+
|
|
16
|
+
chai.use(chaiEnzyme());
|
|
17
|
+
|
|
18
|
+
const COMPONENT_CSS_CLASSES = {
|
|
19
|
+
base: 'slds-media',
|
|
20
|
+
figure: 'slds-media__figure',
|
|
21
|
+
body: 'slds-media__body',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const DemoComponent = (props) => (
|
|
25
|
+
<IconSettings iconPath="/assets/icons">
|
|
26
|
+
<MediaObject {...props} />
|
|
27
|
+
</IconSettings>
|
|
28
|
+
);
|
|
29
|
+
DemoComponent.displayName = 'DemoMediaObject';
|
|
30
|
+
|
|
31
|
+
describe(`${MEDIA_OBJECT}: `, () => {
|
|
32
|
+
/*
|
|
33
|
+
Tests
|
|
34
|
+
*/
|
|
35
|
+
describe('Default Structure and CSS', () => {
|
|
36
|
+
beforeEach(
|
|
37
|
+
mountComponent(
|
|
38
|
+
<DemoComponent
|
|
39
|
+
body="Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugiat minus molestias reprehenderit consequuntur sapiente. Modi veritatis totam accusantium numquam assumenda. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugiat minus molestias reprehenderit consequuntur sapiente. Modi veritatis totam accusantium numquam assumenda."
|
|
40
|
+
className="this-is-a-container-test"
|
|
41
|
+
figure={<Icon category="standard" name="user" size="medium" />}
|
|
42
|
+
/>
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
afterEach(unmountComponent);
|
|
47
|
+
|
|
48
|
+
it('has container class, body and figure', function () {
|
|
49
|
+
const container = this.wrapper.find(`.${COMPONENT_CSS_CLASSES.base}`);
|
|
50
|
+
expect(container.hasClass('this-is-a-container-test')).to.be.true;
|
|
51
|
+
|
|
52
|
+
const body = this.wrapper.find(`.${COMPONENT_CSS_CLASSES.body}`);
|
|
53
|
+
const bodyText = body.text();
|
|
54
|
+
expect(bodyText).to.equal(
|
|
55
|
+
'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugiat minus molestias reprehenderit consequuntur sapiente. Modi veritatis totam accusantium numquam assumenda. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugiat minus molestias reprehenderit consequuntur sapiente. Modi veritatis totam accusantium numquam assumenda.'
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const figure = this.wrapper.find(`.${COMPONENT_CSS_CLASSES.figure}`);
|
|
59
|
+
const icon = figure.find('.slds-icon-standard-user');
|
|
60
|
+
expect(icon.hasClass('slds-icon-standard-user')).to.be.true;
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('Additional Structure', () => {
|
|
65
|
+
beforeEach(
|
|
66
|
+
mountComponent(
|
|
67
|
+
<DemoComponent
|
|
68
|
+
figure={<Icon category="standard" name="user" size="medium" />}
|
|
69
|
+
verticalCenter
|
|
70
|
+
canTruncate
|
|
71
|
+
/>
|
|
72
|
+
)
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
afterEach(unmountComponent);
|
|
76
|
+
|
|
77
|
+
it('has media vertical center class', function () {
|
|
78
|
+
const container = this.wrapper.find(`.${COMPONENT_CSS_CLASSES.base}`);
|
|
79
|
+
expect(container.hasClass('slds-media_center')).to.be.true;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('can truncate within Flexbox layout', function () {
|
|
83
|
+
const container = this.wrapper.find(`.${COMPONENT_CSS_CLASSES.base}`);
|
|
84
|
+
expect(container.hasClass('slds-has-flexi-truncate')).to.be.true;
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|