tabs.test.ts62 lines · main
| 1 | import { beforeEach, describe, expect, it } from 'vitest' |
| 2 | |
| 3 | import { createTabsState } from './tabs' |
| 4 | import { ENTITY_TYPE } from '@/data/entity-types/entity-type-constants' |
| 5 | |
| 6 | describe('tabs recent items', () => { |
| 7 | beforeEach(() => { |
| 8 | localStorage.clear() |
| 9 | }) |
| 10 | |
| 11 | it('refreshes an existing recent item label when the tab is re-added', () => { |
| 12 | const store = createTabsState('default') |
| 13 | |
| 14 | store.addRecentItem({ |
| 15 | id: 'r-1', |
| 16 | type: ENTITY_TYPE.TABLE, |
| 17 | label: 'tasks', |
| 18 | metadata: { |
| 19 | schema: 'public', |
| 20 | name: 'tasks', |
| 21 | tableId: 1, |
| 22 | }, |
| 23 | }) |
| 24 | |
| 25 | store.addRecentItem({ |
| 26 | id: 'r-1', |
| 27 | type: ENTITY_TYPE.TABLE, |
| 28 | label: 'routines', |
| 29 | metadata: { |
| 30 | schema: 'public', |
| 31 | name: 'routines', |
| 32 | tableId: 1, |
| 33 | }, |
| 34 | }) |
| 35 | |
| 36 | expect(store.recentItems).toHaveLength(1) |
| 37 | expect(store.recentItems[0].label).toBe('routines') |
| 38 | expect(store.recentItems[0].metadata?.name).toBe('routines') |
| 39 | }) |
| 40 | |
| 41 | it('keeps recent items aligned when an open tab label changes', () => { |
| 42 | const store = createTabsState('default') |
| 43 | |
| 44 | store.addTab({ |
| 45 | id: 'r-1', |
| 46 | type: ENTITY_TYPE.TABLE, |
| 47 | label: 'tasks', |
| 48 | metadata: { |
| 49 | schema: 'public', |
| 50 | name: 'tasks', |
| 51 | tableId: 1, |
| 52 | }, |
| 53 | isPreview: false, |
| 54 | }) |
| 55 | |
| 56 | store.updateTab('r-1', { label: 'routines' }) |
| 57 | |
| 58 | expect(store.tabsMap['r-1'].label).toBe('routines') |
| 59 | expect(store.recentItems[0].label).toBe('routines') |
| 60 | expect(store.recentItems[0].metadata?.name).toBe('routines') |
| 61 | }) |
| 62 | }) |