@antelopejs/dms-database 0.5.0 → 0.5.2

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 (45) hide show
  1. package/README.md +4 -5
  2. package/dist/config.d.ts +2 -2
  3. package/dist/config.js.map +1 -1
  4. package/dist/db/models/diagram_layouts.model.js +1 -10
  5. package/dist/db/models/diagram_layouts.model.js.map +1 -1
  6. package/dist/routes/connections.js +7 -2
  7. package/dist/routes/connections.js.map +1 -1
  8. package/dist/routes/data.js +4 -1
  9. package/dist/routes/data.js.map +1 -1
  10. package/dist/service/builderRefusal.d.ts +2 -0
  11. package/dist/service/builderRefusal.js +28 -0
  12. package/dist/service/builderRefusal.js.map +1 -0
  13. package/dist/service/connectionRefusals.d.ts +17 -0
  14. package/dist/service/connectionRefusals.js +26 -0
  15. package/dist/service/connectionRefusals.js.map +1 -0
  16. package/dist/service/connectionState.d.ts +0 -2
  17. package/dist/service/connectionState.js +21 -11
  18. package/dist/service/connectionState.js.map +1 -1
  19. package/dist/service/connections.js +3 -2
  20. package/dist/service/connections.js.map +1 -1
  21. package/frontend-vue/app/build/components/DataGridFooter.vue +16 -1
  22. package/frontend-vue/app/build/composables/reloadForSelection.ts +3 -5
  23. package/frontend-vue/app/build/composables/useDataBrowserGrid.ts +1 -0
  24. package/frontend-vue/app/build/composables/useDataBrowserTabs.ts +91 -15
  25. package/frontend-vue/app/build/data/gridData.ts +22 -1
  26. package/frontend-vue/app/build/data/recentTables.ts +15 -14
  27. package/frontend-vue/app/build/data/useStagedSave.ts +0 -3
  28. package/frontend-vue/app/components/DataBrowser.vue +9 -14
  29. package/frontend-vue/app/components/DataBrowserSidebar.vue +1 -0
  30. package/frontend-vue/app/components/DataGrid.vue +5 -12
  31. package/frontend-vue/app/components/DatabaseSwitcher.vue +0 -2
  32. package/frontend-vue/app/components/TableInspector.vue +11 -6
  33. package/frontend-vue/i18n/locales/database-en-GB.json +12 -0
  34. package/frontend-vue/i18n/locales/database-fr-FR.json +12 -0
  35. package/frontend-vue/package.json +1 -1
  36. package/frontend-vue/pnpm-lock.yaml +5 -5
  37. package/frontend-vue/tests/dataBrowserDatabase.test.ts +89 -0
  38. package/frontend-vue/tests/databaseSwitcher.test.ts +11 -7
  39. package/frontend-vue/tests/editRequest.test.ts +0 -51
  40. package/frontend-vue/tests/externalBrowser.test.ts +125 -0
  41. package/frontend-vue/tests/persistence.test.ts +254 -4
  42. package/frontend-vue/tests/recentTables.test.ts +70 -0
  43. package/frontend-vue/tests/serverRender.test.ts +22 -0
  44. package/package.json +7 -7
  45. package/frontend-vue/app/build/data/staleDatabase.ts +0 -58
@@ -67,10 +67,11 @@ async function mountSwitcher(
67
67
 
68
68
  type Listener = () => void
69
69
 
70
+ const PAGE_PATH = '/modules/database/data'
71
+
70
72
  /** A window and a document that record what the page listens for, and the reloads and navigations it makes. */
71
73
  function stubBrowser(visibility: 'visible' | 'hidden' = 'visible') {
72
74
  const assign = vi.fn()
73
- const reload = vi.fn()
74
75
  const removeItem = vi.fn()
75
76
  const listeners = new Map<string, Listener[]>()
76
77
  const target = {
@@ -80,13 +81,12 @@ function stubBrowser(visibility: 'visible' | 'hidden' = 'visible') {
80
81
  }
81
82
  vi.stubGlobal('window', {
82
83
  ...target,
83
- location: { assign, reload },
84
+ location: { assign, pathname: PAGE_PATH },
84
85
  sessionStorage: { removeItem },
85
86
  })
86
87
  vi.stubGlobal('document', { ...target, visibilityState: visibility })
87
88
  return {
88
89
  assign,
89
- reload,
90
90
  removeItem,
91
91
  fire: (type: string) => {
92
92
  for (const listener of listeners.get(type) ?? []) listener()
@@ -273,12 +273,14 @@ describe('database switcher: another tab switched the database', () => {
273
273
  const mountWithServer = (server: ReturnType<typeof serverSelecting>) =>
274
274
  mountSwitcher(server.answers)
275
275
 
276
- it('reloads when the window regains focus on another selection, which an implementation that only reads at load gets wrong', async () => {
276
+ it('reloads the page without its query when the window regains focus on another selection, which an implementation that only reads at load, or reloads the table the URL names, gets wrong', async () => {
277
277
  const server = serverSelecting(OWN)
278
278
  await mountWithServer(server)
279
279
  server.select(WAREHOUSE)
280
280
  browser.fire('focus')
281
- await vi.waitFor(() => expect(browser.reload).toHaveBeenCalledOnce())
281
+ await vi.waitFor(() =>
282
+ expect(browser.assign).toHaveBeenCalledExactlyOnceWith(PAGE_PATH),
283
+ )
282
284
  expect(browser.removeItem).toHaveBeenCalled()
283
285
  })
284
286
 
@@ -287,7 +289,9 @@ describe('database switcher: another tab switched the database', () => {
287
289
  await mountWithServer(server)
288
290
  server.select(WAREHOUSE)
289
291
  browser.fire('visibilitychange')
290
- await vi.waitFor(() => expect(browser.reload).toHaveBeenCalledOnce())
292
+ await vi.waitFor(() =>
293
+ expect(browser.assign).toHaveBeenCalledExactlyOnceWith(PAGE_PATH),
294
+ )
291
295
  })
292
296
 
293
297
  it('does not reload when the selection is the one the page loaded with, which an implementation that reloads on every focus gets wrong', async () => {
@@ -297,7 +301,7 @@ describe('database switcher: another tab switched the database', () => {
297
301
  browser.fire('focus')
298
302
  await vi.waitFor(() => expect(page.reads.length).toBeGreaterThan(before))
299
303
  await new Promise((resolve) => setTimeout(resolve, 0))
300
- expect(browser.reload).not.toHaveBeenCalled()
304
+ expect(browser.assign).not.toHaveBeenCalled()
301
305
  })
302
306
  })
303
307
 
@@ -20,8 +20,6 @@ import { useStagedEdits } from '../app/build/data/stagedEdits'
20
20
  import { useStagedSave } from '../app/build/data/useStagedSave'
21
21
 
22
22
  const EDIT_URL = '/api/database/browse/edit'
23
- const STALE_MESSAGE =
24
- 'The selected database changed in another tab: reload the page'
25
23
  const TAB: BrowserTab = {
26
24
  id: 'public::__DEFAULT__::orders',
27
25
  schema: 'public',
@@ -94,53 +92,4 @@ describe('the edit request', () => {
94
92
  })
95
93
  },
96
94
  )
97
-
98
- it.each([
99
- ['as text, the way the API sends it', STALE_MESSAGE],
100
- ['as JSON', { message: STALE_MESSAGE }],
101
- ])(
102
- 'presents the refusal of a write from a stale tab, %s, as a translated error, which an implementation showing the generic failure gets wrong',
103
- async (_shape, data) => {
104
- const stale = Object.assign(new Error('Conflict'), {
105
- statusCode: 409,
106
- data,
107
- })
108
- await expect(
109
- saveAnEdit(
110
- backendFor(OWN, () => {
111
- throw stale
112
- }),
113
- ),
114
- ).rejects.toMatchObject({
115
- statusCode: 409,
116
- data: { message: 'dms_database.data.save.database_changed' },
117
- })
118
- },
119
- )
120
-
121
- it.each([
122
- ['as text, the way the API sends it', 'Access to warehouse is read only'],
123
- ['as JSON', { message: 'Access to warehouse is read only' }],
124
- ])(
125
- 'presents the refusal of a write to a connection back to read-only access, %s, as a translated error naming the connection, which an implementation showing the generic failure gets wrong',
126
- async (_shape, data) => {
127
- const refused = Object.assign(new Error('Forbidden'), {
128
- statusCode: 403,
129
- data,
130
- })
131
- await expect(
132
- saveAnEdit(
133
- backendFor(WAREHOUSE, () => {
134
- throw refused
135
- }),
136
- ),
137
- ).rejects.toMatchObject({
138
- statusCode: 403,
139
- data: {
140
- message: 'dms_database.data.save.read_only_access',
141
- params: { connection: 'warehouse' },
142
- },
143
- })
144
- },
145
- )
146
95
  })
@@ -16,6 +16,7 @@ import {
16
16
  import type { DatabaseConnection } from '../app/build/composables/useDatabaseConnections'
17
17
  import DataBrowserSidebar from '../app/components/DataBrowserSidebar.vue'
18
18
  import DataGrid from '../app/components/DataGrid.vue'
19
+ import TableInspector from '../app/components/TableInspector.vue'
19
20
 
20
21
  const PICKER = 'data-dms-database-instance-picker'
21
22
  const TAB = {
@@ -144,6 +145,30 @@ describe('data browser sidebar', () => {
144
145
  expect(page.text()).not.toContain(PICKER)
145
146
  expect(page.text()).not.toContain('dms_database.data.scope.instance')
146
147
  })
148
+
149
+ it('names the instance its counts are for on the project database only, which an external database without instances would otherwise read as default', async () => {
150
+ const COUNTS_FOR = 'dms_database.data.scope.counts_for'
151
+ expect((await sidebar(OWN)).text()).toContain(COUNTS_FOR)
152
+ expect((await sidebar(WAREHOUSE)).text()).not.toContain(COUNTS_FOR)
153
+ })
154
+
155
+ it('still warns that the counts failed on an external database, which a footer hidden for every external database gets wrong', async () => {
156
+ const page = browserMount(
157
+ DataBrowserSidebar,
158
+ connectionsBackend(connectionsState(WAREHOUSE), {
159
+ others: (read) => {
160
+ if (read.url === '/api/database/browse/tables')
161
+ throw Object.assign(new Error('down'), { statusCode: 500 })
162
+ return { items: [] }
163
+ },
164
+ }),
165
+ { schemas: [{ id: 'erp', tables: [] }], loading: false, error: false },
166
+ )
167
+ await page.shown
168
+ await vi.waitFor(() =>
169
+ expect(page.text()).toContain('dms_database.data.scope.counts_failed'),
170
+ )
171
+ })
147
172
  })
148
173
 
149
174
  describe('a read-only external database in the data grid', () => {
@@ -191,3 +216,103 @@ describe('a read-only external database in the data grid', () => {
191
216
  expect(cursor).not.toContain('cursor-not-allowed')
192
217
  })
193
218
  })
219
+
220
+ describe('a capped page of an external database in the data grid', () => {
221
+ async function gridText(capped: boolean, search = '') {
222
+ const page = browserMount(
223
+ DataGrid,
224
+ connectionsBackend(connectionsState(WAREHOUSE), {
225
+ others: (read) =>
226
+ read.url === '/api/database/browse/list'
227
+ ? { results: [{ _id: '1' }], total: 1, primaryKey: '_id', capped }
228
+ : others(read),
229
+ }),
230
+ { tab: TAB },
231
+ )
232
+ await page.shown
233
+ await vi.waitFor(() =>
234
+ expect(page.text()).toContain('dms_database.data.grid.rows 1'),
235
+ )
236
+ if (search) {
237
+ const input = page.find(
238
+ (props) => props.placeholder === 'dms_database.data.grid.search',
239
+ )?.['onUpdate:modelValue']
240
+ if (typeof input === 'function') input(search)
241
+ await vi.waitFor(
242
+ () =>
243
+ expect(page.reads.map((read) => read.query.search)).toContain(search),
244
+ { timeout: 2000 },
245
+ )
246
+ }
247
+ return page.text()
248
+ }
249
+
250
+ it('says a search matches among the first rows only, which a grid that drops the API cap gets wrong', async () => {
251
+ expect(await gridText(true, 'retail')).toContain(
252
+ 'dms_database.data.grid.capped 10000',
253
+ )
254
+ })
255
+
256
+ it('says the count stops at the cap on a page with no search, where nothing is matched', async () => {
257
+ const text = await gridText(true)
258
+ expect(text).toContain('dms_database.data.grid.count_capped 10000')
259
+ expect(text).not.toContain('dms_database.data.grid.capped')
260
+ })
261
+
262
+ it('says nothing of a cap on a page that read every row', async () => {
263
+ expect(await gridText(false)).not.toMatch(/grid\.(count_)?capped/)
264
+ })
265
+ })
266
+
267
+ const SAMPLE_POSITION = 'dms_database.inspector.sample.position'
268
+
269
+ async function samplePosition(connection: DatabaseConnection) {
270
+ const page = browserMount(
271
+ TableInspector,
272
+ connectionsBackend(connectionsState(connection), {
273
+ others: ({ url }) => {
274
+ if (url === '/api/database/schemas')
275
+ return {
276
+ schemas: [
277
+ {
278
+ id: 'shop',
279
+ options: {},
280
+ tables: [
281
+ {
282
+ name: 'orders',
283
+ fields: { _id: { kind: 'string' } },
284
+ indexes: {},
285
+ relations: [],
286
+ },
287
+ ],
288
+ stats: { tableCount: 1, elementCount: 3, instanceCount: 0 },
289
+ instances: [],
290
+ },
291
+ ],
292
+ }
293
+ if (url === '/api/database/browse/count') return { total: 3 }
294
+ if (url === '/api/database/browse/list')
295
+ return { results: [{ _id: '1' }], total: 3, primaryKey: '_id' }
296
+ return { items: [] }
297
+ },
298
+ }),
299
+ { rowData: { schema: 'shop', name: 'orders' } },
300
+ )
301
+ await page.shown
302
+ await vi.waitFor(() => {
303
+ const tabs = page.find((props) => Array.isArray(props.items))
304
+ ;(tabs?.['onUpdate:modelValue'] as (value: string) => void)('sample')
305
+ expect(page.text()).toContain(SAMPLE_POSITION)
306
+ })
307
+ return page.text()
308
+ }
309
+
310
+ describe('the Schemas drawer sample row', () => {
311
+ it('names the instance on the project database only, which a position reading default instance on an external database gets wrong', async () => {
312
+ const own = await samplePosition(OWN)
313
+ expect(own).toContain(`${SAMPLE_POSITION} `)
314
+ const external = await samplePosition(WAREHOUSE)
315
+ expect(external).toContain(`${SAMPLE_POSITION}_uninstanced`)
316
+ expect(external).not.toContain(`${SAMPLE_POSITION} `)
317
+ })
318
+ })
@@ -1,6 +1,7 @@
1
1
  import { afterEach, describe, expect, it, vi } from 'vitest'
2
2
  import { computed, reactive, ref } from 'vue'
3
3
  import { useDataBrowserTabs } from '../app/build/composables/useDataBrowserTabs'
4
+ import { useStagedEdits } from '../app/build/data/stagedEdits'
4
5
 
5
6
  afterEach(() => vi.unstubAllGlobals())
6
7
 
@@ -21,6 +22,7 @@ it('restores browser session tabs and persists a new permanent tab', () => {
21
22
  sessionStorage: {
22
23
  getItem: () =>
23
24
  JSON.stringify({
25
+ database: 'own',
24
26
  tabs: [{ schema: 'sales', instance: 'eu', table: 'orders' }],
25
27
  activeId: null,
26
28
  }),
@@ -28,7 +30,7 @@ it('restores browser session tabs and persists a new permanent tab', () => {
28
30
  },
29
31
  })
30
32
  const browser = useDataBrowserTabs()
31
- browser.restore()
33
+ browser.restore('own')
32
34
  expect(browser.activeId.value).toBe('sales::eu::orders')
33
35
  browser.openTab('audit', 'us', 'events', false)
34
36
  expect(browser.tabs.value.map((tab) => tab.id)).toEqual([
@@ -40,6 +42,253 @@ it('restores browser session tabs and persists a new permanent tab', () => {
40
42
  expect(JSON.parse(payload).activeId).toBe('audit::us::events')
41
43
  })
42
44
 
45
+ it('drops the tabs kept on another database', () => {
46
+ setup()
47
+ const setItem = vi.fn()
48
+ vi.stubGlobal('window', {
49
+ sessionStorage: {
50
+ getItem: () =>
51
+ JSON.stringify({
52
+ database: 'warehouse',
53
+ tabs: [{ schema: 'sales', instance: 'eu', table: 'orders' }],
54
+ activeId: 'sales::eu::orders',
55
+ }),
56
+ setItem,
57
+ },
58
+ })
59
+ const browser = useDataBrowserTabs()
60
+ browser.restore('own')
61
+ expect(browser.tabs.value).toEqual([])
62
+ expect(browser.activeId.value).toBeNull()
63
+ browser.openTab('audit', 'us', 'events', false)
64
+ expect(JSON.parse(setItem.mock.lastCall![1])).toMatchObject({
65
+ database: 'own',
66
+ tabs: [expect.objectContaining({ id: 'audit::us::events' })],
67
+ })
68
+ })
69
+
70
+ function storing(saved: object) {
71
+ let raw = JSON.stringify(saved)
72
+ vi.stubGlobal('window', {
73
+ sessionStorage: {
74
+ getItem: () => raw,
75
+ setItem: (_key: string, value: string) => {
76
+ raw = value
77
+ },
78
+ },
79
+ })
80
+ }
81
+
82
+ it('drops a tab set saved with no database', () => {
83
+ setup()
84
+ storing({
85
+ tabs: [{ schema: 'sales', instance: 'eu', table: 'orders' }],
86
+ activeId: null,
87
+ })
88
+ const browser = useDataBrowserTabs()
89
+ browser.restore('own')
90
+ expect(browser.tabs.value).toEqual([])
91
+ })
92
+
93
+ it('drops the open tabs of another database when the page comes back to it without a reload', () => {
94
+ setup()
95
+ const states = new Map<string, unknown>()
96
+ vi.stubGlobal('useDmsState', (key: string, init: () => unknown) => {
97
+ if (!states.has(key)) states.set(key, ref(init()))
98
+ return states.get(key)
99
+ })
100
+ storing({ database: 'own', tabs: [], activeId: null })
101
+ const before = useDataBrowserTabs()
102
+ before.restore('own')
103
+ before.openTab('shop', 'eu', 'orders', false)
104
+ const after = useDataBrowserTabs()
105
+ after.restore('warehouse')
106
+ expect(after.tabs.value).toEqual([])
107
+ after.openTab('audit', 'us', 'events', false)
108
+ expect(after.tabs.value.map((tab) => tab.id)).toEqual(['audit::us::events'])
109
+ })
110
+
111
+ it('discards the staged edits of the open tabs it drops', () => {
112
+ setup()
113
+ const states = new Map<string, unknown>()
114
+ vi.stubGlobal('useDmsState', (key: string, init: () => unknown) => {
115
+ if (!states.has(key)) states.set(key, ref(init()))
116
+ return states.get(key)
117
+ })
118
+ storing({ database: 'own', tabs: [], activeId: null })
119
+ const before = useDataBrowserTabs()
120
+ before.restore('own')
121
+ before.openTab('shop', 'eu', 'orders', false)
122
+ useStagedEdits().stage('shop::eu::orders', {
123
+ rowId: 'r1',
124
+ field: 'total',
125
+ before: 1,
126
+ after: 999,
127
+ })
128
+ const after = useDataBrowserTabs()
129
+ after.restore('warehouse')
130
+ after.openTab('shop', 'eu', 'orders', false)
131
+ expect(useStagedEdits().list('shop::eu::orders')).toEqual([])
132
+ })
133
+
134
+ it('forgets the dropped set, so a load with an unknown selection does not reopen it', () => {
135
+ setup()
136
+ storing({
137
+ database: 'own',
138
+ tabs: [{ schema: 'sales', instance: 'eu', table: 'orders' }],
139
+ activeId: null,
140
+ })
141
+ useDataBrowserTabs().restore('warehouse')
142
+ setup()
143
+ const reloaded = useDataBrowserTabs()
144
+ reloaded.restore(undefined)
145
+ expect(reloaded.tabs.value).toEqual([])
146
+ })
147
+
148
+ it('drops the open tab, its saved set and its URL when the selection changes once mounted', () => {
149
+ setup()
150
+ const route = reactive({ query: {} as Record<string, string> })
151
+ const replace = vi.fn(({ query }: { query: Record<string, string> }) => {
152
+ route.query = query
153
+ })
154
+ vi.stubGlobal('useDmsRoute', () => route)
155
+ vi.stubGlobal('useDmsRouter', () => ({ replace }))
156
+ let raw = ''
157
+ vi.stubGlobal('window', {
158
+ sessionStorage: {
159
+ getItem: () => raw || null,
160
+ setItem: (_key: string, value: string) => {
161
+ raw = value
162
+ },
163
+ },
164
+ })
165
+ const browser = useDataBrowserTabs()
166
+ browser.restore('own')
167
+ browser.openTab('shop', 'eu', 'orders', false)
168
+ expect(route.query).toEqual({
169
+ schema: 'shop',
170
+ table: 'orders',
171
+ instance: 'eu',
172
+ })
173
+ browser.follow('warehouse')
174
+ expect(browser.tabs.value).toEqual([])
175
+ expect(route.query).toEqual({})
176
+ expect(JSON.parse(raw)).toEqual({
177
+ database: 'warehouse',
178
+ tabs: [],
179
+ activeId: null,
180
+ })
181
+ expect(browser.openFromRoute()).toBe(false)
182
+ })
183
+
184
+ it('clears a URL that mirrors a tab of another database instead of opening it again on a reload', () => {
185
+ setup()
186
+ const route = reactive({
187
+ query: { schema: 'sales', table: 'orders', instance: 'eu' } as Record<
188
+ string,
189
+ string
190
+ >,
191
+ })
192
+ vi.stubGlobal('useDmsRoute', () => route)
193
+ vi.stubGlobal('useDmsRouter', () => ({
194
+ replace: ({ query }: { query: Record<string, string> }) => {
195
+ route.query = query
196
+ },
197
+ }))
198
+ let raw = JSON.stringify({
199
+ database: 'own',
200
+ tabs: [{ schema: 'sales', instance: 'eu', table: 'orders' }],
201
+ activeId: 'sales::eu::orders',
202
+ })
203
+ vi.stubGlobal('window', {
204
+ sessionStorage: {
205
+ getItem: () => raw,
206
+ setItem: (_key: string, value: string) => {
207
+ raw = value
208
+ },
209
+ },
210
+ })
211
+ const browser = useDataBrowserTabs()
212
+ browser.restore('warehouse')
213
+ expect(browser.tabs.value).toEqual([])
214
+ expect(route.query).toEqual({})
215
+ expect(JSON.parse(raw)).toEqual({
216
+ database: 'warehouse',
217
+ tabs: [],
218
+ activeId: null,
219
+ })
220
+ })
221
+
222
+ it('keeps a tab opened while the selection was unknown once the selection is known, which a follow treating an unknown database as another one gets wrong', () => {
223
+ setup()
224
+ let raw = ''
225
+ vi.stubGlobal('window', {
226
+ sessionStorage: {
227
+ getItem: () => raw || null,
228
+ setItem: (_key: string, value: string) => {
229
+ raw = value
230
+ },
231
+ },
232
+ })
233
+ const browser = useDataBrowserTabs()
234
+ browser.restore(undefined)
235
+ browser.openTab('shop', 'eu', 'orders', false)
236
+ browser.follow('own')
237
+ expect(browser.tabs.value.map((tab) => tab.id)).toEqual(['shop::eu::orders'])
238
+ expect(JSON.parse(raw)).toMatchObject({
239
+ database: 'own',
240
+ tabs: [expect.objectContaining({ id: 'shop::eu::orders' })],
241
+ })
242
+ })
243
+
244
+ it('keeps a tab opened while the selection is unknown across a reload where it is still unknown, which a reader refusing a set of no known database gets wrong', () => {
245
+ setup()
246
+ let raw = ''
247
+ vi.stubGlobal('window', {
248
+ sessionStorage: {
249
+ getItem: () => raw || null,
250
+ setItem: (_key: string, value: string) => {
251
+ raw = value
252
+ },
253
+ },
254
+ })
255
+ const first = useDataBrowserTabs()
256
+ first.restore(undefined)
257
+ first.openTab('shop', '__DEFAULT__', 'orders', false)
258
+ setup()
259
+ const reloaded = useDataBrowserTabs()
260
+ reloaded.restore(undefined)
261
+ expect(reloaded.tabs.value.map((tab) => tab.id)).toEqual([
262
+ 'shop::__DEFAULT__::orders',
263
+ ])
264
+ setup()
265
+ const known = useDataBrowserTabs()
266
+ known.restore('own')
267
+ expect(known.tabs.value.map((tab) => tab.id)).toEqual([
268
+ 'shop::__DEFAULT__::orders',
269
+ ])
270
+ expect(JSON.parse(raw)).toMatchObject({ database: 'own' })
271
+ })
272
+
273
+ it('keeps the tabs when the selected database is unknown', () => {
274
+ setup()
275
+ storing({
276
+ database: 'warehouse',
277
+ tabs: [{ schema: 'sales', instance: 'eu', table: 'orders' }],
278
+ activeId: null,
279
+ })
280
+ const browser = useDataBrowserTabs()
281
+ browser.restore(undefined)
282
+ expect(browser.tabs.value.map((tab) => tab.id)).toEqual(['sales::eu::orders'])
283
+ browser.openTab('audit', 'us', 'events', false)
284
+ const reloaded = useDataBrowserTabs()
285
+ reloaded.restore('warehouse')
286
+ expect(reloaded.tabs.value.map((tab) => tab.id)).toEqual([
287
+ 'sales::eu::orders',
288
+ 'audit::us::events',
289
+ ])
290
+ })
291
+
43
292
  it('retains usable tabs when session storage is unavailable', () => {
44
293
  setup()
45
294
  const deny = () => {
@@ -47,7 +296,7 @@ it('retains usable tabs when session storage is unavailable', () => {
47
296
  }
48
297
  vi.stubGlobal('window', { sessionStorage: { getItem: deny, setItem: deny } })
49
298
  const browser = useDataBrowserTabs()
50
- browser.restore()
299
+ browser.restore('own')
51
300
  browser.openTab('sales', 'eu', 'orders', false)
52
301
  expect(browser.activeId.value).toBe('sales::eu::orders')
53
302
  })
@@ -65,7 +314,7 @@ it('does not revisit an already selected deep link while restoring tabs', () =>
65
314
  },
66
315
  }))
67
316
  const browser = useDataBrowserTabs()
68
- browser.restore()
317
+ browser.restore('own')
69
318
  expect(browser.activeId.value).toBe('sales::eu::orders')
70
319
  expect(replace).not.toHaveBeenCalled()
71
320
  browser.openTab('sales', 'us', 'orders', false)
@@ -90,6 +339,7 @@ it('restores the preview tab as a preview, the URL naming it included', () => {
90
339
  sessionStorage: {
91
340
  getItem: () =>
92
341
  JSON.stringify({
342
+ database: 'own',
93
343
  tabs: [
94
344
  { schema: 'sales', instance: 'eu', table: 'customers' },
95
345
  {
@@ -105,7 +355,7 @@ it('restores the preview tab as a preview, the URL naming it included', () => {
105
355
  },
106
356
  })
107
357
  const browser = useDataBrowserTabs()
108
- browser.restore()
358
+ browser.restore('own')
109
359
  expect(browser.activeId.value).toBe('sales::eu::orders')
110
360
  expect(browser.tabs.value.map((tab) => tab.preview)).toEqual([false, true])
111
361
  expect(replace).not.toHaveBeenCalled()
@@ -0,0 +1,70 @@
1
+ import { afterEach, expect, it, vi } from 'vitest'
2
+ import { computed, ref } from 'vue'
3
+ import { useDataBrowserTabs } from '../app/build/composables/useDataBrowserTabs'
4
+
5
+ afterEach(() => vi.unstubAllGlobals())
6
+
7
+ /** A browser whose session and local storage keep what the page writes. */
8
+ function browsing() {
9
+ const storage = () => {
10
+ const items = new Map<string, string>()
11
+ return {
12
+ getItem: (key: string) => items.get(key) ?? null,
13
+ setItem: (key: string, value: string) => void items.set(key, value),
14
+ removeItem: (key: string) => void items.delete(key),
15
+ }
16
+ }
17
+ vi.stubGlobal('useDmsState', (_key: string, init: () => unknown) =>
18
+ ref(init()),
19
+ )
20
+ vi.stubGlobal('computed', computed)
21
+ vi.stubGlobal('useDmsRoute', () => ({ query: {} }))
22
+ vi.stubGlobal('useDmsRouter', () => ({ replace: vi.fn() }))
23
+ vi.stubGlobal('useDataBrowserGrid', () => ({ drop: vi.fn() }))
24
+ vi.stubGlobal('window', {
25
+ sessionStorage: storage(),
26
+ localStorage: storage(),
27
+ })
28
+ }
29
+
30
+ /** The tables the empty state offers, as `schema.table`. */
31
+ function offered(browser: ReturnType<typeof useDataBrowserTabs>): string[] {
32
+ return browser.recent.value.map((entry) => `${entry.schema}.${entry.table}`)
33
+ }
34
+
35
+ it('P2: after follow drops the old database tabs, the empty state offers none of its tables', () => {
36
+ browsing()
37
+ const browser = useDataBrowserTabs()
38
+ browser.restore('own')
39
+ browser.openTab('shop', 'eu', 'orders', false)
40
+ browser.closeTab('shop::eu::orders')
41
+ expect(offered(browser)).toEqual(['shop.orders'])
42
+ browser.follow('warehouse')
43
+ expect(offered(browser)).toEqual([])
44
+ browser.openTab('public', '__DEFAULT__', 'invoices', false)
45
+ expect(offered(browser)).toEqual(['public.invoices'])
46
+ })
47
+
48
+ it('offers on a reload only the tables of the selected database, and those of the previous one once it is selected again, which one list for every database gets wrong', () => {
49
+ browsing()
50
+ const before = useDataBrowserTabs()
51
+ before.restore('own')
52
+ before.openTab('shop', 'eu', 'orders', false)
53
+ const switched = useDataBrowserTabs()
54
+ switched.restore('warehouse')
55
+ expect(offered(switched)).toEqual([])
56
+ switched.openTab('public', '__DEFAULT__', 'invoices', false)
57
+ const back = useDataBrowserTabs()
58
+ back.restore('own')
59
+ expect(offered(back)).toEqual(['shop.orders'])
60
+ })
61
+
62
+ it('offers no table while no database is known, which tables remembered under no database get wrong', () => {
63
+ browsing()
64
+ const browser = useDataBrowserTabs()
65
+ browser.restore(undefined)
66
+ browser.openTab('shop', 'eu', 'orders', false)
67
+ expect(offered(browser)).toEqual([])
68
+ browser.follow('warehouse')
69
+ expect(offered(browser)).toEqual([])
70
+ })
@@ -267,6 +267,28 @@ describe('server render: every read is handed to the browser', () => {
267
267
  expect(page.html).not.toContain('dms_database.inspector.actions.diagram')
268
268
  })
269
269
 
270
+ it('table inspector: counts instances on the project database only, which an inspector reading 1 instance on an external database gets wrong', async () => {
271
+ const INSTANCES = 'dms_database.inspector.instances'
272
+ const own = await render(
273
+ TableInspector,
274
+ { rowData: { schema: 'shop', name: 'orders' } },
275
+ '/modules/database/schemas',
276
+ )
277
+ expect(own.html).toContain(INSTANCES)
278
+ const external = await serverRender(
279
+ TableInspector,
280
+ { rowData: { schema: 'shop', name: 'orders' } },
281
+ {
282
+ url: '/modules/database/schemas',
283
+ respond: (read) =>
284
+ read.url === CONNECTIONS_URL
285
+ ? connectionsState(WAREHOUSE)
286
+ : backend(read),
287
+ },
288
+ )
289
+ expect(external.html).not.toContain(INSTANCES)
290
+ })
291
+
270
292
  it('table inspector: leaves the position and steps to the DMS header', async () => {
271
293
  const page = await render(
272
294
  TableInspector,