pebble-web 2.25.2-alpha.0 → 2.25.2-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/dist/components/typings/Calendar.d.ts +1 -0
- package/dist/components/typings/CheckboxGroup.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/pebble-web.dev.js +141 -100
- package/dist/pebble-web.dev.js.map +1 -1
- package/dist/pebble-web.es.dev.js +91 -62
- package/dist/pebble-web.es.dev.js.map +1 -1
- package/dist/pebble-web.es.js +90 -61
- package/dist/pebble-web.es.js.map +1 -1
- package/dist/pebble-web.js +140 -99
- package/dist/pebble-web.js.map +1 -1
- package/dist/pebble-web.module.dev.js +131 -101
- package/dist/pebble-web.module.dev.js.map +1 -1
- package/dist/pebble-web.module.js +130 -100
- package/dist/pebble-web.module.js.map +1 -1
- package/dist/pebble-web.umd.dev.js +141 -100
- package/dist/pebble-web.umd.dev.js.map +1 -1
- package/dist/pebble-web.umd.js +140 -99
- package/dist/pebble-web.umd.js.map +1 -1
- package/dist/utils/testIds.d.ts +7 -0
- package/package.json +1 -1
- package/src/components/Calendar.tsx +28 -4
- package/src/components/CheckboxGroup.tsx +13 -3
- package/src/components/Input.tsx +2 -0
- package/src/components/SecondaryInput.tsx +2 -0
- package/src/components/__tests__/__snapshots__/checkboxGroup.test.tsx.snap +88 -0
- package/src/components/__tests__/calendar.test.tsx +6 -24
- package/src/components/__tests__/checkboxGroup.test.tsx +39 -8
- package/src/components/typings/Calendar.ts +1 -0
- package/src/components/typings/CheckboxGroup.ts +1 -0
- package/src/index.ts +1 -0
- package/src/utils/testIds.ts +13 -0
package/dist/utils/testIds.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export declare function getPhoneNumberInputTestIds(id: string): {
|
|
|
40
40
|
clearVisibleId: string;
|
|
41
41
|
};
|
|
42
42
|
};
|
|
43
|
+
export declare function getMessageTestId(id: string): string;
|
|
43
44
|
export declare function getSelectInputTestIds(id: string, multiSelect: true): BaseSelectIds & OptionGroupCheckBoxIds;
|
|
44
45
|
export declare function getSelectInputTestIds(id: string, multiSelect?: false): BaseSelectIds & OptionGroupRadioIds;
|
|
45
46
|
export declare function getSelectInputTestIds(id: string, multiSelect?: boolean): (BaseSelectIds & OptionGroupCheckBoxIds) | (BaseSelectIds & OptionGroupRadioIds);
|
|
@@ -50,4 +51,10 @@ export declare function getTypeaheadTestIds(id: string): {
|
|
|
50
51
|
clearVisibleId: string;
|
|
51
52
|
optionGroupId: string;
|
|
52
53
|
};
|
|
54
|
+
export declare function getCalendarTestIds(id: string): {
|
|
55
|
+
leftIconId: string;
|
|
56
|
+
rightIconId: string;
|
|
57
|
+
applyButtonId: string;
|
|
58
|
+
clearButtonId: string;
|
|
59
|
+
};
|
|
53
60
|
export {};
|
package/package.json
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
} from "./styles/Calendar.styles";
|
|
14
14
|
import Button from "./Button";
|
|
15
15
|
import { isSameDay, endOfDay, startOfDay, addDays, subDays } from "date-fns";
|
|
16
|
+
import { getCalendarTestIds, getTestIds } from "../utils/testIds";
|
|
16
17
|
|
|
17
18
|
class Calendar extends React.PureComponent<CalendarProps, CalendarState> {
|
|
18
19
|
static defaultProps: Partial<CalendarProps> = {
|
|
@@ -136,9 +137,16 @@ class Calendar extends React.PureComponent<CalendarProps, CalendarState> {
|
|
|
136
137
|
onClear,
|
|
137
138
|
maxDate,
|
|
138
139
|
minDate,
|
|
140
|
+
testId,
|
|
139
141
|
...rest
|
|
140
142
|
} = this.props;
|
|
141
143
|
const { maxRangeDates } = this.state;
|
|
144
|
+
const {
|
|
145
|
+
leftIconId,
|
|
146
|
+
rightIconId,
|
|
147
|
+
clearButtonId,
|
|
148
|
+
applyButtonId
|
|
149
|
+
} = getTestIds(testId, id => getCalendarTestIds(id));
|
|
142
150
|
|
|
143
151
|
return (
|
|
144
152
|
<div
|
|
@@ -165,10 +173,18 @@ class Calendar extends React.PureComponent<CalendarProps, CalendarState> {
|
|
|
165
173
|
tileDisabled={this.getDisabledDays}
|
|
166
174
|
onClickDay={this.onDayClick}
|
|
167
175
|
prevLabel={
|
|
168
|
-
<i
|
|
176
|
+
<i
|
|
177
|
+
style={{ fontSize: 14 }}
|
|
178
|
+
className="pi pi-chevron-left"
|
|
179
|
+
data-testid={leftIconId}
|
|
180
|
+
/>
|
|
169
181
|
}
|
|
170
182
|
nextLabel={
|
|
171
|
-
<i
|
|
183
|
+
<i
|
|
184
|
+
style={{ fontSize: 14 }}
|
|
185
|
+
className="pi pi-arrow-right"
|
|
186
|
+
data-testid={rightIconId}
|
|
187
|
+
/>
|
|
172
188
|
}
|
|
173
189
|
maxDate={maxDate || (maxRangeDates && maxRangeDates.future)}
|
|
174
190
|
minDate={minDate || (maxRangeDates && maxRangeDates.past)}
|
|
@@ -177,11 +193,19 @@ class Calendar extends React.PureComponent<CalendarProps, CalendarState> {
|
|
|
177
193
|
{(onClear || onApply) && (
|
|
178
194
|
<div className={buttonsWrapper}>
|
|
179
195
|
{onClear && (
|
|
180
|
-
<Button
|
|
196
|
+
<Button
|
|
197
|
+
onClick={this.onClear}
|
|
198
|
+
type="secondary"
|
|
199
|
+
testId={clearButtonId}
|
|
200
|
+
>
|
|
181
201
|
Clear
|
|
182
202
|
</Button>
|
|
183
203
|
)}
|
|
184
|
-
{onApply &&
|
|
204
|
+
{onApply && (
|
|
205
|
+
<Button onClick={this.onApply} testId={applyButtonId}>
|
|
206
|
+
Apply
|
|
207
|
+
</Button>
|
|
208
|
+
)}
|
|
185
209
|
</div>
|
|
186
210
|
)}
|
|
187
211
|
</div>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { CheckboxGroupProps } from "./typings/CheckboxGroup";
|
|
3
3
|
import { CheckboxProps } from "./typings/Checkbox";
|
|
4
|
+
import { getOptionTestId } from "../utils/testIds";
|
|
4
5
|
import { getSelectedCheckboxes } from "./utils/getSelectedCheckboxes";
|
|
5
6
|
|
|
6
7
|
export default class CheckboxGroup<OptionType> extends React.PureComponent<
|
|
@@ -15,9 +16,17 @@ export default class CheckboxGroup<OptionType> extends React.PureComponent<
|
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
render() {
|
|
18
|
-
const {
|
|
19
|
+
const {
|
|
20
|
+
children,
|
|
21
|
+
selected,
|
|
22
|
+
className,
|
|
23
|
+
name,
|
|
24
|
+
disabled,
|
|
25
|
+
testId
|
|
26
|
+
} = this.props;
|
|
19
27
|
|
|
20
|
-
const _children = React.Children.map(children, _checkbox => {
|
|
28
|
+
const _children = React.Children.map(children, (_checkbox, i) => {
|
|
29
|
+
const index = typeof i === "number" ? i : 0;
|
|
21
30
|
// `_checkbox as React.ReactElement<CheckboxProps>` is a hack
|
|
22
31
|
// Because React does not allow us to specify what sort of elements
|
|
23
32
|
// you can allow as children and leaves it on you to figure out
|
|
@@ -28,7 +37,8 @@ export default class CheckboxGroup<OptionType> extends React.PureComponent<
|
|
|
28
37
|
return React.cloneElement(checkbox, {
|
|
29
38
|
onChange: this.handleChange,
|
|
30
39
|
checked: selected.indexOf(checkbox.props.value) >= 0,
|
|
31
|
-
disabled
|
|
40
|
+
disabled,
|
|
41
|
+
testId: testId ? getOptionTestId(testId, index) : undefined
|
|
32
42
|
});
|
|
33
43
|
});
|
|
34
44
|
|
package/src/components/Input.tsx
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
} from "./styles/Input.styles";
|
|
16
16
|
import { colors } from "pebble-shared";
|
|
17
17
|
import Loader from "./Loader";
|
|
18
|
+
import { getMessageTestId } from "../utils/testIds";
|
|
18
19
|
|
|
19
20
|
function getColor(
|
|
20
21
|
error: string | undefined,
|
|
@@ -197,6 +198,7 @@ class Input extends React.PureComponent<InputProps, InputState> {
|
|
|
197
198
|
{_message && (
|
|
198
199
|
<div
|
|
199
200
|
className={messageStyle}
|
|
201
|
+
data-testid={testId ? getMessageTestId(testId) : undefined}
|
|
200
202
|
style={{ color: getColor(errorMessage, successMessage) }}
|
|
201
203
|
>
|
|
202
204
|
{_message}
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
messageStyle,
|
|
13
13
|
placeholderStyle
|
|
14
14
|
} from "./styles/SecondaryInput.styles";
|
|
15
|
+
import { getMessageTestId } from "../utils/testIds";
|
|
15
16
|
import {
|
|
16
17
|
SecondaryInputProps,
|
|
17
18
|
SecondaryInputState
|
|
@@ -139,6 +140,7 @@ export default class SecondaryInput extends React.PureComponent<
|
|
|
139
140
|
{_message && (
|
|
140
141
|
<div
|
|
141
142
|
className={messageStyle}
|
|
143
|
+
data-testid={testId ? getMessageTestId(testId) : undefined}
|
|
142
144
|
style={{ color: getColor(errorMessage, successMessage) }}
|
|
143
145
|
>
|
|
144
146
|
{_message}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`CheckboxGroup snapshot 1`] = `
|
|
4
|
+
.emotion-0 {
|
|
5
|
+
margin-right: 10px;
|
|
6
|
+
font-size: 16px;
|
|
7
|
+
padding-top: 2px;
|
|
8
|
+
height: 18px;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.emotion-1 {
|
|
12
|
+
cursor: pointer;
|
|
13
|
+
display: -webkit-box;
|
|
14
|
+
display: -webkit-flex;
|
|
15
|
+
display: -ms-flexbox;
|
|
16
|
+
display: flex;
|
|
17
|
+
outline: none;
|
|
18
|
+
padding: 10px 0;
|
|
19
|
+
position: relative;
|
|
20
|
+
-webkit-align-items: center;
|
|
21
|
+
-webkit-box-align: center;
|
|
22
|
+
-ms-flex-align: center;
|
|
23
|
+
align-items: center;
|
|
24
|
+
font-weight: 400;
|
|
25
|
+
color: #101721;
|
|
26
|
+
font-size: 14px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.emotion-1[data-disabled='true'] {
|
|
30
|
+
cursor: not-allowed;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.emotion-1[data-disabled='true'] .i {
|
|
34
|
+
color: #E0E0E0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
<div
|
|
38
|
+
aria-label="test"
|
|
39
|
+
role="checkboxgroup"
|
|
40
|
+
>
|
|
41
|
+
<div
|
|
42
|
+
aria-checked={false}
|
|
43
|
+
className="emotion-1"
|
|
44
|
+
data-testid="checkbox-group-0"
|
|
45
|
+
onClick={[Function]}
|
|
46
|
+
role="checkbox"
|
|
47
|
+
tabIndex={-1}
|
|
48
|
+
>
|
|
49
|
+
<div
|
|
50
|
+
className="emotion-0"
|
|
51
|
+
>
|
|
52
|
+
<i
|
|
53
|
+
className="pi pi-checkbox-unselected"
|
|
54
|
+
style={
|
|
55
|
+
Object {
|
|
56
|
+
"color": "#E0E0E0",
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/>
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
I am a checkbox
|
|
63
|
+
</div>
|
|
64
|
+
<div
|
|
65
|
+
aria-checked={true}
|
|
66
|
+
className="emotion-1"
|
|
67
|
+
data-testid="checkbox-group-1"
|
|
68
|
+
onClick={[Function]}
|
|
69
|
+
role="checkbox"
|
|
70
|
+
tabIndex={0}
|
|
71
|
+
>
|
|
72
|
+
<div
|
|
73
|
+
className="emotion-0"
|
|
74
|
+
>
|
|
75
|
+
<i
|
|
76
|
+
className="pi pi-checkbox-selected"
|
|
77
|
+
style={
|
|
78
|
+
Object {
|
|
79
|
+
"color": "#6161FF",
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/>
|
|
83
|
+
</div>
|
|
84
|
+
|
|
85
|
+
I am a checkbox
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
`;
|
|
@@ -22,19 +22,13 @@ describe("Calendar", () => {
|
|
|
22
22
|
selected={date}
|
|
23
23
|
/>
|
|
24
24
|
);
|
|
25
|
-
calendar
|
|
26
|
-
.find(".react-calendar__tile")
|
|
27
|
-
.at(0)
|
|
28
|
-
.simulate("click");
|
|
25
|
+
calendar.find(".react-calendar__tile").at(0).simulate("click");
|
|
29
26
|
|
|
30
27
|
// in case of range selector onChange should only be called once
|
|
31
28
|
// both values of range have been selected.
|
|
32
29
|
expect(changeSpy.calledOnce).toBeFalsy();
|
|
33
30
|
|
|
34
|
-
calendar
|
|
35
|
-
.find(".react-calendar__tile")
|
|
36
|
-
.at(10)
|
|
37
|
-
.simulate("click");
|
|
31
|
+
calendar.find(".react-calendar__tile").at(10).simulate("click");
|
|
38
32
|
|
|
39
33
|
calendar
|
|
40
34
|
.find(".calendar-test > div")
|
|
@@ -74,10 +68,7 @@ describe("Calendar", () => {
|
|
|
74
68
|
/>
|
|
75
69
|
);
|
|
76
70
|
|
|
77
|
-
calendar
|
|
78
|
-
.find(".react-calendar__tile")
|
|
79
|
-
.at(0)
|
|
80
|
-
.simulate("click");
|
|
71
|
+
calendar.find(".react-calendar__tile").at(0).simulate("click");
|
|
81
72
|
|
|
82
73
|
calendar
|
|
83
74
|
.find(".calendar-test > div")
|
|
@@ -107,10 +98,7 @@ describe("Calendar", () => {
|
|
|
107
98
|
selected={date[0]}
|
|
108
99
|
/>
|
|
109
100
|
);
|
|
110
|
-
calendar
|
|
111
|
-
.find(".react-calendar__tile")
|
|
112
|
-
.at(0)
|
|
113
|
-
.simulate("click");
|
|
101
|
+
calendar.find(".react-calendar__tile").at(0).simulate("click");
|
|
114
102
|
|
|
115
103
|
expect(changeSpy.calledOnce).toBeTruthy();
|
|
116
104
|
|
|
@@ -149,15 +137,9 @@ describe("Calendar", () => {
|
|
|
149
137
|
/>
|
|
150
138
|
);
|
|
151
139
|
|
|
152
|
-
calendar
|
|
153
|
-
.find(".react-calendar__tile")
|
|
154
|
-
.at(0)
|
|
155
|
-
.simulate("click");
|
|
140
|
+
calendar.find(".react-calendar__tile").at(0).simulate("click");
|
|
156
141
|
|
|
157
|
-
calendar
|
|
158
|
-
.find(".react-calendar__tile")
|
|
159
|
-
.at(10)
|
|
160
|
-
.simulate("click");
|
|
142
|
+
calendar.find(".react-calendar__tile").at(10).simulate("click");
|
|
161
143
|
|
|
162
144
|
calendar
|
|
163
145
|
.find(".calendar-test > div")
|
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { Checkbox, CheckboxGroup } from "../";
|
|
3
3
|
import { mount } from "enzyme";
|
|
4
|
+
import renderer from "react-test-renderer";
|
|
4
5
|
import sinon from "sinon";
|
|
5
6
|
|
|
6
7
|
describe("CheckboxGroup", () => {
|
|
8
|
+
test("snapshot", () => {
|
|
9
|
+
const spy = sinon.spy();
|
|
10
|
+
const component = renderer.create(
|
|
11
|
+
<CheckboxGroup
|
|
12
|
+
selected={["checkbox-1"]}
|
|
13
|
+
onChange={spy}
|
|
14
|
+
name="test"
|
|
15
|
+
testId="checkbox-group"
|
|
16
|
+
>
|
|
17
|
+
<Checkbox value="checkbox-0" label="I am a checkbox" />
|
|
18
|
+
<Checkbox value="checkbox-1" label="I am a checkbox" />
|
|
19
|
+
</CheckboxGroup>
|
|
20
|
+
);
|
|
21
|
+
const tree = component.toJSON();
|
|
22
|
+
expect(tree).toMatchSnapshot();
|
|
23
|
+
});
|
|
24
|
+
|
|
7
25
|
test("should call onChange on click with correct arguments", () => {
|
|
8
26
|
const spy = sinon.spy();
|
|
9
27
|
|
|
@@ -14,10 +32,7 @@ describe("CheckboxGroup", () => {
|
|
|
14
32
|
</CheckboxGroup>
|
|
15
33
|
);
|
|
16
34
|
|
|
17
|
-
checkbox
|
|
18
|
-
.find(Checkbox)
|
|
19
|
-
.at(1)
|
|
20
|
-
.simulate("click");
|
|
35
|
+
checkbox.find(Checkbox).at(1).simulate("click");
|
|
21
36
|
|
|
22
37
|
expect(spy.calledWith([])).toBeTruthy();
|
|
23
38
|
|
|
@@ -25,11 +40,27 @@ describe("CheckboxGroup", () => {
|
|
|
25
40
|
selected: []
|
|
26
41
|
});
|
|
27
42
|
|
|
28
|
-
checkbox
|
|
29
|
-
.find(Checkbox)
|
|
30
|
-
.at(0)
|
|
31
|
-
.simulate("click");
|
|
43
|
+
checkbox.find(Checkbox).at(0).simulate("click");
|
|
32
44
|
|
|
33
45
|
expect(spy.calledWith(["checkbox-0"])).toBeTruthy();
|
|
34
46
|
});
|
|
47
|
+
|
|
48
|
+
test("should append checkbox test ids for children", () => {
|
|
49
|
+
const spy = sinon.spy();
|
|
50
|
+
|
|
51
|
+
const checkbox = mount(
|
|
52
|
+
<CheckboxGroup
|
|
53
|
+
selected={[]}
|
|
54
|
+
onChange={spy}
|
|
55
|
+
name="test"
|
|
56
|
+
testId="checkbox-group"
|
|
57
|
+
>
|
|
58
|
+
<Checkbox value="checkbox-0" label="I am a checkbox" />
|
|
59
|
+
<Checkbox value="checkbox-1" label="I am a checkbox" />
|
|
60
|
+
</CheckboxGroup>
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
expect(checkbox.find("[data-testid='checkbox-group-0']").length).toBe(1);
|
|
64
|
+
expect(checkbox.find("[data-testid='checkbox-group-1']").length).toBe(1);
|
|
65
|
+
});
|
|
35
66
|
});
|
package/src/index.ts
CHANGED
package/src/utils/testIds.ts
CHANGED
|
@@ -54,6 +54,10 @@ export function getPhoneNumberInputTestIds(id: string) {
|
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
export function getMessageTestId(id: string) {
|
|
58
|
+
return `${id}-message`;
|
|
59
|
+
}
|
|
60
|
+
|
|
57
61
|
export function getSelectInputTestIds(
|
|
58
62
|
id: string,
|
|
59
63
|
multiSelect: true
|
|
@@ -96,3 +100,12 @@ export function getTypeaheadTestIds(id: string) {
|
|
|
96
100
|
...getOptionGroupRadioTestIds(optionGroupId)
|
|
97
101
|
};
|
|
98
102
|
}
|
|
103
|
+
|
|
104
|
+
export function getCalendarTestIds(id: string){
|
|
105
|
+
return {
|
|
106
|
+
leftIconId: `${id}-left-icon`,
|
|
107
|
+
rightIconId: `${id}-right-icon`,
|
|
108
|
+
applyButtonId: `${id}-apply-btn`,
|
|
109
|
+
clearButtonId: `${id}-clear-btn`
|
|
110
|
+
};
|
|
111
|
+
}
|