@open-mercato/ui 0.10.1-develop.8159.1.71854b31a8 → 0.10.1-develop.8164.1.f12a3857ee
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/dist/backend/FlashMessages.js +2 -2
- package/dist/backend/FlashMessages.js.map +2 -2
- package/dist/backend/detail/AddressEditor.js +6 -2
- package/dist/backend/detail/AddressEditor.js.map +2 -2
- package/dist/backend/detail/AddressTiles.js +7 -0
- package/dist/backend/detail/AddressTiles.js.map +2 -2
- package/dist/backend/detail/AddressesSection.js +10 -5
- package/dist/backend/detail/AddressesSection.js.map +2 -2
- package/dist/backend/inputs/ComboboxInput.js +1 -0
- package/dist/backend/inputs/ComboboxInput.js.map +2 -2
- package/package.json +3 -3
- package/src/backend/FlashMessages.tsx +10 -2
- package/src/backend/__tests__/FlashMessages.test.tsx +41 -0
- package/src/backend/detail/AddressEditor.tsx +11 -2
- package/src/backend/detail/AddressTiles.tsx +7 -0
- package/src/backend/detail/AddressesSection.tsx +12 -6
- package/src/backend/detail/__tests__/AddressEditor.fieldRace.test.tsx +72 -0
- package/src/backend/detail/__tests__/AddressTiles.keyboard.test.tsx +62 -0
- package/src/backend/detail/__tests__/AddressesSection.versionRefresh.test.tsx +106 -0
- package/src/backend/inputs/ComboboxInput.tsx +2 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { act, waitFor } from '@testing-library/react'
|
|
3
|
+
import { renderWithProviders } from '@open-mercato/shared/lib/testing/renderWithProviders'
|
|
4
|
+
import { AddressesSection, type AddressDataAdapter, type AddressSummary } from '../AddressesSection'
|
|
5
|
+
import type { AddressInput } from '../AddressTiles'
|
|
6
|
+
|
|
7
|
+
type TileCallbacks = {
|
|
8
|
+
onCreate: (payload: AddressInput) => Promise<void>
|
|
9
|
+
onUpdate: (id: string, payload: AddressInput) => Promise<void>
|
|
10
|
+
onDelete: (id: string) => Promise<void>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let mockCallbacks: TileCallbacks | null = null
|
|
14
|
+
const mockSurfaceRecordConflict = jest.fn((_error: unknown, _translator: unknown) => false)
|
|
15
|
+
|
|
16
|
+
jest.mock('../../conflicts', () => ({
|
|
17
|
+
surfaceRecordConflict: (error: unknown, translator: unknown) => mockSurfaceRecordConflict(error, translator),
|
|
18
|
+
}))
|
|
19
|
+
|
|
20
|
+
jest.mock('../AddressTiles', () => ({
|
|
21
|
+
__esModule: true,
|
|
22
|
+
default: (props: TileCallbacks) => {
|
|
23
|
+
mockCallbacks = props
|
|
24
|
+
return null
|
|
25
|
+
},
|
|
26
|
+
}))
|
|
27
|
+
jest.mock('@open-mercato/ui/backend/detail', () => ({ LoadingMessage: () => null }))
|
|
28
|
+
jest.mock('@open-mercato/ui/backend/FlashMessages', () => ({ flash: jest.fn() }))
|
|
29
|
+
jest.mock('../../injection/useRegisteredComponent', () => ({
|
|
30
|
+
useRegisteredComponent: (_handle: string, fallback: React.ComponentType) => fallback,
|
|
31
|
+
}))
|
|
32
|
+
|
|
33
|
+
const firstVersion = '2026-11-14T07:00:00.000Z'
|
|
34
|
+
const secondVersion = '2026-11-14T07:01:00.000Z'
|
|
35
|
+
const thirdVersion = '2026-11-14T07:02:00.000Z'
|
|
36
|
+
const payload: AddressInput = { addressLine1: '1 Main Street' }
|
|
37
|
+
const address: AddressSummary = { id: 'address-1', addressLine1: payload.addressLine1, updatedAt: firstVersion }
|
|
38
|
+
|
|
39
|
+
function callbacks(): TileCallbacks {
|
|
40
|
+
if (!mockCallbacks) throw new Error('[internal] address callbacks unavailable')
|
|
41
|
+
return mockCallbacks
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function renderSection(adapter: AddressDataAdapter) {
|
|
45
|
+
mockCallbacks = null
|
|
46
|
+
renderWithProviders(
|
|
47
|
+
<AddressesSection
|
|
48
|
+
entityId="entity-1"
|
|
49
|
+
emptyLabel="No addresses"
|
|
50
|
+
addActionLabel="Add address"
|
|
51
|
+
emptyState={{ title: 'No addresses', actionLabel: 'Add address' }}
|
|
52
|
+
dataAdapter={adapter}
|
|
53
|
+
/>,
|
|
54
|
+
{ dict: { 'ui.forms.flash.recordModified': 'Refresh the record.' } },
|
|
55
|
+
)
|
|
56
|
+
await waitFor(() => expect(mockCallbacks).not.toBeNull())
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
beforeEach(() => {
|
|
60
|
+
mockSurfaceRecordConflict.mockReset().mockReturnValue(false)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
describe('AddressesSection saved versions', () => {
|
|
64
|
+
it('loads a newly created child version before its first update and the next delete', async () => {
|
|
65
|
+
const adapter = {
|
|
66
|
+
list: jest.fn().mockResolvedValueOnce([]).mockResolvedValueOnce([address]).mockResolvedValueOnce([{ ...address, updatedAt: secondVersion }]),
|
|
67
|
+
create: jest.fn(async () => ({ id: address.id })),
|
|
68
|
+
update: jest.fn(async (_input: Parameters<AddressDataAdapter['update']>[0]) => undefined),
|
|
69
|
+
delete: jest.fn(async () => undefined),
|
|
70
|
+
} satisfies AddressDataAdapter
|
|
71
|
+
await renderSection(adapter)
|
|
72
|
+
await act(async () => callbacks().onCreate(payload))
|
|
73
|
+
await act(async () => callbacks().onUpdate(address.id, payload))
|
|
74
|
+
expect(adapter.update).toHaveBeenCalledWith(expect.objectContaining({ id: address.id, updatedAt: firstVersion }))
|
|
75
|
+
await act(async () => callbacks().onDelete(address.id))
|
|
76
|
+
expect(adapter.delete).toHaveBeenCalledWith(expect.objectContaining({ id: address.id, updatedAt: secondVersion }))
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it.each(['update', 'delete'] as const)('localizes a detected %s conflict instead of exposing its code', async (operation) => {
|
|
80
|
+
const adapter = {
|
|
81
|
+
list: jest.fn().mockResolvedValue([address]),
|
|
82
|
+
create: jest.fn(async () => ({ id: address.id })),
|
|
83
|
+
update: jest.fn(async () => { throw new Error('record_modified') }),
|
|
84
|
+
delete: jest.fn(async () => { throw new Error('record_modified') }),
|
|
85
|
+
} satisfies AddressDataAdapter
|
|
86
|
+
await renderSection(adapter)
|
|
87
|
+
mockSurfaceRecordConflict.mockReturnValue(true)
|
|
88
|
+
const mutation = operation === 'update'
|
|
89
|
+
? callbacks().onUpdate(address.id, payload)
|
|
90
|
+
: callbacks().onDelete(address.id)
|
|
91
|
+
await expect(mutation).rejects.toThrow('Refresh the record.')
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('uses the refreshed version on a second edit without a page reload', async () => {
|
|
95
|
+
const adapter = {
|
|
96
|
+
list: jest.fn().mockResolvedValueOnce([address]).mockResolvedValueOnce([{ ...address, updatedAt: secondVersion }]).mockResolvedValueOnce([{ ...address, updatedAt: thirdVersion }]),
|
|
97
|
+
create: jest.fn(async () => ({ id: address.id })),
|
|
98
|
+
update: jest.fn(async (_input: Parameters<AddressDataAdapter['update']>[0]) => undefined),
|
|
99
|
+
delete: jest.fn(async () => undefined),
|
|
100
|
+
} satisfies AddressDataAdapter
|
|
101
|
+
await renderSection(adapter)
|
|
102
|
+
await act(async () => callbacks().onUpdate(address.id, { ...payload, city: 'First edit' }))
|
|
103
|
+
await act(async () => callbacks().onUpdate(address.id, { ...payload, city: 'Second edit' }))
|
|
104
|
+
expect(adapter.update.mock.calls.map(([input]) => input.updatedAt)).toEqual([firstVersion, secondVersion])
|
|
105
|
+
})
|
|
106
|
+
})
|
|
@@ -14,6 +14,7 @@ export type ComboboxOption = {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export type ComboboxInputProps = {
|
|
17
|
+
id?: string
|
|
17
18
|
value: string
|
|
18
19
|
onChange: (next: string) => void
|
|
19
20
|
placeholder?: string
|
|
@@ -69,6 +70,7 @@ function areOptionsEqual(a: ComboboxOption[], b: ComboboxOption[]): boolean {
|
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
export function ComboboxInput({
|
|
73
|
+
id,
|
|
72
74
|
value,
|
|
73
75
|
onChange,
|
|
74
76
|
placeholder,
|