@open-mercato/ui 0.6.7-develop.6770.1.b52298cf20 → 0.6.7-develop.6773.1.f9b7fbae4f
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.7-develop.
|
|
3
|
+
"version": "0.6.7-develop.6773.1.f9b7fbae4f",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -155,13 +155,13 @@
|
|
|
155
155
|
"remark-gfm": "^4.0.1"
|
|
156
156
|
},
|
|
157
157
|
"peerDependencies": {
|
|
158
|
-
"@open-mercato/shared": "0.6.7-develop.
|
|
158
|
+
"@open-mercato/shared": "0.6.7-develop.6773.1.f9b7fbae4f",
|
|
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
|
-
"@open-mercato/shared": "0.6.7-develop.
|
|
164
|
+
"@open-mercato/shared": "0.6.7-develop.6773.1.f9b7fbae4f",
|
|
165
165
|
"@testing-library/dom": "^10.4.1",
|
|
166
166
|
"@testing-library/jest-dom": "^6.9.1",
|
|
167
167
|
"@testing-library/react": "^16.3.1",
|
|
@@ -3,8 +3,14 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import * as React from 'react'
|
|
6
|
-
import { render, screen, waitFor } from '@testing-library/react'
|
|
7
|
-
import {
|
|
6
|
+
import { act, render, screen, waitFor } from '@testing-library/react'
|
|
7
|
+
import { emitOrganizationScopeChanged } from '@open-mercato/shared/lib/frontend/organizationEvents'
|
|
8
|
+
import type { BackendChromePayload } from '@open-mercato/shared/modules/navigation/backendChrome'
|
|
9
|
+
import {
|
|
10
|
+
BackendChromeProvider,
|
|
11
|
+
useBackendChrome,
|
|
12
|
+
useCurrentOrganization,
|
|
13
|
+
} from '../BackendChromeProvider'
|
|
8
14
|
import { apiCall } from '../utils/apiCall'
|
|
9
15
|
|
|
10
16
|
jest.mock('../utils/apiCall', () => ({
|
|
@@ -21,6 +27,30 @@ function ChromeStateProbe() {
|
|
|
21
27
|
)
|
|
22
28
|
}
|
|
23
29
|
|
|
30
|
+
function CurrentOrganizationProbe() {
|
|
31
|
+
const organization = useCurrentOrganization()
|
|
32
|
+
return (
|
|
33
|
+
<span data-testid="current-organization">
|
|
34
|
+
{organization ? `${organization.id}:${organization.name}` : 'none'}
|
|
35
|
+
</span>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function makePayload(
|
|
40
|
+
currentOrganization: BackendChromePayload['currentOrganization'],
|
|
41
|
+
): BackendChromePayload {
|
|
42
|
+
return {
|
|
43
|
+
groups: [],
|
|
44
|
+
settingsSections: [],
|
|
45
|
+
settingsPathPrefixes: [],
|
|
46
|
+
profileSections: [],
|
|
47
|
+
profilePathPrefixes: [],
|
|
48
|
+
grantedFeatures: [],
|
|
49
|
+
roles: [],
|
|
50
|
+
currentOrganization,
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
24
54
|
describe('BackendChromeProvider', () => {
|
|
25
55
|
beforeEach(() => {
|
|
26
56
|
;(apiCall as jest.Mock).mockReset()
|
|
@@ -42,4 +72,70 @@ describe('BackendChromeProvider', () => {
|
|
|
42
72
|
expect(screen.getByTestId('ready')).toHaveTextContent('not-ready')
|
|
43
73
|
expect(apiCall).toHaveBeenCalledWith('/api/auth/admin/nav', { credentials: 'include' })
|
|
44
74
|
})
|
|
75
|
+
|
|
76
|
+
it('returns null outside a provider', () => {
|
|
77
|
+
render(<CurrentOrganizationProbe />)
|
|
78
|
+
|
|
79
|
+
expect(screen.getByTestId('current-organization')).toHaveTextContent('none')
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('returns null before the chrome payload arrives', () => {
|
|
83
|
+
;(apiCall as jest.Mock).mockReturnValue(new Promise(() => {}))
|
|
84
|
+
|
|
85
|
+
render(
|
|
86
|
+
<BackendChromeProvider adminNavApi="/api/auth/admin/nav?test=pending">
|
|
87
|
+
<CurrentOrganizationProbe />
|
|
88
|
+
</BackendChromeProvider>,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
expect(screen.getByTestId('current-organization')).toHaveTextContent('none')
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('returns the organization from the hydrated payload', async () => {
|
|
95
|
+
;(apiCall as jest.Mock).mockResolvedValue({
|
|
96
|
+
ok: true,
|
|
97
|
+
result: makePayload({ id: 'org-1', name: 'Northwind Ltd' }),
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
render(
|
|
101
|
+
<BackendChromeProvider adminNavApi="/api/auth/admin/nav?test=hydrated">
|
|
102
|
+
<CurrentOrganizationProbe />
|
|
103
|
+
</BackendChromeProvider>,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
await waitFor(() => {
|
|
107
|
+
expect(screen.getByTestId('current-organization')).toHaveTextContent('org-1:Northwind Ltd')
|
|
108
|
+
})
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('refreshes the organization after the active scope changes', async () => {
|
|
112
|
+
;(apiCall as jest.Mock)
|
|
113
|
+
.mockResolvedValueOnce({
|
|
114
|
+
ok: true,
|
|
115
|
+
result: makePayload({ id: 'org-1', name: 'Northwind Ltd' }),
|
|
116
|
+
})
|
|
117
|
+
.mockResolvedValueOnce({
|
|
118
|
+
ok: true,
|
|
119
|
+
result: makePayload({ id: 'org-2', name: 'Contoso GmbH' }),
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
render(
|
|
123
|
+
<BackendChromeProvider adminNavApi="/api/auth/admin/nav?test=scope-refresh">
|
|
124
|
+
<CurrentOrganizationProbe />
|
|
125
|
+
</BackendChromeProvider>,
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
await waitFor(() => {
|
|
129
|
+
expect(screen.getByTestId('current-organization')).toHaveTextContent('org-1:Northwind Ltd')
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
act(() => {
|
|
133
|
+
emitOrganizationScopeChanged({ organizationId: 'org-2', tenantId: 'tenant-1' })
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
await waitFor(() => {
|
|
137
|
+
expect(screen.getByTestId('current-organization')).toHaveTextContent('org-2:Contoso GmbH')
|
|
138
|
+
})
|
|
139
|
+
expect(apiCall).toHaveBeenCalledTimes(2)
|
|
140
|
+
})
|
|
45
141
|
})
|