-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set output evaluation context for a single node #8440
Changes from 25 commits
ce332a1
391c526
a23dddc
a079f66
f3fa62f
ae6f53d
9ea511b
b658ef6
32e7b28
70425c2
c5bf8f6
09dca91
48e9a55
fbc457e
882c23b
d163b54
ecfdbec
ada03b6
a46aee2
415fc47
9f0e95d
45ed77d
f07fa80
986d309
745f049
f92385c
616c83e
795f836
55e97bc
5575023
351eea7
7786b70
ba211b0
2b038df
4362fc8
9888941
41d4172
e71c60b
8aa3e0e
0ded00d
791c841
bf63ea8
371ad48
19906cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { provideGuiConfig } from '@/providers/guiConfig' | ||
import { provideWidgetRegistry } from '@/providers/widgetRegistry' | ||
import { useGraphStore } from '@/stores/graph' | ||
import { GraphDb, mockNode } from '@/stores/graph/graphDatabase' | ||
import { useProjectStore } from '@/stores/project' | ||
import { ComputedValueRegistry } from '@/stores/project/computedValueRegistry' | ||
import { MockTransport, MockWebSocket } from '@/util/net' | ||
import * as random from 'lib0/random' | ||
import { getActivePinia } from 'pinia' | ||
import type { ExprId } from 'shared/yjsModel' | ||
import { ref, type App } from 'vue' | ||
import { mockDataHandler, mockLSHandler } from './engine' | ||
export * as providers from './providers' | ||
export * as vue from './vue' | ||
|
||
export function languageServer() { | ||
MockTransport.addMock('engine', mockLSHandler) | ||
} | ||
|
||
export function dataServer() { | ||
MockWebSocket.addMock('data', mockDataHandler) | ||
} | ||
|
||
export function guiConfig(app: App) { | ||
return provideGuiConfig._mock( | ||
ref({ | ||
startup: { | ||
project: 'Mock Project', | ||
displayedProjectName: 'Mock Project', | ||
}, | ||
engine: { rpcUrl: 'mock://engine', dataUrl: 'mock://data' }, | ||
}), | ||
app, | ||
) | ||
} | ||
|
||
export const computedValueRegistry = ComputedValueRegistry.Mock | ||
export const graphDb = GraphDb.Mock | ||
|
||
export function widgetRegistry(app: App) { | ||
return widgetRegistry.withGraphDb(graphDb())(app) | ||
} | ||
|
||
widgetRegistry.withGraphDb = function widgetRegistryWithGraphDb(graphDb: GraphDb) { | ||
return (app: App) => provideWidgetRegistry._mock([graphDb], app) | ||
} | ||
|
||
export function graphStore() { | ||
return useGraphStore(getActivePinia()) | ||
} | ||
|
||
type ProjectStore = ReturnType<typeof projectStore> | ||
|
||
export function projectStore() { | ||
const projectStore = useProjectStore(getActivePinia()) | ||
const mod = projectStore.projectModel.createNewModule('Main.enso') | ||
mod.doc.ydoc.emit('load', []) | ||
mod.doc.contents.insert(0, 'main =\n') | ||
return projectStore | ||
} | ||
|
||
/** The stores should be initialized in this order, as `graphStore` depends on `projectStore`. */ | ||
export function projectStoreAndGraphStore() { | ||
return [projectStore(), graphStore()] satisfies [] | unknown[] | ||
} | ||
|
||
export function newExprId() { | ||
return random.uuidv4() as ExprId | ||
} | ||
|
||
/** This should only be used for supplying as initial props when testing. | ||
* Please do {@link GraphDb.mockNode} with a `useGraphStore().db` after mount. */ | ||
export function node() { | ||
return mockNode() | ||
} | ||
|
||
export function waitForMainModule(projectStore?: ProjectStore) { | ||
const definedProjectStore = projectStore ?? useProjectStore(getActivePinia()) | ||
return new Promise((resolve, reject) => { | ||
const handle1 = window.setInterval(() => { | ||
if (definedProjectStore.module != null) { | ||
window.clearInterval(handle1) | ||
window.clearTimeout(handle2) | ||
resolve(definedProjectStore.module) | ||
} | ||
}, 10) | ||
const handle2 = window.setTimeout(() => { | ||
window.clearInterval(handle1) | ||
reject() | ||
}, 5_000) | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import type { GraphSelection } from '@/providers/graphSelection' | ||
import type { GraphNavigator } from '../src/providers/graphNavigator' | ||
import { Rect } from '../src/util/rect' | ||
import { Vec2 } from '../src/util/vec2' | ||
|
||
export const graphNavigator: GraphNavigator = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this have to be mocked? I feel like no providers should need any mocking, except for things related to network requests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. previously we had component tests for GraphNode... I guess the correct solution is maybe to use a wrapper component then? but also, we're no longer doing component tests so it's not like these are currently used either. |
||
events: {} as any, | ||
clientToScenePos: () => Vec2.Zero, | ||
clientToSceneRect: () => Rect.Zero, | ||
panAndZoomTo: () => {}, | ||
transform: '', | ||
prescaledTransform: '', | ||
translate: Vec2.Zero, | ||
scale: 1, | ||
sceneMousePos: Vec2.Zero, | ||
viewBox: '', | ||
viewport: Rect.Zero, | ||
} | ||
|
||
export function graphNavigatorWith(modifications?: Partial<GraphNavigator>): GraphNavigator { | ||
return Object.assign({}, graphNavigator, modifications) | ||
} | ||
|
||
export const graphSelection: GraphSelection = { | ||
events: {} as any, | ||
anchor: undefined, | ||
deselectAll: () => {}, | ||
addHoveredPort: () => new Set(), | ||
removeHoveredPort: () => false, | ||
handleSelectionOf: () => {}, | ||
hoveredNode: undefined, | ||
hoveredPort: undefined, | ||
isSelected: () => false, | ||
mouseHandler: () => false, | ||
selectAll: () => {}, | ||
selected: new Set(), | ||
} | ||
|
||
export function graphSelectionWith(modifications?: Partial<GraphSelection>): GraphSelection { | ||
return Object.assign({}, graphSelection, modifications) | ||
} | ||
|
||
export const all = { | ||
'graph navigator': graphNavigator, | ||
'graph selection': graphSelection, | ||
} | ||
|
||
export function allWith( | ||
modifications: Partial<{ [K in keyof typeof all]: Partial<(typeof all)[K]> }>, | ||
): typeof all { | ||
return { | ||
'graph navigator': graphNavigatorWith(modifications['graph navigator']), | ||
'graph selection': graphSelectionWith(modifications['graph selection']), | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { type VueWrapper } from '@vue/test-utils' | ||
import { nextTick } from 'vue' | ||
|
||
// It is currently not feasible to use generics here, as the type of the component's emits | ||
// is not exposed. | ||
export function handleEmit(wrapper: VueWrapper<any>, event: string, fn: (...args: any[]) => void) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this used anywhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as above, previously used for component tests. i figured it's fine to keep it if we may want to do component testing in the future, but i have no problems with removing all unused code because we are probably not planning to do that anytime soon anyway. |
||
let previousLength = 0 | ||
return { | ||
async run() { | ||
const emitted = wrapper.emitted(event) | ||
if (!emitted) return | ||
for (let i = previousLength; i < emitted.length; i += 1) { | ||
fn(...emitted[i]!) | ||
} | ||
previousLength = emitted.length | ||
await nextTick() | ||
}, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find any usages of this function. Can it be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was required previously when I used component tests for GraphNode