@@ -4,6 +4,9 @@ import { ConfigKey, getConfigValue, setUserConfigValue } from '../vscode/config'
44import { Toast } from '../vscode/toast'
55import { Response } from '../vscode/response'
66import { RegisteredCommands } from '../commands/external'
7+ import { buildMockMemento } from '../test/util'
8+ import { GlobalPersistenceKey , PersistenceKey } from '../persistence/constants'
9+ import { DEFAULT_HEIGHT } from '../plots/webview/contract'
710
811jest . mock ( 'vscode' )
912jest . mock ( '../vscode/toast' )
@@ -25,19 +28,51 @@ beforeEach(() => {
2528} )
2629
2730describe ( 'showSetupOnFirstUse' , ( ) => {
31+ it ( 'should set a global state key after a new install' , async ( ) => {
32+ const workspaceState = buildMockMemento ( )
33+ const globalState = buildMockMemento ( )
34+
35+ await showSetupOnFirstUse ( globalState , workspaceState )
36+
37+ expect ( globalState . get ( GlobalPersistenceKey . INSTALLED ) ) . toStrictEqual ( true )
38+ } )
39+
2840 it ( 'should ask to show the setup page after a new install' , async ( ) => {
29- await showSetupOnFirstUse ( true )
41+ const workspaceState = buildMockMemento ( )
42+ const globalState = buildMockMemento ( )
43+
44+ await showSetupOnFirstUse ( globalState , workspaceState )
45+
3046 expect ( mockedAskShowOrCloseOrNever ) . toHaveBeenCalledTimes ( 1 )
3147 } )
3248
3349 it ( 'should not ask to show the setup page when the install is not new' , async ( ) => {
34- await showSetupOnFirstUse ( false )
50+ const workspaceState = buildMockMemento ( )
51+ const globalState = buildMockMemento ( {
52+ [ GlobalPersistenceKey . INSTALLED ] : true
53+ } )
54+
55+ await showSetupOnFirstUse ( globalState , workspaceState )
56+ expect ( mockedAskShowOrCloseOrNever ) . not . toHaveBeenCalled ( )
57+ } )
58+
59+ it ( 'should not ask to show the setup page when the workspace state has data even if the global install key is not set' , async ( ) => {
60+ const workspaceState = buildMockMemento ( {
61+ [ PersistenceKey . PLOT_HEIGHT + 'root1' ] : DEFAULT_HEIGHT
62+ } )
63+ const globalState = buildMockMemento ( )
64+
65+ await showSetupOnFirstUse ( globalState , workspaceState )
66+
3567 expect ( mockedAskShowOrCloseOrNever ) . not . toHaveBeenCalled ( )
3668 } )
3769
3870 it ( 'should not ask to show the setup page when the user has set a config option' , async ( ) => {
3971 mockedGetConfigValue . mockReturnValueOnce ( true )
40- await showSetupOnFirstUse ( true )
72+ const workspaceState = buildMockMemento ( )
73+ const globalState = buildMockMemento ( )
74+
75+ await showSetupOnFirstUse ( globalState , workspaceState )
4176 expect ( mockedAskShowOrCloseOrNever ) . not . toHaveBeenCalled ( )
4277 expect ( mockedGetConfigValue ) . toHaveBeenCalledTimes ( 1 )
4378 expect ( mockedGetConfigValue ) . toHaveBeenCalledWith (
@@ -47,7 +82,10 @@ describe('showSetupOnFirstUse', () => {
4782
4883 it ( 'should set the config option if the user responds with never' , async ( ) => {
4984 mockedAskShowOrCloseOrNever . mockResolvedValueOnce ( Response . NEVER )
50- await showSetupOnFirstUse ( true )
85+ const workspaceState = buildMockMemento ( )
86+ const globalState = buildMockMemento ( )
87+
88+ await showSetupOnFirstUse ( globalState , workspaceState )
5189
5290 expect ( mockedSetConfigValue ) . toHaveBeenCalledTimes ( 1 )
5391 expect ( mockedSetConfigValue ) . toHaveBeenCalledWith (
@@ -58,7 +96,10 @@ describe('showSetupOnFirstUse', () => {
5896
5997 it ( 'should show the setup page if the user responds with show' , async ( ) => {
6098 mockedAskShowOrCloseOrNever . mockResolvedValueOnce ( Response . SHOW )
61- await showSetupOnFirstUse ( true )
99+ const workspaceState = buildMockMemento ( )
100+ const globalState = buildMockMemento ( )
101+
102+ await showSetupOnFirstUse ( globalState , workspaceState )
62103
63104 expect ( mockedSetConfigValue ) . not . toHaveBeenCalled ( )
64105 expect ( mockedExecuteCommand ) . toHaveBeenCalledWith (
@@ -68,15 +109,21 @@ describe('showSetupOnFirstUse', () => {
68109
69110 it ( 'should take no action if the user closes the dialog' , async ( ) => {
70111 mockedAskShowOrCloseOrNever . mockResolvedValueOnce ( undefined )
71- await showSetupOnFirstUse ( true )
112+ const workspaceState = buildMockMemento ( )
113+ const globalState = buildMockMemento ( )
114+
115+ await showSetupOnFirstUse ( globalState , workspaceState )
72116
73117 expect ( mockedSetConfigValue ) . not . toHaveBeenCalled ( )
74118 expect ( mockedExecuteCommand ) . not . toHaveBeenCalled ( )
75119 } )
76120
77121 it ( 'should take no action if the user respond with close' , async ( ) => {
78122 mockedAskShowOrCloseOrNever . mockResolvedValueOnce ( Response . CLOSE )
79- await showSetupOnFirstUse ( true )
123+ const workspaceState = buildMockMemento ( )
124+ const globalState = buildMockMemento ( )
125+
126+ await showSetupOnFirstUse ( globalState , workspaceState )
80127
81128 expect ( mockedSetConfigValue ) . not . toHaveBeenCalled ( )
82129 expect ( mockedExecuteCommand ) . not . toHaveBeenCalled ( )
0 commit comments