-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor): Migrate existing users to new canvas and set new canvas…
… as default (#11896)
- Loading branch information
1 parent
132aa0b
commit caa7447
Showing
7 changed files
with
203 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
packages/editor-ui/src/composables/useNodeViewVersionSwitcher.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import { useNodeViewVersionSwitcher } from './useNodeViewVersionSwitcher'; | ||
import { useWorkflowsStore } from '@/stores/workflows.store'; | ||
import { createTestingPinia } from '@pinia/testing'; | ||
import { STORES } from '@/constants'; | ||
import { setActivePinia } from 'pinia'; | ||
import { mockedStore } from '@/__tests__/utils'; | ||
import { useNDVStore } from '@/stores/ndv.store'; | ||
|
||
vi.mock('@/composables/useTelemetry', () => ({ | ||
useTelemetry: () => ({ | ||
track: vi.fn(), | ||
}), | ||
})); | ||
|
||
describe('useNodeViewVersionSwitcher', () => { | ||
const initialState = { | ||
[STORES.WORKFLOWS]: {}, | ||
[STORES.NDV]: {}, | ||
}; | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
const pinia = createTestingPinia({ initialState }); | ||
setActivePinia(pinia); | ||
}); | ||
|
||
describe('isNewUser', () => { | ||
test('should return true when there are no active workflows', () => { | ||
const { isNewUser } = useNodeViewVersionSwitcher(); | ||
expect(isNewUser.value).toBe(true); | ||
}); | ||
|
||
test('should return false when there are active workflows', () => { | ||
const workflowsStore = mockedStore(useWorkflowsStore); | ||
workflowsStore.activeWorkflows = ['1']; | ||
|
||
const { isNewUser } = useNodeViewVersionSwitcher(); | ||
expect(isNewUser.value).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('nodeViewVersion', () => { | ||
test('should initialize with default version "2"', () => { | ||
const { nodeViewVersion } = useNodeViewVersionSwitcher(); | ||
expect(nodeViewVersion.value).toBe('2'); | ||
}); | ||
}); | ||
|
||
describe('isNodeViewDiscoveryTooltipVisible', () => { | ||
test('should be visible under correct conditions', () => { | ||
const workflowsStore = mockedStore(useWorkflowsStore); | ||
workflowsStore.activeWorkflows = ['1']; | ||
|
||
const ndvStore = mockedStore(useNDVStore); | ||
ndvStore.activeNodeName = null; | ||
|
||
const { isNodeViewDiscoveryTooltipVisible } = useNodeViewVersionSwitcher(); | ||
expect(isNodeViewDiscoveryTooltipVisible.value).toBe(true); | ||
}); | ||
|
||
test('should not be visible for new users', () => { | ||
const workflowsStore = mockedStore(useWorkflowsStore); | ||
workflowsStore.activeWorkflows = []; | ||
|
||
const { isNodeViewDiscoveryTooltipVisible } = useNodeViewVersionSwitcher(); | ||
expect(isNodeViewDiscoveryTooltipVisible.value).toBe(false); | ||
}); | ||
|
||
test('should not be visible when node is selected', () => { | ||
const ndvStore = mockedStore(useNDVStore); | ||
ndvStore.activeNodeName = 'test-node'; | ||
|
||
const { isNodeViewDiscoveryTooltipVisible } = useNodeViewVersionSwitcher(); | ||
expect(isNodeViewDiscoveryTooltipVisible.value).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('switchNodeViewVersion', () => { | ||
test('should switch from version 2 to 1 and back', () => { | ||
const { nodeViewVersion, switchNodeViewVersion } = useNodeViewVersionSwitcher(); | ||
|
||
switchNodeViewVersion(); | ||
|
||
expect(nodeViewVersion.value).toBe('1'); | ||
|
||
switchNodeViewVersion(); | ||
|
||
expect(nodeViewVersion.value).toBe('2'); | ||
}); | ||
}); | ||
|
||
describe('migrateToNewNodeViewVersion', () => { | ||
test('should not migrate if already migrated', () => { | ||
const { nodeViewVersion, nodeViewVersionMigrated, migrateToNewNodeViewVersion } = | ||
useNodeViewVersionSwitcher(); | ||
nodeViewVersionMigrated.value = true; | ||
|
||
migrateToNewNodeViewVersion(); | ||
|
||
expect(nodeViewVersion.value).toBe('2'); | ||
}); | ||
|
||
test('should not migrate if already on version 2', () => { | ||
const { nodeViewVersion, migrateToNewNodeViewVersion } = useNodeViewVersionSwitcher(); | ||
nodeViewVersion.value = '2'; | ||
|
||
migrateToNewNodeViewVersion(); | ||
|
||
expect(nodeViewVersion.value).not.toBe('1'); | ||
}); | ||
|
||
test('should migrate to version 2 if not migrated and on version 1', () => { | ||
const { nodeViewVersion, nodeViewVersionMigrated, migrateToNewNodeViewVersion } = | ||
useNodeViewVersionSwitcher(); | ||
nodeViewVersion.value = '1'; | ||
nodeViewVersionMigrated.value = false; | ||
|
||
migrateToNewNodeViewVersion(); | ||
|
||
expect(nodeViewVersion.value).toBe('2'); | ||
expect(nodeViewVersionMigrated.value).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('setNodeViewSwitcherDropdownOpened', () => { | ||
test('should set discovered when dropdown is closed', () => { | ||
const { setNodeViewSwitcherDropdownOpened, nodeViewSwitcherDiscovered } = | ||
useNodeViewVersionSwitcher(); | ||
|
||
setNodeViewSwitcherDropdownOpened(false); | ||
|
||
expect(nodeViewSwitcherDiscovered.value).toBe(true); | ||
nodeViewSwitcherDiscovered.value = false; | ||
}); | ||
|
||
test('should not set discovered when dropdown is opened', () => { | ||
const { setNodeViewSwitcherDropdownOpened, nodeViewSwitcherDiscovered } = | ||
useNodeViewVersionSwitcher(); | ||
|
||
setNodeViewSwitcherDropdownOpened(true); | ||
|
||
expect(nodeViewSwitcherDiscovered.value).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('setNodeViewSwitcherDiscovered', () => { | ||
test('should set nodeViewSwitcherDiscovered to true', () => { | ||
const { setNodeViewSwitcherDiscovered, nodeViewSwitcherDiscovered } = | ||
useNodeViewVersionSwitcher(); | ||
|
||
setNodeViewSwitcherDiscovered(); | ||
|
||
expect(nodeViewSwitcherDiscovered.value).toBe(true); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters