@loadsmart/loadsmart-ui 5.10.1 → 5.11.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 (89) hide show
  1. package/dist/components/Calendar/Calendar.stories.d.ts +2 -7
  2. package/dist/components/Calendar/Date.helper.d.ts +47 -12
  3. package/dist/components/Dropdown/Dropdown.stories.d.ts +4 -1
  4. package/dist/components/Loaders/LoadingBar.stories.d.ts +1 -1
  5. package/dist/index.js +64 -64
  6. package/dist/index.js.map +1 -1
  7. package/dist/tests/generator.d.ts +35 -0
  8. package/dist/tests/renderer.d.ts +10 -0
  9. package/package.json +1 -1
  10. package/src/components/Accordion/Accordion.stories.tsx +1 -1
  11. package/src/components/Accordion/Accordion.test.tsx +2 -2
  12. package/src/components/Banner/Banner.test.tsx +2 -2
  13. package/src/components/Breadcrumbs/Breadbrumbs.test.tsx +2 -2
  14. package/src/components/Button/Button.test.tsx +2 -2
  15. package/src/components/Calendar/Calendar.stories.tsx +4 -2
  16. package/src/components/Calendar/Calendar.test.tsx +3 -3
  17. package/src/components/Calendar/Date.helper.test.ts +463 -15
  18. package/src/components/Calendar/Date.helper.ts +106 -45
  19. package/src/components/Calendar/Pickers/DayPicker.test.tsx +2 -2
  20. package/src/components/Calendar/Pickers/MonthPicker.test.tsx +2 -2
  21. package/src/components/Calendar/Pickers/YearPicker.test.tsx +9 -7
  22. package/src/components/Card/Card.stories.tsx +1 -1
  23. package/src/components/Card/Card.test.tsx +2 -2
  24. package/src/components/Checkbox/Checkbox.test.tsx +2 -2
  25. package/src/components/DatePicker/DatePicker.test.tsx +2 -2
  26. package/src/components/DatePicker/DateRangePicker.stories.tsx +6 -1
  27. package/src/components/DatePicker/DateRangePicker.test.tsx +2 -2
  28. package/src/components/Dialog/Dialog.test.tsx +2 -2
  29. package/src/components/DragDropFile/components/DropZone.test.tsx +1 -1
  30. package/src/components/Drawer/Drawer.test.tsx +1 -1
  31. package/src/components/Dropdown/Dropdown.stories.tsx +10 -5
  32. package/src/components/Dropdown/Dropdown.test.tsx +14 -16
  33. package/src/components/EmptyState/EmptyState.test.tsx +1 -1
  34. package/src/components/ErrorMessage/ErrorMessage.test.tsx +1 -1
  35. package/src/components/HighlightMatch/HighlightMatch.test.tsx +1 -1
  36. package/src/components/IconFactory/IconFactory.test.tsx +2 -2
  37. package/src/components/Label/Label.test.tsx +2 -2
  38. package/src/components/Link/Link.test.tsx +2 -2
  39. package/src/components/Loaders/LoadingBar.stories.tsx +2 -2
  40. package/src/components/Loaders/LoadingBar.test.tsx +1 -1
  41. package/src/components/Loaders/LoadingDots.test.tsx +1 -1
  42. package/src/components/Loaders/Spinner.test.tsx +2 -2
  43. package/src/components/Modal/Modal.test.tsx +2 -2
  44. package/src/components/Pagination/Pagination.test.tsx +1 -1
  45. package/src/components/Popover/Popover.test.tsx +2 -2
  46. package/src/components/ProgressBar/ProgressBar.test.tsx +1 -1
  47. package/src/components/Radio/Radio.test.tsx +2 -2
  48. package/src/components/Section/Section.test.tsx +2 -2
  49. package/src/components/Section/Sections.stories.tsx +1 -1
  50. package/src/components/Select/Select.fixtures.ts +1 -1
  51. package/src/components/Select/Select.stories.tsx +2 -2
  52. package/src/components/Select/Select.test.tsx +12 -5
  53. package/src/components/Select/useSelect.helpers.test.ts +1 -1
  54. package/src/components/SideNavigation/Logo/Logo.test.tsx +2 -2
  55. package/src/components/SideNavigation/Menu/Menu.test.tsx +2 -2
  56. package/src/components/SideNavigation/Separator/Separator.test.tsx +1 -1
  57. package/src/components/SideNavigation/SideNavigation.test.tsx +2 -2
  58. package/src/components/Steps/Steps.fixtures.ts +1 -1
  59. package/src/components/Steps/Steps.test.tsx +2 -2
  60. package/src/components/Steps/useStep.test.tsx +1 -1
  61. package/src/components/Switch/Switch.test.tsx +1 -1
  62. package/src/components/Table/Table.fixtures.ts +1 -1
  63. package/src/components/Table/Table.test.tsx +1 -1
  64. package/src/components/TablePagination/TablePagination.test.tsx +1 -1
  65. package/src/components/Tabs/Tabs.test.tsx +1 -1
  66. package/src/components/Tag/Tag.stories.tsx +1 -1
  67. package/src/components/Tag/Tag.test.tsx +2 -2
  68. package/src/components/Text/Text.test.tsx +2 -2
  69. package/src/components/TextField/TextField.test.tsx +1 -1
  70. package/src/components/Textarea/Textarea.test.tsx +1 -1
  71. package/src/components/Toast/Toast.test.tsx +2 -2
  72. package/src/components/ToggleGroup/Toggle.test.tsx +2 -2
  73. package/src/components/ToggleGroup/ToggleGroup.test.tsx +2 -2
  74. package/src/components/Tooltip/Tooltip.test.tsx +2 -2
  75. package/src/components/TopNavigation/Logo/Logo.test.tsx +2 -2
  76. package/src/components/TopNavigation/Menu/Menu.test.tsx +1 -1
  77. package/src/components/VisuallyHidden/VisuallyHidden.test.tsx +1 -1
  78. package/src/hooks/useClickOutside/useClickOutside.test.tsx +1 -1
  79. package/src/hooks/useDidMount/useDidMount.test.tsx +1 -1
  80. package/src/hooks/useFocusTrap/useFocusTrap.test.tsx +1 -1
  81. package/src/hooks/useFocusWithin/useFocusWithin.test.tsx +1 -1
  82. package/src/hooks/useHeightExpansionToggler/useHeightExpansionToggler.test.tsx +1 -1
  83. package/src/hooks/useSelectable/SelectableStrategy.test.ts +1 -1
  84. package/src/hooks/useSelectable/useSelectable.test.ts +1 -1
  85. package/src/testing/SelectEvent/SelectEvent.test.tsx +2 -2
  86. package/src/tests/generator.ts +127 -0
  87. package/src/tests/renderer.tsx +39 -0
  88. package/src/tools/conditional.test.ts +1 -1
  89. package/src/utils/toolset/interleave.test.ts +1 -1
@@ -0,0 +1,127 @@
1
+ import Chance from 'chance'
2
+ import { nanoid } from 'nanoid'
3
+
4
+ const chance = new Chance()
5
+
6
+ /**
7
+ * Generates an array of `amount` (or random) length, based on the given
8
+ * template function.
9
+ * The template function receives as named parameter the current `index`.
10
+ * @param {Function} template Template function to generate one item
11
+ * @param {number} amount Amount of items to be generated. If none is provide,
12
+ * then a random amount is generated.
13
+ * @returns {Array} Returns an array of lenght `amount`, with items
14
+ * generated based on the provided `template`.
15
+ */
16
+ function generateArray<T>(
17
+ template: ({ index }: { index: number }) => T,
18
+ amount?: number
19
+ ): Array<T> {
20
+ const safeAmount = amount || chance.integer({ min: 5, max: 10 })
21
+
22
+ const data = []
23
+ for (let i = 0; i < safeAmount; i++) {
24
+ const item = template({ index: i })
25
+ data.push(item)
26
+ }
27
+
28
+ return data
29
+ }
30
+
31
+ function generatePick<T>(
32
+ array: Array<T>,
33
+ options?: { amount: number; allowRepeat?: boolean }
34
+ ): T | Array<T> {
35
+ const { amount = 1, allowRepeat = true } = options || {}
36
+
37
+ if (amount === 1) {
38
+ return chance.pickone(array)
39
+ }
40
+
41
+ let picked = chance.pickset(array, amount)
42
+
43
+ if (!allowRepeat) {
44
+ picked = Array.from(new Set(picked))
45
+ }
46
+
47
+ return picked
48
+ }
49
+
50
+ function generateDate(overrides: { month?: number; day?: number; year?: number } = {}): string {
51
+ const month = String(overrides.month ?? chance.natural({ min: 1, max: 12 })).padStart(2, '0')
52
+ const day = String(overrides.day ?? chance.natural({ min: 1, max: 28 })).padStart(2, '0')
53
+ const year = overrides.year ?? new Date().getFullYear()
54
+
55
+ return `${month}/${day}/${year}`
56
+ }
57
+
58
+ function generateTime(opts?: Chance.Options): string {
59
+ const hour = String(chance.hour({ twentyfour: true, ...opts })).padStart(2, '0')
60
+ const minute = String(chance.minute()).padStart(2, '0')
61
+
62
+ return `${hour}:${minute}`
63
+ }
64
+
65
+ function generateUsername(): string {
66
+ const name = chance.name()
67
+ return name.replace(/^\s+|\s+$/g, '').toLowerCase()
68
+ }
69
+
70
+ function generateID(): string {
71
+ return nanoid()
72
+ }
73
+
74
+ interface DataGenerator {
75
+ animal: () => string
76
+ array: <T>(template: ({ index }: { index: number }) => T, amount?: number) => Array<T>
77
+ boolean: () => boolean
78
+ company: () => string
79
+ date: () => string
80
+ float: (opts?: Chance.Options) => number
81
+ id: () => string
82
+ name: (opts?: Chance.Options) => string
83
+ natural: (opts?: Chance.Options) => number
84
+ paragraph: (opts?: Chance.Options) => string
85
+ /**
86
+ * @deprecated Use pickone or pickset
87
+ */
88
+ pick: <T>(array: Array<T>, options?: { amount: number; allowRepeat?: boolean }) => T | Array<T>
89
+ pickone<T>(arr: T[]): T
90
+ pickset<T>(arr: T[], count?: number): T[]
91
+ profession: () => string
92
+ sentence: (opts?: Chance.Options) => string
93
+ state: (opts?: Chance.Options) => string
94
+ time: (opts?: Chance.Options) => string
95
+ token: () => string
96
+ url: () => string
97
+ username: () => string
98
+ word: (opts?: Chance.Options) => string
99
+ dollar: () => string
100
+ }
101
+
102
+ const generators: DataGenerator = {
103
+ animal: chance.animal.bind(chance),
104
+ array: generateArray,
105
+ boolean: chance.bool.bind(chance),
106
+ company: chance.company.bind(chance),
107
+ date: generateDate,
108
+ float: chance.floating.bind(chance),
109
+ id: generateID,
110
+ name: chance.name.bind(chance),
111
+ natural: chance.natural.bind(chance),
112
+ paragraph: chance.paragraph.bind(chance),
113
+ pick: generatePick,
114
+ pickone: chance.pickone.bind(chance),
115
+ pickset: chance.pickset.bind(chance),
116
+ profession: chance.profession.bind(chance),
117
+ sentence: chance.sentence.bind(chance),
118
+ state: chance.state.bind(chance),
119
+ time: generateTime,
120
+ token: chance.animal.bind(chance),
121
+ url: chance.url.bind(chance),
122
+ username: generateUsername,
123
+ word: chance.word.bind(chance),
124
+ dollar: chance.dollar.bind(chance),
125
+ }
126
+
127
+ export default generators
@@ -0,0 +1,39 @@
1
+ import {
2
+ render,
3
+ fireEvent,
4
+ RenderOptions,
5
+ within,
6
+ waitFor,
7
+ waitForElementToBeRemoved,
8
+ act,
9
+ screen,
10
+ queries,
11
+ } from '@testing-library/react'
12
+ import userEvent from '@testing-library/user-event'
13
+
14
+ class Renderer {
15
+ result: React.ReactElement
16
+
17
+ constructor(children: React.ReactElement) {
18
+ this.result = children
19
+ }
20
+
21
+ render(options?: Omit<RenderOptions, 'queries'>) {
22
+ return render(this.result, options)
23
+ }
24
+ }
25
+
26
+ export default function customRenderer(children: React.ReactElement): Renderer {
27
+ return new Renderer(children)
28
+ }
29
+
30
+ export {
31
+ act,
32
+ fireEvent as fire,
33
+ queries,
34
+ screen,
35
+ userEvent as user,
36
+ waitFor,
37
+ waitForElementToBeRemoved,
38
+ within,
39
+ }
@@ -1,5 +1,5 @@
1
1
  import conditional, { whenProps } from './conditional'
2
- import generator from '../../tests/generator'
2
+ import generator from '../tests/generator'
3
3
 
4
4
  describe('conditional', () => {
5
5
  describe('whenProps', () => {
@@ -1,5 +1,5 @@
1
1
  import interleave from './interleave'
2
- import generator from '../../../tests/generator'
2
+ import generator from '../../tests/generator'
3
3
 
4
4
  function generateArray() {
5
5
  return generator.array(() => generator.natural({ min: 1, max: 999 }), 3)