playbook_ui 11.0.0.pre.alpha.2 → 11.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/pb_background/_background.scss +8 -1
  3. data/app/pb_kits/playbook/pb_background/_background.tsx +9 -1
  4. data/app/pb_kits/playbook/pb_background/background.rb +76 -16
  5. data/app/pb_kits/playbook/pb_background/docs/_background_status.html.erb +14 -2
  6. data/app/pb_kits/playbook/pb_background/docs/_background_status.jsx +43 -2
  7. data/app/pb_kits/playbook/pb_background/docs/_background_status.md +1 -1
  8. data/app/pb_kits/playbook/pb_badge/_badge.tsx +1 -2
  9. data/app/pb_kits/playbook/pb_body/_body.scss +4 -4
  10. data/app/pb_kits/playbook/pb_body/_body.tsx +5 -4
  11. data/app/pb_kits/playbook/pb_body/_body_mixins.scss +7 -3
  12. data/app/pb_kits/playbook/pb_body/body.rb +4 -3
  13. data/app/pb_kits/playbook/pb_body/body.test.js +12 -9
  14. data/app/pb_kits/playbook/pb_body/docs/_body_light.html.erb +4 -4
  15. data/app/pb_kits/playbook/pb_body/docs/_body_light.jsx +4 -4
  16. data/app/pb_kits/playbook/pb_body/docs/_description.md +2 -2
  17. data/app/pb_kits/playbook/pb_body/docs/_footer.md +1 -1
  18. data/app/pb_kits/playbook/pb_button/button.rb +5 -5
  19. data/app/pb_kits/playbook/pb_caption/_caption.tsx +1 -1
  20. data/app/pb_kits/playbook/pb_caption/_caption_mixin.scss +3 -1
  21. data/app/pb_kits/playbook/pb_caption/docs/_caption_colors.html.erb +2 -1
  22. data/app/pb_kits/playbook/pb_caption/docs/_caption_colors.jsx +5 -0
  23. data/app/pb_kits/playbook/pb_card/_card.tsx +5 -5
  24. data/app/pb_kits/playbook/pb_checkbox/{_checkbox.jsx → _checkbox.tsx} +33 -29
  25. data/app/pb_kits/playbook/pb_currency/_currency.jsx +7 -2
  26. data/app/pb_kits/playbook/pb_currency/currency.rb +8 -0
  27. data/app/pb_kits/playbook/pb_currency/currency.test.js +28 -0
  28. data/app/pb_kits/playbook/pb_currency/docs/_currency_matching_decimals.html.erb +24 -0
  29. data/app/pb_kits/playbook/pb_currency/docs/_currency_matching_decimals.jsx +38 -0
  30. data/app/pb_kits/playbook/pb_currency/docs/example.yml +2 -0
  31. data/app/pb_kits/playbook/pb_currency/docs/index.js +1 -0
  32. data/app/pb_kits/playbook/pb_date_picker/_date_picker.jsx +30 -18
  33. data/app/pb_kits/playbook/pb_date_picker/_date_picker.scss +3 -0
  34. data/app/pb_kits/playbook/pb_date_picker/date_picker.rb +12 -1
  35. data/app/pb_kits/playbook/pb_date_picker/date_picker.test.js +160 -0
  36. data/app/pb_kits/playbook/pb_date_picker/date_picker_helper.js +37 -11
  37. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_default.html.erb +1 -1
  38. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_month_and_year.html.erb +2 -2
  39. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_month_and_year.jsx +1 -1
  40. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_month_and_year.md +1 -1
  41. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_time.html.erb +6 -0
  42. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_time.jsx +21 -0
  43. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_time.md +1 -0
  44. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_week.html.erb +5 -0
  45. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_week.jsx +18 -0
  46. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_week.md +1 -0
  47. data/app/pb_kits/playbook/pb_date_picker/docs/example.yml +4 -0
  48. data/app/pb_kits/playbook/pb_date_picker/docs/index.js +2 -0
  49. data/app/pb_kits/playbook/pb_date_picker/plugins/timeSelect.js +137 -0
  50. data/app/pb_kits/playbook/pb_date_picker/sass_partials/_day_styles.scss +27 -2
  51. data/app/pb_kits/playbook/pb_date_picker/sass_partials/_flatpickr_styles.scss +1 -5
  52. data/app/pb_kits/playbook/pb_date_picker/sass_partials/_time_selection_styles.scss +63 -0
  53. data/app/pb_kits/playbook/pb_date_picker/sass_partials/_week_styles.scss +127 -0
  54. data/app/pb_kits/playbook/pb_form_pill/{_form_pill.jsx → _form_pill.tsx} +16 -12
  55. data/app/pb_kits/playbook/pb_form_pill/docs/_form_pill_example.jsx +1 -1
  56. data/app/pb_kits/playbook/pb_form_pill/docs/_form_pill_size.jsx +1 -1
  57. data/app/pb_kits/playbook/pb_form_pill/docs/_form_pill_tag.jsx +1 -1
  58. data/app/pb_kits/playbook/pb_form_pill/docs/_form_pill_user.jsx +1 -1
  59. data/app/pb_kits/playbook/pb_hashtag/{_hashtag.jsx → _hashtag.tsx} +3 -4
  60. data/app/pb_kits/playbook/pb_home_address_street/{_city_emphasis.html.erb → city_emphasis.html.erb} +0 -0
  61. data/app/pb_kits/playbook/pb_home_address_street/city_emphasis.rb +16 -0
  62. data/app/pb_kits/playbook/pb_home_address_street/docs/example.yml +0 -2
  63. data/app/pb_kits/playbook/pb_home_address_street/home_address_street.html.erb +3 -2
  64. data/app/pb_kits/playbook/pb_home_address_street/home_address_street.rb +23 -2
  65. data/app/pb_kits/playbook/pb_home_address_street/{_street_emphasis.html.erb → street_emphasis.html.erb} +0 -0
  66. data/app/pb_kits/playbook/pb_home_address_street/street_emphasis.rb +15 -0
  67. data/app/pb_kits/playbook/pb_radio/_radio.tsx +86 -0
  68. data/app/pb_kits/playbook/pb_select/{_select.jsx → _select.tsx} +34 -38
  69. data/app/pb_kits/playbook/pb_text_input/{_text_input.jsx → _text_input.tsx} +42 -43
  70. data/app/pb_kits/playbook/tokens/_colors.scss +17 -1
  71. data/app/pb_kits/playbook/utilities/props.ts +2 -2
  72. data/lib/playbook/props.rb +1 -1
  73. data/lib/playbook/version.rb +2 -2
  74. metadata +26 -12
  75. data/app/pb_kits/playbook/pb_radio/_radio.jsx +0 -78
@@ -1,34 +1,32 @@
1
- /* @flow */
2
-
3
1
  import React, { useEffect, useRef } from 'react'
4
2
  import Body from '../pb_body/_body'
5
3
  import Icon from '../pb_icon/_icon'
6
4
  import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
7
5
  import classnames from 'classnames'
8
- import { globalProps } from '../utilities/globalProps'
6
+ import { globalProps, GlobalProps } from '../utilities/globalProps'
9
7
 
10
8
  type CheckboxProps = {
11
- aria?: object,
9
+ aria?: {[key: string]: string},
12
10
  checked?: boolean,
13
11
  children: Node,
14
12
  className?: string,
15
13
  dark?: boolean,
16
- data?: object,
14
+ data?: {[key: string]: string},
17
15
  error?: boolean,
18
16
  id?: string,
19
17
  indeterminate?: boolean,
20
18
  name: string,
21
- onChange: (boolean) => void,
19
+ onChange: (event: React.FormEvent<HTMLInputElement>) => void,
22
20
  tabIndex: number,
23
21
  text: string,
24
22
  value: string,
25
- }
23
+ } & GlobalProps
26
24
 
27
- const Checkbox = (props: CheckboxProps) => {
25
+ const Checkbox = (props: CheckboxProps): JSX.Element => {
28
26
  const {
29
27
  aria = {},
30
28
  checked = false,
31
- children = null,
29
+ children,
32
30
  className,
33
31
  dark = false,
34
32
  data = {},
@@ -42,12 +40,12 @@ const Checkbox = (props: CheckboxProps) => {
42
40
  value = '',
43
41
  } = props
44
42
 
45
- const checkRef = useRef()
43
+ const checkRef = useRef(null)
46
44
  const dataProps = buildDataProps(data)
47
45
  const ariaProps = buildAriaProps(aria)
48
46
  const classes = classnames(
49
- buildCss('pb_checkbox_kit', { checked, error, indeterminate }),
50
- globalProps(props),
47
+ buildCss('pb_checkbox_kit', checked ? 'checked' : null, error ? 'error' : null, indeterminate? 'indeterminate' : null),
48
+ globalProps(props),
51
49
  className
52
50
  )
53
51
 
@@ -58,6 +56,22 @@ const Checkbox = (props: CheckboxProps) => {
58
56
  }
59
57
  }, [indeterminate, checked])
60
58
 
59
+ const checkboxChildren = () => {
60
+ if (children)
61
+ return (children)
62
+ else
63
+ return (
64
+ <input
65
+ defaultChecked={checked}
66
+ name={name}
67
+ onChange={onChange}
68
+ ref={checkRef}
69
+ tabIndex={tabIndex}
70
+ type="checkbox"
71
+ value={value}
72
+ />)
73
+ }
74
+
61
75
  return (
62
76
  <label
63
77
  {...ariaProps}
@@ -65,20 +79,9 @@ const Checkbox = (props: CheckboxProps) => {
65
79
  className={classes}
66
80
  id={id}
67
81
  >
68
- <If condition={children}>
69
- {children}
70
- <Else />
71
- <input
72
- defaultChecked={checked}
73
- name={name}
74
- onChange={onChange}
75
- ref={checkRef}
76
- tabIndex={tabIndex}
77
- type="checkbox"
78
- value={value}
79
- />
80
- </If>
81
- <If condition={!indeterminate}>
82
+ <>{checkboxChildren()}</>
83
+
84
+ {!indeterminate &&
82
85
  <span className="pb_checkbox_checkmark">
83
86
  <Icon
84
87
  className="check_icon"
@@ -86,9 +89,9 @@ const Checkbox = (props: CheckboxProps) => {
86
89
  icon="check"
87
90
  />
88
91
  </span>
89
- </If>
92
+ }
90
93
 
91
- <If condition={indeterminate}>
94
+ {indeterminate &&
92
95
  <span className="pb_checkbox_indeterminate">
93
96
  <Icon
94
97
  className="indeterminate_icon"
@@ -96,12 +99,13 @@ const Checkbox = (props: CheckboxProps) => {
96
99
  icon="minus"
97
100
  />
98
101
  </span>
99
- </If>
102
+ }
100
103
 
101
104
  <Body
102
105
  className="pb_checkbox_label"
103
106
  dark={dark}
104
107
  status={error ? 'negative' : null}
108
+ variant={null}
105
109
  >
106
110
  {text}
107
111
  </Body>
@@ -18,6 +18,7 @@ type CurrencyProps = {
18
18
  className?: string,
19
19
  dark?: boolean,
20
20
  data?: object,
21
+ decimals?: 'default' | 'matching',
21
22
  emphasized?: boolean,
22
23
  id?: string,
23
24
  label?: string,
@@ -40,6 +41,7 @@ const Currency = (props: CurrencyProps) => {
40
41
  aria = {},
41
42
  amount,
42
43
  data = {},
44
+ decimals = 'default',
43
45
  emphasized = true,
44
46
  id,
45
47
  unit,
@@ -85,9 +87,12 @@ const Currency = (props: CurrencyProps) => {
85
87
  return isAmount ? num.slice(0, -1) : isUnit ? num.slice(-1) : ''
86
88
  }
87
89
 
88
- const getAmount = abbreviate ? getAbbreviatedValue('amount') : whole,
90
+ const getMatchingDecimalAmount = decimals === "matching" ? amount : whole,
91
+ getMatchingDecimalValue = decimals === "matching" ? '' : `.${decimal}`
92
+
93
+ const getAmount = abbreviate ? getAbbreviatedValue('amount') : getMatchingDecimalAmount,
89
94
  getAbbreviation = abbreviate ? getAbbreviatedValue('unit') : null,
90
- getDecimalValue = abbreviate ? '' : `.${decimal}`
95
+ getDecimalValue = abbreviate ? '' : getMatchingDecimalValue
91
96
 
92
97
  return (
93
98
  <div
@@ -36,6 +36,10 @@ module Playbook
36
36
  prop :abbreviate, type: Playbook::Props::Boolean,
37
37
  default: false
38
38
 
39
+ prop :decimals, type: Playbook::Props::Enum,
40
+ values: %w[default matching],
41
+ default: "default"
42
+
39
43
  def classname
40
44
  generate_classname("pb_currency_kit", align, size, dark_class)
41
45
  end
@@ -84,6 +88,8 @@ module Playbook
84
88
  private
85
89
 
86
90
  def whole_value
91
+ return amount if decimals == "matching"
92
+
87
93
  amount.split(".").first.to_s
88
94
  end
89
95
 
@@ -94,6 +100,8 @@ module Playbook
94
100
  end
95
101
 
96
102
  def units_element
103
+ return "" if decimals == "matching" && !abbreviate && !unit
104
+
97
105
  _, decimal_part = amount.split(".")
98
106
  if unit.nil? && abbreviate == false
99
107
  decimal_part.nil? ? ".00" : ".#{decimal_part}"
@@ -33,3 +33,31 @@ test('abbreviate prop returns proper abbreviated amount', () => {
33
33
  expect(screen.getByTestId('test-billions')).toHaveTextContent('$3.2B')
34
34
  expect(screen.getByTestId('test-trillions')).toHaveTextContent('$3.2T')
35
35
  })
36
+
37
+ test('decimals matching prop returns decimals as title text', () => {
38
+ render(
39
+ <Currency
40
+ amount="320.20"
41
+ data={{ testid: 'test-decimals-matching' }}
42
+ decimals='matching'
43
+ />
44
+ )
45
+
46
+ const currencyKit = screen.getByTestId('test-decimals-matching')
47
+ expect(currencyKit.querySelector('.pb_currency_value')).toHaveTextContent('320.20')
48
+ expect(currencyKit.querySelector('.unit')).toHaveTextContent('')
49
+ })
50
+
51
+ test('decimals default prop returns decimals as body text', () => {
52
+ render(
53
+ <Currency
54
+ amount="320.20"
55
+ data={{ testid: 'test-decimals-default' }}
56
+ decimals='default'
57
+ />
58
+ )
59
+
60
+ const currencyKit = screen.getByTestId('test-decimals-default')
61
+ expect(currencyKit.querySelector('.pb_currency_value')).toHaveTextContent('320')
62
+ expect(currencyKit.querySelector('.unit')).toHaveTextContent('.20')
63
+ })
@@ -0,0 +1,24 @@
1
+ <%= pb_rails("currency", props: {
2
+ amount: "372.12",
3
+ decimals: "matching",
4
+ label: "Small",
5
+ margin_bottom: "md",
6
+ size: "sm",
7
+ unit: "/day",
8
+ }) %>
9
+
10
+ <%= pb_rails("currency", props: {
11
+ amount: "30,327.43",
12
+ decimals: "matching",
13
+ label: "Medium",
14
+ margin_bottom: "md",
15
+ size: "md",
16
+ symbol: "€",
17
+ }) %>
18
+
19
+ <%= pb_rails("currency", props: {
20
+ amount: "621,953.99",
21
+ decimals: "matching",
22
+ label: "Large",
23
+ size: "lg",
24
+ }) %>
@@ -0,0 +1,38 @@
1
+ import React from 'react'
2
+
3
+ import Currency from '../_currency'
4
+
5
+ const CurrencyMatchingDecimals = (props) => {
6
+ return (
7
+ <>
8
+ <Currency
9
+ amount="372.12"
10
+ decimals="matching"
11
+ label="Small"
12
+ marginBottom="md"
13
+ size="sm"
14
+ unit="/day"
15
+ {...props}
16
+ />
17
+ <Currency
18
+ amount="30,327.43"
19
+ decimals="matching"
20
+ label="Medium"
21
+ marginBottom="md"
22
+ size="md"
23
+ symbol="€"
24
+ {...props}
25
+ />
26
+ <Currency
27
+ amount="621,953.99"
28
+ decimals="matching"
29
+ label="Large"
30
+ size="lg"
31
+ {...props}
32
+ />
33
+ </>
34
+ )
35
+ }
36
+
37
+ export default CurrencyMatchingDecimals
38
+
@@ -6,6 +6,7 @@ examples:
6
6
  - currency_alignment: Alignment
7
7
  - currency_no_symbol: No Symbol
8
8
  - currency_abbreviated: Abbreviate Larger Amounts
9
+ - currency_matching_decimals: Matching Decimals
9
10
 
10
11
  react:
11
12
  - currency_variants: Variants
@@ -13,3 +14,4 @@ examples:
13
14
  - currency_alignment: Alignment
14
15
  - currency_no_symbol: No Symbol
15
16
  - currency_abbreviated: Abbreviate Larger Amounts
17
+ - currency_matching_decimals: Matching Decimals
@@ -3,3 +3,4 @@ export { default as CurrencySize } from './_currency_size.jsx'
3
3
  export { default as CurrencyAlignment } from './_currency_alignment.jsx'
4
4
  export { default as CurrencyNoSymbol } from './_currency_no_symbol.jsx'
5
5
  export { default as CurrencyAbbreviated } from './_currency_abbreviated.jsx'
6
+ export { default as CurrencyMatchingDecimals } from './_currency_matching_decimals.jsx'
@@ -4,7 +4,7 @@ import React, { useEffect } from 'react'
4
4
  import classnames from 'classnames'
5
5
 
6
6
  import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
7
- import { globalProps } from '../utilities/globalProps'
7
+ import { deprecatedProps, globalProps } from '../utilities/globalProps'
8
8
 
9
9
  import datePickerHelper from './date_picker_helper'
10
10
 
@@ -22,6 +22,7 @@ type DatePickerProps = {
22
22
  disableInput?: Boolean,
23
23
  disableRange?: Array,
24
24
  disableWeekdays?: Array,
25
+ enableTime?: Boolean,
25
26
  error?: String,
26
27
  format?: String,
27
28
  hideIcon?: Boolean,
@@ -40,11 +41,16 @@ type DatePickerProps = {
40
41
  onChange: (String) => void,
41
42
  pickerId?: String,
42
43
  placeholder?: String,
43
- plugins?: Boolean,
44
+ plugins: Boolean,
45
+ selectionType?: "month" | "week",
46
+ showTimezone?: Boolean,
47
+ timeFormat?: String,
44
48
  type?: String,
45
49
  yearRange?: Array,
46
50
  }
47
51
  const DatePicker = (props: DatePickerProps) => {
52
+ if (props.plugins) deprecatedProps('Date Picker', ['plugins'])
53
+
48
54
  const {
49
55
  allowInput = false,
50
56
  aria = {},
@@ -56,6 +62,7 @@ const DatePicker = (props: DatePickerProps) => {
56
62
  disableInput,
57
63
  disableRange = null,
58
64
  disableWeekdays = null,
65
+ enableTime = false,
59
66
  error,
60
67
  format = 'm/d/Y',
61
68
  hideIcon = false,
@@ -75,6 +82,8 @@ const DatePicker = (props: DatePickerProps) => {
75
82
  pickerId,
76
83
  placeholder = 'Select Date',
77
84
  plugins = false,
85
+ selectionType = '',
86
+ showTimezone = false,
78
87
  yearRange = [ 1900, 2100 ],
79
88
  } = props
80
89
 
@@ -89,23 +98,26 @@ const DatePicker = (props: DatePickerProps) => {
89
98
 
90
99
  useEffect(() => {
91
100
  datePickerHelper({
92
- allowInput: allowInput,
93
- defaultDate: defaultDate,
94
- disableDate: disableDate,
95
- disableRange: disableRange,
96
- disableWeekdays: disableWeekdays,
97
- format: format,
98
- hideIcon: hideIcon,
99
- inLine: inLine,
100
- maxDate: maxDate,
101
- minDate: minDate,
102
- mode: mode,
103
- onChange: onChange,
104
- pickerId: pickerId,
105
- plugins: plugins,
106
- yearRange: yearRange,
101
+ allowInput,
102
+ defaultDate,
103
+ disableDate,
104
+ disableRange,
105
+ disableWeekdays,
106
+ enableTime,
107
+ format,
108
+ hideIcon,
109
+ inLine,
110
+ maxDate,
111
+ minDate,
112
+ mode,
113
+ onChange,
114
+ pickerId,
115
+ plugins,
116
+ selectionType,
117
+ showTimezone,
118
+ yearRange,
107
119
  })
108
- }, [])
120
+ })
109
121
 
110
122
  const iconWrapperClass = () => {
111
123
  let base = 'cal_icon_wrapper'
@@ -4,6 +4,9 @@
4
4
  @import "./sass_partials/flatpickr_styles";
5
5
  @import "./sass_partials/inline_styles";
6
6
  @import "./sass_partials/month_and_year_styles";
7
+ @import "./sass_partials/time_selection_styles";
8
+
9
+
7
10
 
8
11
  [class^=pb_date_picker_kit] {
9
12
  .input_wrapper {
@@ -17,6 +17,8 @@ module Playbook
17
17
  default: []
18
18
  prop :disable_weekdays, type: Playbook::Props::Array,
19
19
  default: []
20
+ prop :enable_time, type: Playbook::Props::Boolean,
21
+ default: false
20
22
  prop :error, type: Playbook::Props::String
21
23
  prop :format, type: Playbook::Props::String,
22
24
  default: "m/d/Y"
@@ -42,7 +44,13 @@ module Playbook
42
44
  prop :placeholder, type: Playbook::Props::String,
43
45
  default: "Select Date"
44
46
  prop :plugins, type: Playbook::Props::Boolean,
45
- default: false
47
+ default: false,
48
+ deprecated: true
49
+ prop :selection_type, type: Playbook::Props::Enum,
50
+ values: %w[week month none],
51
+ default: "none"
52
+ prop :show_timezone, type: Playbook::Props::Boolean,
53
+ default: false
46
54
  prop :required, type: Playbook::Props::Boolean,
47
55
  default: false
48
56
  prop :year_range, type: Playbook::Props::Array,
@@ -59,6 +67,7 @@ module Playbook
59
67
  disableDate: disable_date,
60
68
  disableRange: disable_range,
61
69
  disableWeekdays: disable_weekdays,
70
+ enableTime: enable_time,
62
71
  format: format,
63
72
  hideIcon: hide_icon,
64
73
  inline: inline,
@@ -68,6 +77,8 @@ module Playbook
68
77
  pickerId: picker_id,
69
78
  plugins: plugins,
70
79
  required: required,
80
+ selectionType: selection_type,
81
+ showTimezone: show_timezone,
71
82
  yearRange: year_range,
72
83
  }.to_json.html_safe
73
84
  end
@@ -0,0 +1,160 @@
1
+ /* eslint-disable no-console */
2
+ import React from 'react'
3
+ import { fireEvent, render, screen, waitFor, within } from '../utilities/test-utils'
4
+
5
+ import DatePicker from './_date_picker'
6
+ import { getTimezoneText } from './plugins/timeSelect'
7
+
8
+ const DEFAULT_DATE = new Date()
9
+ DEFAULT_DATE.setFullYear(2022)
10
+ DEFAULT_DATE.setMonth(1)
11
+ DEFAULT_DATE.setDate(1)
12
+ DEFAULT_DATE.setHours(12)
13
+ DEFAULT_DATE.setMinutes(0)
14
+
15
+ describe('DatePicker Kit', () => {
16
+ beforeEach(() => {
17
+ jest.spyOn(console, 'error').mockImplementation(() => {});
18
+ });
19
+
20
+ test('renders DatePicker input field', () => {
21
+ const testId = 'datepicker-kit'
22
+ render(
23
+ <DatePicker
24
+ data={{ testid: testId }}
25
+ defaultDate={DEFAULT_DATE}
26
+ pickerId="date-picker"
27
+ />
28
+ )
29
+
30
+ const kit = screen.getByTestId(testId)
31
+ expect(kit).toHaveClass('pb_date_picker_kit')
32
+ })
33
+
34
+ test('shows DatePicker date format m/d/Y', async () => {
35
+ const testId = 'datepicker-date'
36
+ render(
37
+ <DatePicker
38
+ data={{ testid: testId }}
39
+ defaultDate={DEFAULT_DATE}
40
+ format="m/d/Y"
41
+ pickerId="date-picker-date"
42
+ />
43
+ )
44
+
45
+ const kit = screen.getByTestId(testId)
46
+
47
+ const input = within(kit).getByPlaceholderText('Select Date')
48
+ expect(input).toBeInTheDocument()
49
+ await waitFor(() => {
50
+ expect(input).toHaveValue('02/01/2022')
51
+ })
52
+ })
53
+
54
+ test('shows DatePicker time caption text', async () => {
55
+ const testId = 'datepicker-time-caption'
56
+ render(
57
+ <DatePicker
58
+ data={{ testid: testId }}
59
+ defaultDate={DEFAULT_DATE}
60
+ enableTime
61
+ pickerId="date-picker-time-caption"
62
+ />
63
+ )
64
+
65
+ const kit = screen.getByTestId(testId)
66
+ const input = within(kit).getByPlaceholderText('Select Date')
67
+
68
+ fireEvent(
69
+ input,
70
+ new MouseEvent('click', {
71
+ bubbles: true,
72
+ cancelable: true,
73
+ }),
74
+ )
75
+ await waitFor(() => {
76
+ const caption = within(kit).getByText('Select Time')
77
+ expect(caption).toBeInTheDocument()
78
+ })
79
+ })
80
+
81
+ test('shows DatePicker timezone text', async () => {
82
+ const testId = 'datepicker-timezone'
83
+ render(
84
+ <DatePicker
85
+ data={{ testid: testId }}
86
+ defaultDate={DEFAULT_DATE}
87
+ enableTime
88
+ pickerId="date-picker-timezone"
89
+ showTimezone
90
+ />
91
+ )
92
+
93
+ const kit = screen.getByTestId(testId)
94
+ const input = within(kit).getByPlaceholderText('Select Date')
95
+ const defaultTimezoneText = getTimezoneText(DEFAULT_DATE)
96
+
97
+ fireEvent(
98
+ input,
99
+ new MouseEvent('click', {
100
+ bubbles: true,
101
+ cancelable: true,
102
+ }),
103
+ )
104
+ await waitFor(() => {
105
+ const timezoneText = within(kit).getByText(defaultTimezoneText)
106
+ expect(timezoneText).toBeInTheDocument()
107
+ })
108
+ })
109
+
110
+ test('shows DatePicker meridiem toggle', async () => {
111
+ const testId = 'datepicker-meridiem'
112
+ render(
113
+ <DatePicker
114
+ data={{ testid: testId }}
115
+ defaultDate={DEFAULT_DATE}
116
+ enableTime
117
+ pickerId="date-picker-meridiem"
118
+ />
119
+ )
120
+
121
+ const kit = screen.getByTestId(testId)
122
+ const input = within(kit).getByPlaceholderText('Select Date')
123
+
124
+ fireEvent(
125
+ input,
126
+ new MouseEvent('click', {
127
+ bubbles: true,
128
+ cancelable: true,
129
+ }),
130
+ )
131
+ const meridiemToggleAM = within(kit).getByLabelText('AM')
132
+ const meridiemTogglePM = within(kit).getByLabelText('PM')
133
+ await waitFor(() => {
134
+ expect(meridiemToggleAM).toBeInTheDocument()
135
+ expect(meridiemTogglePM).toBeInTheDocument()
136
+ })
137
+
138
+ fireEvent(
139
+ meridiemToggleAM,
140
+ new MouseEvent('click', {
141
+ bubbles: true,
142
+ cancelable: true,
143
+ }),
144
+ )
145
+ await waitFor(() => {
146
+ expect(input).toHaveValue('02/01/2022 at 12:00 AM')
147
+ })
148
+
149
+ fireEvent(
150
+ meridiemTogglePM,
151
+ new MouseEvent('click', {
152
+ bubbles: true,
153
+ cancelable: true,
154
+ }),
155
+ )
156
+ await waitFor(() => {
157
+ expect(input).toHaveValue('02/01/2022 at 12:00 PM')
158
+ })
159
+ })
160
+ })