@open-mercato/ui 0.6.8-develop.6924.1.a8d208fcdc → 0.6.8-develop.6925.1.cefa200fa4

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": "@open-mercato/ui",
3
- "version": "0.6.8-develop.6924.1.a8d208fcdc",
3
+ "version": "0.6.8-develop.6925.1.cefa200fa4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -155,14 +155,14 @@
155
155
  "remark-gfm": "^4.0.1"
156
156
  },
157
157
  "peerDependencies": {
158
- "@open-mercato/shared": "0.6.8-develop.6924.1.a8d208fcdc",
158
+ "@open-mercato/shared": "0.6.8-develop.6925.1.cefa200fa4",
159
159
  "react": ">=18.0.0",
160
160
  "react-dom": ">=18.0.0",
161
161
  "react-is": ">=18.0.0"
162
162
  },
163
163
  "devDependencies": {
164
164
  "@figma/code-connect": "^1.3.4",
165
- "@open-mercato/shared": "0.6.8-develop.6924.1.a8d208fcdc",
165
+ "@open-mercato/shared": "0.6.8-develop.6925.1.cefa200fa4",
166
166
  "@testing-library/dom": "^10.4.1",
167
167
  "@testing-library/jest-dom": "^7.0.0",
168
168
  "@testing-library/react": "^16.3.1",
@@ -0,0 +1,97 @@
1
+ /** @jest-environment jsdom */
2
+
3
+ jest.mock('next/navigation', () => ({
4
+ useRouter: () => ({ push: jest.fn() }),
5
+ usePathname: () => '/',
6
+ useSearchParams: () => new URLSearchParams(),
7
+ }))
8
+ jest.mock('remark-gfm', () => ({ __esModule: true, default: {} }))
9
+ jest.mock('../confirm-dialog', () => ({
10
+ useConfirmDialog: () => ({ confirm: jest.fn().mockResolvedValue(true), ConfirmDialogElement: null }),
11
+ }))
12
+ jest.mock('../custom-fields/FieldDefinitionsManager', () => {
13
+ const React = require('react')
14
+ return { __esModule: true, FieldDefinitionsManager: React.forwardRef(() => <div>field definitions</div>) }
15
+ })
16
+ jest.mock('../utils/customFieldForms', () => ({
17
+ __esModule: true,
18
+ buildFormFieldFromCustomFieldDef: jest.fn(() => null),
19
+ buildFormFieldsFromCustomFields: jest.fn(() => []),
20
+ fetchCustomFieldFormStructure: jest.fn(async () => ({
21
+ fields: [],
22
+ definitions: [],
23
+ metadata: { items: [], fieldsetsByEntity: {}, entitySettings: {} },
24
+ })),
25
+ }))
26
+
27
+ import * as React from 'react'
28
+ import { fireEvent, screen, waitFor } from '@testing-library/react'
29
+ import { renderWithProviders } from '@open-mercato/shared/lib/testing/renderWithProviders'
30
+ import { CrudForm, type CrudField } from '../CrudForm'
31
+
32
+ const dict = { 'ui.forms.actions.save': 'Save' }
33
+
34
+ const fields: CrudField[] = [
35
+ { id: 'name', label: 'Name', type: 'text' },
36
+ { id: 'isActive', label: 'Active', type: 'checkbox' },
37
+ ]
38
+
39
+ /**
40
+ * A checkbox seeded `false` must be able to reach `true`. The users edit form uses this
41
+ * to reactivate a deactivated account, so a stuck-off checkbox would let an operator
42
+ * deactivate someone with no way back.
43
+ */
44
+ describe('CrudForm checkbox toggling', () => {
45
+ it('submits true after toggling a checkbox that started false', async () => {
46
+ const onSubmit = jest.fn().mockResolvedValue(undefined)
47
+
48
+ renderWithProviders(
49
+ <CrudForm
50
+ title="Test"
51
+ fields={fields}
52
+ initialValues={{ name: 'thing', isActive: false }}
53
+ onSubmit={onSubmit}
54
+ submitLabel="Save"
55
+ />,
56
+ { dict },
57
+ )
58
+
59
+ const checkbox = await screen.findByRole('checkbox')
60
+ expect(checkbox).toHaveAttribute('data-state', 'unchecked')
61
+
62
+ fireEvent.click(checkbox)
63
+
64
+ await waitFor(() => expect(checkbox).toHaveAttribute('data-state', 'checked'))
65
+
66
+ fireEvent.click(screen.getAllByRole('button', { name: 'Save' })[0])
67
+
68
+ await waitFor(() => expect(onSubmit).toHaveBeenCalled())
69
+ expect(onSubmit.mock.calls[0][0]).toMatchObject({ isActive: true })
70
+ })
71
+
72
+ it('submits false after clearing a checkbox that started true', async () => {
73
+ const onSubmit = jest.fn().mockResolvedValue(undefined)
74
+
75
+ renderWithProviders(
76
+ <CrudForm
77
+ title="Test"
78
+ fields={fields}
79
+ initialValues={{ name: 'thing', isActive: true }}
80
+ onSubmit={onSubmit}
81
+ submitLabel="Save"
82
+ />,
83
+ { dict },
84
+ )
85
+
86
+ const checkbox = await screen.findByRole('checkbox')
87
+ expect(checkbox).toHaveAttribute('data-state', 'checked')
88
+
89
+ fireEvent.click(checkbox)
90
+ await waitFor(() => expect(checkbox).toHaveAttribute('data-state', 'unchecked'))
91
+
92
+ fireEvent.click(screen.getAllByRole('button', { name: 'Save' })[0])
93
+
94
+ await waitFor(() => expect(onSubmit).toHaveBeenCalled())
95
+ expect(onSubmit.mock.calls[0][0]).toMatchObject({ isActive: false })
96
+ })
97
+ })