@oslokommune/punkt-react 12.32.0 → 12.32.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslokommune/punkt-react",
3
- "version": "12.32.0",
3
+ "version": "12.32.7",
4
4
  "description": "React komponentbibliotek til Punkt, et designsystem laget av Oslo Origo",
5
5
  "homepage": "https://punkt.oslo.kommune.no",
6
6
  "author": "Team Designsystem, Oslo Origo",
@@ -38,7 +38,7 @@
38
38
  "dependencies": {
39
39
  "@lit-labs/ssr-dom-shim": "^1.2.1",
40
40
  "@lit/react": "^1.0.5",
41
- "@oslokommune/punkt-elements": "^12.32.0",
41
+ "@oslokommune/punkt-elements": "^12.32.7",
42
42
  "angular-html-parser": "^6.0.2",
43
43
  "html-format": "^1.1.7",
44
44
  "prettier": "^3.3.3",
@@ -47,9 +47,9 @@
47
47
  "react-syntax-highlighter": "^15.5.0"
48
48
  },
49
49
  "devDependencies": {
50
+ "@babel/plugin-proposal-private-property-in-object": "^7.18.6",
50
51
  "@oslokommune/punkt-assets": "^12.30.1",
51
- "@oslokommune/punkt-css": "^12.32.0",
52
- "@oslokommune/punkt-testing-utils": "^12.32.0",
52
+ "@oslokommune/punkt-css": "^12.32.1",
53
53
  "@testing-library/jest-dom": "^6.5.0",
54
54
  "@testing-library/react": "^16.0.1",
55
55
  "@testing-library/user-event": "^14.5.2",
@@ -72,7 +72,7 @@
72
72
  "react-scripts": "^5.0.1",
73
73
  "sass": "^1.78.0",
74
74
  "typescript": "^5.6.2",
75
- "vite": "^5.4.4",
75
+ "vite": "^5.4.18",
76
76
  "vite-plugin-dts": "^4.2.1"
77
77
  },
78
78
  "peerDependencies": {
@@ -112,5 +112,5 @@
112
112
  "url": "https://github.com/oslokommune/punkt/issues"
113
113
  },
114
114
  "license": "MIT",
115
- "gitHead": "8d17b2b21d83b498b237d837747e753c64570285"
115
+ "gitHead": "001ce7fd764b33b5f4c7d90ad5418a62a4d780a6"
116
116
  }
@@ -94,6 +94,38 @@ test('forwardRef works correctly', async () => {
94
94
  expect(ref.current).toBe(screen.getByRole('button'))
95
95
  })
96
96
 
97
+ test('PktButton triggers click when focused and enter is pressed', async () => {
98
+ const handleClick = jest.fn()
99
+ render(<PktButton onClick={handleClick}>Trøkk her</PktButton>)
100
+
101
+ await window.customElements.whenDefined('pkt-button')
102
+
103
+ const button = screen.getByRole('button')
104
+
105
+ button.focus()
106
+ expect(button).toHaveFocus()
107
+
108
+ await userEvent.keyboard('{Enter}')
109
+
110
+ expect(handleClick).toHaveBeenCalledTimes(1)
111
+ })
112
+
113
+ test('PktButton triggers click when focused and space is pressed', async () => {
114
+ const handleClick = jest.fn()
115
+ render(<PktButton onClick={handleClick}>Trøkk igjen</PktButton>)
116
+
117
+ await window.customElements.whenDefined('pkt-button')
118
+
119
+ const button = screen.getByRole('button')
120
+
121
+ button.focus()
122
+ expect(button).toHaveFocus()
123
+
124
+ await userEvent.keyboard(' ')
125
+
126
+ expect(handleClick).toHaveBeenCalledTimes(1)
127
+ })
128
+
97
129
  describe('accessibility', () => {
98
130
  it('renders with no wcag errors with axe', async () => {
99
131
  const { container } = render(<PktButton title="Normal" skin="primary"></PktButton>)
@@ -4,8 +4,8 @@ import React, {
4
4
  SelectHTMLAttributes,
5
5
  ChangeEventHandler,
6
6
  FocusEventHandler,
7
- LegacyRef,
8
7
  FC,
8
+ LegacyRef,
9
9
  forwardRef,
10
10
  } from 'react'
11
11
  import { PktCombobox as PktElCombobox } from '@oslokommune/punkt-elements'
@@ -78,7 +78,7 @@ export const PktPreviewPropEditor: FC<PropEditorProps> = ({ propKey, spec, props
78
78
  requiredTag={spec.required}
79
79
  >
80
80
  <option value=""></option>
81
- {icons.map((icon) => (
81
+ {(icons as { id: string }[]).map((icon) => (
82
82
  <option key={icon.id} value={icon.id}>
83
83
  {icon.id}
84
84
  </option>
@@ -1,219 +0,0 @@
1
- import '@testing-library/jest-dom'
2
- import * as ReactTestingLibrary from '@testing-library/react'
3
- import { setupPktTestingLibrary } from '@oslokommune/punkt-testing-utils'
4
- import { axe, toHaveNoViolations } from 'jest-axe'
5
- import { PktCombobox } from './Combobox'
6
-
7
- const { getPktElementByLabelText, waitForPktElementsToBeDefined } = setupPktTestingLibrary(ReactTestingLibrary)
8
-
9
- describe('PktCombobox', () => {
10
- beforeAll(() => {
11
- expect.extend(toHaveNoViolations)
12
- })
13
-
14
- beforeEach(() => {
15
- jest.clearAllMocks()
16
- })
17
-
18
- it('renders a basic combobox with label', async () => {
19
- const { container } = ReactTestingLibrary.render(<PktCombobox id="myCombobox" label="My Combobox" allowUserInput />)
20
-
21
- await waitForPktElementsToBeDefined()
22
-
23
- // Check if the label is present in the document
24
- const comboboxLabel = getPktElementByLabelText('My Combobox')
25
- expect(comboboxLabel).toBeInTheDocument()
26
- })
27
- it('renders an error state combobox', async () => {
28
- const { container } = ReactTestingLibrary.render(<PktCombobox id="myCombobox" label="My Combobox" hasError />)
29
-
30
- await waitForPktElementsToBeDefined()
31
-
32
- const comboboxError = getPktElementByLabelText('My Combobox').querySelector('.pkt-combobox__input') as HTMLElement
33
-
34
- // Verify that the error class is applied to the combobox
35
- expect(comboboxError).toHaveClass('pkt-combobox__input--error')
36
- })
37
- it('renders a disabled combobox', async () => {
38
- const { container } = ReactTestingLibrary.render(<PktCombobox id="myCombobox" label="My Combobox" disabled />)
39
-
40
- await waitForPktElementsToBeDefined()
41
-
42
- const comboboxDisabled = getPktElementByLabelText('My Combobox') as HTMLElement
43
-
44
- // Verify that the error class is applied to the combobox
45
- expect(comboboxDisabled).toBeDisabled()
46
- })
47
- it('renders a combobox with default value', async () => {
48
- const { container } = ReactTestingLibrary.render(
49
- <PktCombobox id="myCombobox" label="My Combobox" defaultValue="Option 1" />,
50
- )
51
-
52
- await waitForPktElementsToBeDefined()
53
-
54
- const combobox: HTMLElement = getPktElementByLabelText('My Combobox')
55
-
56
- // Verify that the default value is set
57
- expect(combobox).toHaveAttribute('value', 'Option 1')
58
- })
59
- it('renders a combobox with options', async () => {
60
- const { queryAllByRole } = ReactTestingLibrary.render(
61
- <PktCombobox id="myCombobox" label="My Combobox">
62
- <option value="Option 1">Option 1</option>
63
- <option value="Option 2">Option 2</option>
64
- <option value="Option 3">Option 3</option>
65
- </PktCombobox>,
66
- )
67
- await waitForPktElementsToBeDefined()
68
- const options = queryAllByRole('option')
69
- // Verify that the options are rendered correctly
70
- expect(options).toHaveLength(3)
71
- expect(options[0].textContent).toContain('Option 1')
72
- expect(options[1].textContent).toContain('Option 2')
73
- expect(options[2].textContent).toContain('Option 3')
74
- })
75
- it('handles onChange callback', async () => {
76
- const onChangeMock = jest.fn()
77
- const { container } = ReactTestingLibrary.render(
78
- <PktCombobox id="myCombobox" label="My Combobox" onChange={onChangeMock} allowUserInput />,
79
- )
80
-
81
- await waitForPktElementsToBeDefined()
82
-
83
- // Get the combobox element
84
- const combobox = getPktElementByLabelText('My Combobox')
85
- const comboboxInput = combobox.querySelector('input') as HTMLInputElement
86
-
87
- ReactTestingLibrary.fireEvent.change(comboboxInput, { target: { value: 'New Value' } })
88
-
89
- // Verify that the onChange callback is called
90
- expect(onChangeMock).toHaveBeenCalledTimes(1)
91
- })
92
- it('handles onFocus callback', async () => {
93
- const onFocusMock = jest.fn()
94
- const { container } = ReactTestingLibrary.render(
95
- <PktCombobox id="myCombobox" label="My Combobox" onFocus={onFocusMock} allowUserInput />,
96
- )
97
-
98
- await waitForPktElementsToBeDefined()
99
-
100
- // Get the combobox element
101
- const combobox = getPktElementByLabelText('My Combobox')
102
- const comboboxInput = combobox.querySelector('input') as HTMLInputElement
103
-
104
- // Simulate a focus event on the combobox
105
- ReactTestingLibrary.fireEvent.focus(comboboxInput)
106
-
107
- // Verify that the onFocus callback is called
108
- expect(onFocusMock).toHaveBeenCalledTimes(1)
109
- })
110
- it('handles onBlur callback', async () => {
111
- const onBlurMock = jest.fn()
112
- const { container } = ReactTestingLibrary.render(
113
- <PktCombobox id="myCombobox" label="My Combobox" onBlur={onBlurMock} allowUserInput />,
114
- )
115
-
116
- await waitForPktElementsToBeDefined()
117
-
118
- // Get the combobox element
119
- const combobox = getPktElementByLabelText('My Combobox')
120
- const comboboxInput = combobox.querySelector('input') as HTMLInputElement
121
-
122
- // Simulate a blur event on the combobox
123
- ReactTestingLibrary.fireEvent.blur(comboboxInput)
124
-
125
- // Verify that the onBlur callback is called
126
- expect(onBlurMock).toHaveBeenCalled()
127
- })
128
- it('should not have any accessibility violations', async () => {
129
- const { container } = ReactTestingLibrary.render(<PktCombobox id="myCombobox" label="My Combobox" />)
130
-
131
- await waitForPktElementsToBeDefined()
132
-
133
- const results = await axe(container)
134
-
135
- expect(results).toHaveNoViolations()
136
- })
137
- it('should not have any accessibility violations with options', async () => {
138
- const { container } = ReactTestingLibrary.render(
139
- <PktCombobox id="myCombobox" label="My Combobox">
140
- <option value="Option 1">Option 1</option>
141
- <option value="Option 2">Option 2</option>
142
- <option value="Option 3">Option 3</option>
143
- </PktCombobox>,
144
- )
145
-
146
- await waitForPktElementsToBeDefined()
147
-
148
- const results = await axe(container)
149
-
150
- expect(results).toHaveNoViolations()
151
- })
152
- it('should not have any accessibility violations with options and default value', async () => {
153
- const { container } = ReactTestingLibrary.render(
154
- <PktCombobox id="myCombobox" label="My Combobox" defaultValue="Option 1">
155
- <option value="Option 1">Option 1</option>
156
- <option value="Option 2">Option 2</option>
157
- <option value="Option 3">Option 3</option>
158
- </PktCombobox>,
159
- )
160
-
161
- await waitForPktElementsToBeDefined()
162
-
163
- const results = await axe(container)
164
-
165
- expect(results).toHaveNoViolations()
166
- })
167
- it('should not have any accessibility violations with options and default value and error state', async () => {
168
- const { container } = ReactTestingLibrary.render(
169
- <PktCombobox id="myCombobox" label="My Combobox" defaultValue="Option 1" hasError>
170
- <option value="Option 1">Option 1</option>
171
- <option value="Option 2">Option 2</option>
172
- <option value="Option 3">Option 3</option>
173
- </PktCombobox>,
174
- )
175
-
176
- await waitForPktElementsToBeDefined()
177
-
178
- const results = await axe(container)
179
-
180
- expect(results).toHaveNoViolations()
181
- })
182
- it('should not have any accessibility violations with options and default value and error state and disabled', async () => {
183
- const { container } = ReactTestingLibrary.render(
184
- <PktCombobox id="myCombobox" label="My Combobox" defaultValue="Option 1" hasError disabled>
185
- <option value="Option 1">Option 1</option>
186
- <option value="Option 2">Option 2</option>
187
- <option value="Option 3">Option 3</option>
188
- </PktCombobox>,
189
- )
190
-
191
- await waitForPktElementsToBeDefined()
192
-
193
- const results = await axe(container)
194
-
195
- expect(results).toHaveNoViolations()
196
- })
197
- it('should not have any accessibility violations with options and default value and error state and disabled and placeholder', async () => {
198
- const { container } = ReactTestingLibrary.render(
199
- <PktCombobox
200
- id="myCombobox"
201
- label="My Combobox"
202
- defaultValue="Option 1"
203
- hasError
204
- disabled
205
- placeholder="Select an option"
206
- >
207
- <option value="Option 1">Option 1</option>
208
- <option value="Option 2">Option 2</option>
209
- <option value="Option 3">Option 3</option>
210
- </PktCombobox>,
211
- )
212
-
213
- await waitForPktElementsToBeDefined()
214
-
215
- const results = await axe(container)
216
-
217
- expect(results).toHaveNoViolations()
218
- })
219
- })