Skip to content

Commit dc2ae0d

Browse files
committed
fix test cases
1 parent 3b763c5 commit dc2ae0d

File tree

2 files changed

+38
-35
lines changed

2 files changed

+38
-35
lines changed

src/commons/sagas/WorkspaceSaga/helpers/clearContext.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
import type { Context } from 'js-slang';
22
import { defineSymbol } from 'js-slang/dist/createContext';
3-
import { LanguageOptions, Variant } from 'js-slang/dist/types';
43
import { put, select, take } from 'redux-saga/effects';
5-
import { ExternalLibraryName } from 'src/commons/application/types/ExternalTypes';
64
import WorkspaceActions from 'src/commons/workspace/WorkspaceActions';
75

86
import type { OverallState } from '../../../application/ApplicationTypes';
97
import { actions } from '../../../utils/ActionsHelper';
108
import type { WorkspaceLocation } from '../../../workspace/WorkspaceTypes';
9+
import { selectWorkspace } from '../../SafeEffects';
1110

1211
export function* clearContext(workspaceLocation: WorkspaceLocation, entrypointCode: string) {
13-
const [chapter, symbols, externalLibraryName, globals, variant, languageOptions]: [
14-
number,
15-
string[],
16-
ExternalLibraryName,
17-
Array<[string, any]>,
18-
Variant,
19-
LanguageOptions
20-
] = yield select((state: OverallState) => [
21-
state.workspaces[workspaceLocation].context.chapter,
22-
state.workspaces[workspaceLocation].context.externalSymbols,
23-
state.workspaces[workspaceLocation].externalLibrary,
24-
state.workspaces[workspaceLocation].globals,
25-
state.workspaces[workspaceLocation].context.variant,
26-
state.workspaces[workspaceLocation].context.languageOptions
27-
]);
12+
const {
13+
context: { chapter, externalSymbols: symbols, variant, languageOptions },
14+
externalLibrary: externalLibraryName,
15+
globals,
16+
} = yield* selectWorkspace(workspaceLocation);
2817

2918
const library = {
3019
chapter,

src/commons/sagas/__tests__/WorkspaceSaga.test.ts

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ describe('EVAL_EDITOR', () => {
130130
name: ExternalLibraryName.NONE,
131131
symbols: context.externalSymbols
132132
},
133-
globals
133+
globals,
134+
languageOptions: context.languageOptions
134135
};
135136

136137
const newDefaultState = generateDefaultState(workspaceLocation, {
@@ -397,7 +398,8 @@ describe('EVAL_TESTCASE', () => {
397398
name: ExternalLibraryName.NONE,
398399
symbols: context.externalSymbols
399400
},
400-
globals
401+
globals,
402+
languageOptions: context.languageOptions
401403
};
402404

403405
const newDefaultState = generateDefaultState(workspaceLocation, {
@@ -689,23 +691,34 @@ describe('PLAYGROUND_EXTERNAL_SELECT', () => {
689691
name: newExternalLibraryName,
690692
symbols
691693
},
692-
globals
694+
globals,
695+
languageOptions: context.languageOptions
693696
};
694697

695-
return expectSaga(workspaceSaga)
696-
.withState(newDefaultState)
697-
.put(WorkspaceActions.changeExternalLibrary(newExternalLibraryName, workspaceLocation))
698-
.put(WorkspaceActions.beginClearContext(workspaceLocation, library, true))
699-
.put(WorkspaceActions.clearReplOutput(workspaceLocation))
700-
.call(showSuccessMessage, `Switched to ${newExternalLibraryName} library`, 1000)
701-
.dispatch({
702-
type: WorkspaceActions.externalLibrarySelect.type,
703-
payload: {
704-
externalLibraryName: newExternalLibraryName,
705-
workspaceLocation
706-
}
707-
})
708-
.silentRun();
698+
return (
699+
expectSaga(workspaceSaga)
700+
.withState(newDefaultState)
701+
.put(WorkspaceActions.changeExternalLibrary(newExternalLibraryName, workspaceLocation))
702+
// beginClearContext is asserted here but the library object can contain
703+
// runtime-specific fields (like languageOptions). Match only the action
704+
// shape we care about (type, workspaceLocation and shouldInitLibrary)
705+
.put.like({
706+
action: {
707+
type: WorkspaceActions.beginClearContext.type,
708+
payload: { workspaceLocation, shouldInitLibrary: true }
709+
}
710+
})
711+
.put(WorkspaceActions.clearReplOutput(workspaceLocation))
712+
.call(showSuccessMessage, `Switched to ${newExternalLibraryName} library`, 1000)
713+
.dispatch({
714+
type: WorkspaceActions.externalLibrarySelect.type,
715+
payload: {
716+
externalLibraryName: newExternalLibraryName,
717+
workspaceLocation
718+
}
719+
})
720+
.silentRun()
721+
);
709722
});
710723

711724
test('does not call the above when oldExternalLibraryName === newExternalLibraryName', () => {
@@ -770,7 +783,8 @@ describe('BEGIN_CLEAR_CONTEXT', () => {
770783
name: newExternalLibraryName,
771784
symbols
772785
},
773-
globals
786+
globals,
787+
languageOptions: undefined
774788
};
775789

776790
return expectSaga(workspaceSaga)

0 commit comments

Comments
 (0)