enso/app/gui2/e2e/mockProjectManager.ts
somebody1234 9b7e3d0f16
E2E tests (#8239)
- Closes #8179

# Important Notes
- ⚠️ These tests are currently *not run* on any CI workflow.
- There is some unused code for mocking the PM. This has been intentionally kept, as this may be useful in the future.
Note that this may be useful for testing the dashboard, however the dashboard is currently only tested in cloud mode
- that is, without the backend switcher, and with only the remote backend available. As such, currently it uses HTTP API mocks, and no PM mock.
2023-11-27 15:48:37 +00:00

64 lines
1.9 KiB
TypeScript

declare const projectIdBrand: unique symbol
/** A name of a project. */
export type ProjectId = string & { [projectIdBrand]: never }
declare const projectNameBrand: unique symbol
/** A name of a project. */
export type ProjectName = string & { [projectNameBrand]: never }
declare const utcDateTimeBrand: unique symbol
/** A name of a project. */
export type UTCDateTime = string & { [utcDateTimeBrand]: never }
/** A value specifying the hostname and port of a socket. */
export interface IpWithSocket {
host: string
port: number
}
export interface OpenProject {
engineVersion: string
languageServerJsonAddress: IpWithSocket
languageServerBinaryAddress: IpWithSocket
projectName: ProjectName
projectNormalizedName: string
projectNamespace: string
}
/** Details for a project. */
export interface ProjectMetadata {
name: ProjectName
namespace: string
id: ProjectId
engineVersion: string | null
created: UTCDateTime
lastOpened: UTCDateTime | null
}
export const projects = new Map<string, ProjectMetadata>()
const openProjects = new Set<string>()
export const methods = {
async 'project/open'(id) {
openProjects.add(id)
const project = projects.get(id)
if (!project) throw new Error(`Cannot find project with ID ${id}.`)
return {
projectName: project.name,
projectNormalizedName: project.name,
projectNamespace: project.namespace,
languageServerJsonAddress: { host: '127.0.0.1', port: 30000 },
languageServerBinaryAddress: { host: '127.0.0.1', port: 30001 },
engineVersion: '',
} satisfies OpenProject
},
async 'project/close'(id) {
openProjects.delete(id)
return {}
},
async 'project/list'(numberOfProjects) {
const projectsList = Array.from(projects.values())
return {
projects: numberOfProjects != null ? projectsList.slice(0, numberOfProjects) : projectsList,
}
},
} satisfies Record<string, (...params: any[]) => Promise<unknown>>