pebble-web 2.25.2 → 2.26.1-alpha.0

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 (94) hide show
  1. package/dist/components/typings/Button.d.ts +1 -0
  2. package/dist/components/typings/Calendar.d.ts +1 -0
  3. package/dist/components/typings/CheckboxGroup.d.ts +1 -0
  4. package/dist/components/typings/Control.d.ts +1 -0
  5. package/dist/components/typings/DateInput.d.ts +1 -0
  6. package/dist/components/typings/Dropdown.d.ts +1 -0
  7. package/dist/components/typings/Input.d.ts +1 -0
  8. package/dist/components/typings/Loader.d.ts +1 -0
  9. package/dist/components/typings/Message.d.ts +1 -0
  10. package/dist/components/typings/OptionGroup.d.ts +1 -0
  11. package/dist/components/typings/OptionGroupCheckBox.d.ts +1 -0
  12. package/dist/components/typings/OptionGroupRadio.d.ts +1 -0
  13. package/dist/components/typings/PhoneNumberInput.d.ts +1 -0
  14. package/dist/components/typings/PopUp.d.ts +1 -0
  15. package/dist/components/typings/RadioGroup.d.ts +1 -0
  16. package/dist/components/typings/Search.d.ts +1 -0
  17. package/dist/components/typings/SecondaryInput.d.ts +1 -0
  18. package/dist/components/typings/Select.d.ts +1 -0
  19. package/dist/components/typings/Text.d.ts +1 -0
  20. package/dist/components/typings/Typeahead.d.ts +1 -0
  21. package/dist/index.d.ts +1 -0
  22. package/dist/pebble-web.dev.js +358 -164
  23. package/dist/pebble-web.dev.js.map +1 -1
  24. package/dist/pebble-web.es.dev.js +239 -70
  25. package/dist/pebble-web.es.dev.js.map +1 -1
  26. package/dist/pebble-web.es.js +233 -64
  27. package/dist/pebble-web.es.js.map +1 -1
  28. package/dist/pebble-web.js +352 -158
  29. package/dist/pebble-web.js.map +1 -1
  30. package/dist/pebble-web.module.dev.js +347 -165
  31. package/dist/pebble-web.module.dev.js.map +1 -1
  32. package/dist/pebble-web.module.js +341 -159
  33. package/dist/pebble-web.module.js.map +1 -1
  34. package/dist/pebble-web.umd.dev.js +360 -166
  35. package/dist/pebble-web.umd.dev.js.map +1 -1
  36. package/dist/pebble-web.umd.js +354 -160
  37. package/dist/pebble-web.umd.js.map +1 -1
  38. package/dist/utils/index.d.ts +1 -0
  39. package/dist/utils/testIds.d.ts +65 -0
  40. package/package.json +3 -2
  41. package/src/components/Button.tsx +3 -1
  42. package/src/components/Calendar.tsx +28 -4
  43. package/src/components/CheckboxGroup.tsx +13 -3
  44. package/src/components/DateInput.tsx +3 -1
  45. package/src/components/DropDown.tsx +3 -1
  46. package/src/components/Input.tsx +15 -3
  47. package/src/components/Loader.tsx +3 -1
  48. package/src/components/Message.tsx +3 -1
  49. package/src/components/NativeDateInput.tsx +2 -1
  50. package/src/components/OptionGroupCheckBox.tsx +14 -2
  51. package/src/components/PhoneNumberInput.tsx +7 -1
  52. package/src/components/PopUp.tsx +7 -1
  53. package/src/components/RadioGroup.tsx +20 -3
  54. package/src/components/Search.tsx +3 -1
  55. package/src/components/SecondaryInput.tsx +9 -2
  56. package/src/components/Select.tsx +13 -1
  57. package/src/components/Tabs.tsx +1 -1
  58. package/src/components/Text.tsx +7 -2
  59. package/src/components/TimePicker.tsx +2 -2
  60. package/src/components/Toast.tsx +2 -2
  61. package/src/components/TypeAhead.tsx +14 -3
  62. package/src/components/__tests__/__snapshots__/checkboxGroup.test.tsx.snap +88 -0
  63. package/src/components/__tests__/__snapshots__/optionGroup.test.tsx.snap +0 -3
  64. package/src/components/__tests__/__snapshots__/select.test.tsx.snap +3 -0
  65. package/src/components/__tests__/__snapshots__/timepicker.test.tsx.snap +18 -18
  66. package/src/components/__tests__/calendar.test.tsx +6 -24
  67. package/src/components/__tests__/checkboxGroup.test.tsx +39 -8
  68. package/src/components/__tests__/select.test.tsx +19 -30
  69. package/src/components/__tests__/timepicker.test.tsx +4 -14
  70. package/src/components/shared/Control.tsx +3 -1
  71. package/src/components/shared/OptionGroup.tsx +23 -5
  72. package/src/components/typings/Button.ts +1 -0
  73. package/src/components/typings/Calendar.ts +1 -0
  74. package/src/components/typings/CheckboxGroup.ts +1 -0
  75. package/src/components/typings/Control.ts +1 -0
  76. package/src/components/typings/DateInput.ts +1 -0
  77. package/src/components/typings/Dropdown.ts +1 -0
  78. package/src/components/typings/Input.ts +1 -0
  79. package/src/components/typings/Loader.ts +1 -0
  80. package/src/components/typings/Message.ts +1 -0
  81. package/src/components/typings/OptionGroup.ts +1 -0
  82. package/src/components/typings/OptionGroupCheckBox.ts +1 -0
  83. package/src/components/typings/OptionGroupRadio.ts +1 -0
  84. package/src/components/typings/PhoneNumberInput.ts +1 -0
  85. package/src/components/typings/PopUp.ts +1 -0
  86. package/src/components/typings/RadioGroup.ts +1 -0
  87. package/src/components/typings/Search.ts +1 -0
  88. package/src/components/typings/SecondaryInput.ts +1 -0
  89. package/src/components/typings/Select.ts +1 -0
  90. package/src/components/typings/Text.ts +1 -0
  91. package/src/components/typings/Typeahead.ts +1 -0
  92. package/src/index.ts +1 -0
  93. package/src/utils/index.ts +1 -0
  94. package/src/utils/testIds.ts +119 -0
@@ -78,7 +78,7 @@ const TimePicker: React.FunctionComponent<TimePickerProps> = props => {
78
78
  toggleDropdown();
79
79
  }}
80
80
  className={buttonStyle}
81
- data-test-id="hour-label"
81
+ data-testid="hour-label"
82
82
  >
83
83
  <span className={css({ marginRight: "15px" })}>
84
84
  {selectedHour !== undefined
@@ -128,7 +128,7 @@ const TimePicker: React.FunctionComponent<TimePickerProps> = props => {
128
128
  toggleDropdown();
129
129
  }}
130
130
  className={buttonStyle}
131
- data-test-id="minute-label"
131
+ data-testid="minute-label"
132
132
  >
133
133
  <span className={css({ marginRight: "15px" })}>
134
134
  {selectedMinute !== undefined
@@ -124,12 +124,12 @@ class Toast extends React.PureComponent<ToastProps, ToastState> {
124
124
  };
125
125
 
126
126
  componentDidMount() {
127
- emitter.on<EventType>("showToast", this.show);
127
+ emitter.on<EventType>("showToast", e => e && this.show(e));
128
128
  emitter.on<EventType>("hideToast", this.hide);
129
129
  }
130
130
 
131
131
  componentWillUnmount() {
132
- emitter.off<EventType>("showToast", this.show);
132
+ emitter.off<EventType>("showToast", e => e && this.show(e));
133
133
  emitter.off("hideToast", this.hide);
134
134
  }
135
135
 
@@ -12,6 +12,7 @@ import OutsideClick from "./OutsideClick";
12
12
  import OptionGroupRadio from "./OptionGroupRadio";
13
13
  import { animated } from "react-spring/renderprops.cjs";
14
14
  import MountTransition from "./shared/MountTransition";
15
+ import { getTestIds, getTypeaheadTestIds } from "../utils/testIds";
15
16
 
16
17
  function defaultSearchBox<OptionType>(
17
18
  { registerChange, onFocus, value }: SearchBoxArgs,
@@ -44,6 +45,7 @@ function defaultSearchBox<OptionType>(
44
45
  loading={props.loading}
45
46
  required={props.required}
46
47
  disabled={props.disabled}
48
+ testId={props.testId}
47
49
  />
48
50
  );
49
51
  }
@@ -97,9 +99,12 @@ export default class TypeAhead<OptionType> extends React.PureComponent<
97
99
  className,
98
100
  searchBox = defaultSearchBox,
99
101
  dropdownClassName,
100
- children
102
+ children,
103
+ testId
101
104
  } = this.props;
102
105
 
106
+ const testIds = getTestIds(testId, getTypeaheadTestIds);
107
+
103
108
  const { showSuggestions, value } = this.state;
104
109
 
105
110
  return (
@@ -118,7 +123,10 @@ export default class TypeAhead<OptionType> extends React.PureComponent<
118
123
  onFocus: this.onFocus,
119
124
  value
120
125
  },
121
- this.props
126
+ {
127
+ ...this.props,
128
+ testId: testIds.searchBoxId
129
+ }
122
130
  )}
123
131
 
124
132
  <MountTransition visible={showSuggestions} native>
@@ -127,7 +135,10 @@ export default class TypeAhead<OptionType> extends React.PureComponent<
127
135
  style={transitionStyles}
128
136
  className={cx(optionsWrapper, dropdownClassName)}
129
137
  >
130
- <OptionGroupRadio onChange={this.onSelect}>
138
+ <OptionGroupRadio
139
+ onChange={this.onSelect}
140
+ testId={testIds.optionGroupId}
141
+ >
131
142
  {children}
132
143
  </OptionGroupRadio>
133
144
  </animated.div>
@@ -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
+ `;
@@ -81,7 +81,6 @@ exports[`Component: OptionGroup default snapshot 1`] = `
81
81
 
82
82
  <div
83
83
  className="emotion-24"
84
- data-test-id="optiongroup"
85
84
  role="radiogroup"
86
85
  style={
87
86
  Object {
@@ -715,7 +714,6 @@ Array [
715
714
  <div
716
715
  aria-label="Search"
717
716
  className="emotion-36"
718
- data-test-id="optiongroup"
719
717
  role="group"
720
718
  style={
721
719
  Object {
@@ -1380,7 +1378,6 @@ Array [
1380
1378
  <div
1381
1379
  aria-label="Search"
1382
1380
  className="emotion-24"
1383
- data-test-id="optiongroup"
1384
1381
  role="radiogroup"
1385
1382
  style={
1386
1383
  Object {
@@ -172,6 +172,7 @@ exports[`Component: Select multi-select: snapshot 1`] = `
172
172
  >
173
173
  <div
174
174
  className="emotion-6"
175
+ data-testid="test-multi-select-input"
175
176
  onClick={[Function]}
176
177
  >
177
178
  <div
@@ -386,6 +387,7 @@ exports[`Component: Select single-select with searchbox: snapshot 1`] = `
386
387
  >
387
388
  <div
388
389
  className="emotion-6"
390
+ data-testid="test-single-select-input"
389
391
  onClick={[Function]}
390
392
  >
391
393
  <div
@@ -600,6 +602,7 @@ exports[`Component: Select single-select: snapshot 1`] = `
600
602
  >
601
603
  <div
602
604
  className="emotion-6"
605
+ data-testid="test-single-select-input"
603
606
  onClick={[Function]}
604
607
  >
605
608
  <div
@@ -70,7 +70,7 @@ exports[`TimePicker { selectedHour: 1, selectedMinute: 0 } 1`] = `
70
70
  >
71
71
  <div
72
72
  className="emotion-2"
73
- data-test-id="hour-label"
73
+ data-testid="hour-label"
74
74
  onClick={[Function]}
75
75
  >
76
76
  <span
@@ -109,7 +109,7 @@ exports[`TimePicker { selectedHour: 1, selectedMinute: 0 } 1`] = `
109
109
  >
110
110
  <div
111
111
  className="emotion-2"
112
- data-test-id="minute-label"
112
+ data-testid="minute-label"
113
113
  onClick={[Function]}
114
114
  >
115
115
  <span
@@ -201,7 +201,7 @@ exports[`TimePicker { selectedHour: 1, selectedMinute: 15 } 1`] = `
201
201
  >
202
202
  <div
203
203
  className="emotion-2"
204
- data-test-id="hour-label"
204
+ data-testid="hour-label"
205
205
  onClick={[Function]}
206
206
  >
207
207
  <span
@@ -240,7 +240,7 @@ exports[`TimePicker { selectedHour: 1, selectedMinute: 15 } 1`] = `
240
240
  >
241
241
  <div
242
242
  className="emotion-2"
243
- data-test-id="minute-label"
243
+ data-testid="minute-label"
244
244
  onClick={[Function]}
245
245
  >
246
246
  <span
@@ -332,7 +332,7 @@ exports[`TimePicker { selectedHour: 1, selectedMinute: undefined } 1`] = `
332
332
  >
333
333
  <div
334
334
  className="emotion-2"
335
- data-test-id="hour-label"
335
+ data-testid="hour-label"
336
336
  onClick={[Function]}
337
337
  >
338
338
  <span
@@ -371,7 +371,7 @@ exports[`TimePicker { selectedHour: 1, selectedMinute: undefined } 1`] = `
371
371
  >
372
372
  <div
373
373
  className="emotion-2"
374
- data-test-id="minute-label"
374
+ data-testid="minute-label"
375
375
  onClick={[Function]}
376
376
  >
377
377
  <span
@@ -463,7 +463,7 @@ exports[`TimePicker { selectedHour: 12, selectedMinute: 0 } 1`] = `
463
463
  >
464
464
  <div
465
465
  className="emotion-2"
466
- data-test-id="hour-label"
466
+ data-testid="hour-label"
467
467
  onClick={[Function]}
468
468
  >
469
469
  <span
@@ -502,7 +502,7 @@ exports[`TimePicker { selectedHour: 12, selectedMinute: 0 } 1`] = `
502
502
  >
503
503
  <div
504
504
  className="emotion-2"
505
- data-test-id="minute-label"
505
+ data-testid="minute-label"
506
506
  onClick={[Function]}
507
507
  >
508
508
  <span
@@ -594,7 +594,7 @@ exports[`TimePicker { selectedHour: 12, selectedMinute: 15 } 1`] = `
594
594
  >
595
595
  <div
596
596
  className="emotion-2"
597
- data-test-id="hour-label"
597
+ data-testid="hour-label"
598
598
  onClick={[Function]}
599
599
  >
600
600
  <span
@@ -633,7 +633,7 @@ exports[`TimePicker { selectedHour: 12, selectedMinute: 15 } 1`] = `
633
633
  >
634
634
  <div
635
635
  className="emotion-2"
636
- data-test-id="minute-label"
636
+ data-testid="minute-label"
637
637
  onClick={[Function]}
638
638
  >
639
639
  <span
@@ -725,7 +725,7 @@ exports[`TimePicker { selectedHour: 12, selectedMinute: undefined } 1`] = `
725
725
  >
726
726
  <div
727
727
  className="emotion-2"
728
- data-test-id="hour-label"
728
+ data-testid="hour-label"
729
729
  onClick={[Function]}
730
730
  >
731
731
  <span
@@ -764,7 +764,7 @@ exports[`TimePicker { selectedHour: 12, selectedMinute: undefined } 1`] = `
764
764
  >
765
765
  <div
766
766
  className="emotion-2"
767
- data-test-id="minute-label"
767
+ data-testid="minute-label"
768
768
  onClick={[Function]}
769
769
  >
770
770
  <span
@@ -856,7 +856,7 @@ exports[`TimePicker { selectedHour: undefined, selectedMinute: 0 } 1`] = `
856
856
  >
857
857
  <div
858
858
  className="emotion-2"
859
- data-test-id="hour-label"
859
+ data-testid="hour-label"
860
860
  onClick={[Function]}
861
861
  >
862
862
  <span
@@ -895,7 +895,7 @@ exports[`TimePicker { selectedHour: undefined, selectedMinute: 0 } 1`] = `
895
895
  >
896
896
  <div
897
897
  className="emotion-2"
898
- data-test-id="minute-label"
898
+ data-testid="minute-label"
899
899
  onClick={[Function]}
900
900
  >
901
901
  <span
@@ -987,7 +987,7 @@ exports[`TimePicker { selectedHour: undefined, selectedMinute: 15 } 1`] = `
987
987
  >
988
988
  <div
989
989
  className="emotion-2"
990
- data-test-id="hour-label"
990
+ data-testid="hour-label"
991
991
  onClick={[Function]}
992
992
  >
993
993
  <span
@@ -1026,7 +1026,7 @@ exports[`TimePicker { selectedHour: undefined, selectedMinute: 15 } 1`] = `
1026
1026
  >
1027
1027
  <div
1028
1028
  className="emotion-2"
1029
- data-test-id="minute-label"
1029
+ data-testid="minute-label"
1030
1030
  onClick={[Function]}
1031
1031
  >
1032
1032
  <span
@@ -1117,7 +1117,7 @@ exports[`TimePicker { selectedHour: undefined, selectedMinute: undefined } 1`] =
1117
1117
  >
1118
1118
  <div
1119
1119
  className="emotion-2"
1120
- data-test-id="hour-label"
1120
+ data-testid="hour-label"
1121
1121
  onClick={[Function]}
1122
1122
  >
1123
1123
  <span
@@ -1156,7 +1156,7 @@ exports[`TimePicker { selectedHour: undefined, selectedMinute: undefined } 1`] =
1156
1156
  >
1157
1157
  <div
1158
1158
  className="emotion-2"
1159
- data-test-id="minute-label"
1159
+ data-testid="minute-label"
1160
1160
  onClick={[Function]}
1161
1161
  >
1162
1162
  <span
@@ -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
  });
@@ -9,6 +9,7 @@ import Button from "../Button";
9
9
  import Input from "../Input";
10
10
  import Search from "../Search";
11
11
  import "../../../tests/__setup__/matchers";
12
+ import { getSelectInputTestIds } from "../../utils/testIds";
12
13
 
13
14
  const options = new Array(5)
14
15
  .fill(1)
@@ -18,6 +19,9 @@ const options = new Array(5)
18
19
 
19
20
  const noop = () => {};
20
21
 
22
+ const SINGLE_SELECT_TEST_ID = "test-single-select";
23
+ const MULTI_SELECT_TEST_ID = "test-multi-select";
24
+
21
25
  function getComponent(
22
26
  spy = noop,
23
27
  props: Partial<SingleSelectProps<string>> = {}
@@ -28,6 +32,7 @@ function getComponent(
28
32
  placeholder="Choose Option"
29
33
  selected={"option-2"}
30
34
  {...props}
35
+ testId={SINGLE_SELECT_TEST_ID}
31
36
  >
32
37
  {options}
33
38
  </Select>
@@ -44,6 +49,7 @@ function getMultiSelectComponent<T>(
44
49
  placeholder="Choose Option"
45
50
  multiSelect
46
51
  {...props}
52
+ testId={MULTI_SELECT_TEST_ID}
47
53
  >
48
54
  {options}
49
55
  </Select>
@@ -96,18 +102,17 @@ describe("Component: Select", () => {
96
102
  const spy = sinon.spy();
97
103
  const select = mount(getComponent(spy));
98
104
  select.find(Input).simulate("click");
99
- select
100
- .find(Option)
101
- .at(2)
102
- .simulate("click");
105
+ select.find(Option).at(2).simulate("click");
103
106
 
104
107
  expect(spy.calledWith("option-3")).toBeTruthy();
105
108
 
106
109
  // wait for the dropdown animation to get over.
107
110
  clock.tick(1000);
108
111
 
112
+ const { optionGroupId } = getSelectInputTestIds(SINGLE_SELECT_TEST_ID);
113
+
109
114
  // This means that Option is no more rendered in DOM.
110
- expect(select).toNotBeInDOM("[data-test-id='optiongroup']");
115
+ expect(select).toNotBeInDOM(`[data-testid='${optionGroupId}']`);
111
116
  });
112
117
 
113
118
  test("multi select: should trigger onChange with correct onChange", () => {
@@ -124,10 +129,7 @@ describe("Component: Select", () => {
124
129
  })
125
130
  );
126
131
  select.find(Input).simulate("click");
127
- select
128
- .find(Option)
129
- .at(2)
130
- .simulate("click");
132
+ select.find(Option).at(2).simulate("click");
131
133
 
132
134
  expect(spy.calledWith(["option-3"])).toBeTruthy();
133
135
 
@@ -135,10 +137,7 @@ describe("Component: Select", () => {
135
137
  selected: ["option-3"]
136
138
  });
137
139
 
138
- select
139
- .find(Option)
140
- .at(3)
141
- .simulate("click");
140
+ select.find(Option).at(3).simulate("click");
142
141
 
143
142
  expect(spy.calledWith(["option-3", "option-4"])).toBeTruthy();
144
143
 
@@ -146,20 +145,14 @@ describe("Component: Select", () => {
146
145
  selected: ["option-3", "option-4"]
147
146
  });
148
147
 
149
- select
150
- .find(Option)
151
- .at(2)
152
- .simulate("click");
148
+ select.find(Option).at(2).simulate("click");
153
149
 
154
150
  expect(spy.calledWith(["option-4"])).toBeTruthy();
155
151
 
156
152
  expect(select.find(Button)).toHaveLength(2);
157
153
 
158
154
  // test onClear
159
- select
160
- .find(Button)
161
- .at(0)
162
- .simulate("click");
155
+ select.find(Button).at(0).simulate("click");
163
156
  expect(clearSpy.calledOnce).toBeTruthy();
164
157
 
165
158
  // Reopen dropdown and test onApply
@@ -168,16 +161,15 @@ describe("Component: Select", () => {
168
161
  selected: ["option-3"]
169
162
  });
170
163
 
171
- select
172
- .find(Button)
173
- .at(1)
174
- .simulate("click");
164
+ select.find(Button).at(1).simulate("click");
175
165
  expect(applySpy.calledWith(["option-3"])).toBeTruthy();
176
166
 
177
167
  clock.tick(1000);
178
168
 
169
+ const { optionGroupId } = getSelectInputTestIds(MULTI_SELECT_TEST_ID, true);
170
+
179
171
  // ensure the dropdown is closed
180
- expect(select).toNotBeInDOM("[data-test-id='optiongroup']");
172
+ expect(select).toNotBeInDOM(`[data-testid='${optionGroupId}']`);
181
173
  });
182
174
 
183
175
  test("single select: query change triggers onChange", () => {
@@ -222,10 +214,7 @@ describe("Component: Select", () => {
222
214
  );
223
215
  select.find(Input).simulate("click");
224
216
 
225
- select
226
- .find(Search)
227
- .find(".pi-close")
228
- .simulate("click");
217
+ select.find(Search).find(".pi-close").simulate("click");
229
218
  expect(clearQuerySpy.calledWith("")).toBeTruthy();
230
219
  });
231
220
 
@@ -36,30 +36,20 @@ describe("TimePicker: functionality test", () => {
36
36
  const timePicker = mount(
37
37
  <TimePicker onHourChange={spyHour} onMinuteChange={spyMinute} />
38
38
  );
39
- timePicker.find("[data-test-id='hour-label']").simulate("click");
39
+ timePicker.find("[data-testid='hour-label']").simulate("click");
40
40
 
41
41
  clock.tick(10000);
42
42
 
43
- timePicker
44
- .find(DropDown)
45
- .at(0)
46
- .find(Option)
47
- .at(0)
48
- .simulate("click");
43
+ timePicker.find(DropDown).at(0).find(Option).at(0).simulate("click");
49
44
 
50
45
  expect(spyHour.calledOnce).toBeTruthy();
51
46
  expect(spyHour.calledWith(1)).toBeTruthy();
52
47
 
53
- timePicker.find("[data-test-id='minute-label']").simulate("click");
48
+ timePicker.find("[data-testid='minute-label']").simulate("click");
54
49
 
55
50
  clock.tick(10000);
56
51
 
57
- timePicker
58
- .find(DropDown)
59
- .at(1)
60
- .find(Option)
61
- .at(0)
62
- .simulate("click");
52
+ timePicker.find(DropDown).at(1).find(Option).at(0).simulate("click");
63
53
 
64
54
  expect(spyMinute.calledOnce).toBeTruthy();
65
55
  expect(spyMinute.calledWith(0)).toBeTruthy();