mirror of
https://github.com/cypress-io/cypress.git
synced 2026-03-09 01:19:20 -05:00
fix: order projects by most recently opened (#21589)
This commit is contained in:
@@ -121,6 +121,8 @@ export class ProjectActions {
|
||||
}
|
||||
|
||||
async setCurrentProject (projectRoot: string) {
|
||||
await this.updateProjectList(() => this.api.insertProjectToCache(projectRoot))
|
||||
|
||||
await this.clearCurrentProject()
|
||||
this.ctx.lifecycleManager.setCurrentProject(projectRoot)
|
||||
}
|
||||
@@ -137,10 +139,7 @@ export class ProjectActions {
|
||||
async loadProjects () {
|
||||
const projectRoots = await this.api.getProjectRootsFromCache()
|
||||
|
||||
this.projects = [
|
||||
...this.projects,
|
||||
...projectRoots.map((projectRoot) => ({ projectRoot })),
|
||||
]
|
||||
this.projects = projectRoots.map((projectRoot) => ({ projectRoot }))
|
||||
|
||||
return this.projects
|
||||
}
|
||||
@@ -176,8 +175,8 @@ export class ProjectActions {
|
||||
}
|
||||
}
|
||||
|
||||
createProject () {
|
||||
//
|
||||
private async updateProjectList (updater: () => Promise<void>) {
|
||||
return updater().then(() => this.loadProjects())
|
||||
}
|
||||
|
||||
async addProjectFromElectronNativeFolderSelect () {
|
||||
@@ -195,15 +194,10 @@ export class ProjectActions {
|
||||
async addProject (args: AddProject) {
|
||||
const projectRoot = await this.getDirectoryPath(args.path)
|
||||
|
||||
const found = this.projects.find((x) => x.projectRoot === projectRoot)
|
||||
|
||||
if (!found) {
|
||||
this.projects.push({ projectRoot })
|
||||
await this.api.insertProjectToCache(projectRoot)
|
||||
}
|
||||
|
||||
if (args.open) {
|
||||
this.setCurrentProject(projectRoot).catch(this.ctx.onError)
|
||||
} else {
|
||||
await this.updateProjectList(() => this.api.insertProjectToCache(projectRoot))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,15 +256,7 @@ export class ProjectActions {
|
||||
}
|
||||
|
||||
removeProject (projectRoot: string) {
|
||||
const found = this.projects.find((x) => x.projectRoot === projectRoot)
|
||||
|
||||
if (!found) {
|
||||
throw new Error(`Cannot remove ${projectRoot}, it is not a known project`)
|
||||
}
|
||||
|
||||
this.projects = this.projects.filter((project) => project.projectRoot !== projectRoot)
|
||||
|
||||
return this.api.removeProjectFromCache(projectRoot)
|
||||
return this.updateProjectList(() => this.api.removeProjectFromCache(projectRoot))
|
||||
}
|
||||
|
||||
async createConfigFile (type?: 'component' | 'e2e' | null) {
|
||||
|
||||
@@ -53,6 +53,8 @@ export function createTestDataContext (mode: DataContextConfig['mode'] = 'run',
|
||||
configApi: {} as InjectedConfigApi,
|
||||
projectApi: {
|
||||
closeActiveProject: sinon.stub(),
|
||||
insertProjectToCache: sinon.stub().resolves(),
|
||||
getProjectRootsFromCache: sinon.stub().resolves([]),
|
||||
} as unknown as ProjectApiShape,
|
||||
electronApi: {
|
||||
isMainWindowFocused: sinon.stub().returns(false),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import defaultMessages from '@packages/frontend-shared/src/locales/en-US.json'
|
||||
import path from 'path'
|
||||
import type { SinonSpy } from 'sinon'
|
||||
import { getPathForPlatform } from './support/getPathForPlatform'
|
||||
|
||||
const sep = Cypress.platform === 'win32' ? '\\' : '/'
|
||||
|
||||
@@ -65,7 +66,10 @@ describe('Launchpad: Global Mode', () => {
|
||||
describe('when projects have been added', () => {
|
||||
const setupAndValidateProjectsList = (projectList, globalModeOptions?: string[] | undefined) => {
|
||||
cy.openGlobalMode(globalModeOptions)
|
||||
projectList.forEach((projectName) => {
|
||||
|
||||
// Adding a project puts the project first in the list, so we reverse the list
|
||||
// to ensure the projectList in the UI matches what is passed in.
|
||||
;[...projectList].reverse().forEach((projectName) => {
|
||||
cy.addProject(projectName)
|
||||
})
|
||||
|
||||
@@ -117,12 +121,10 @@ describe('Launchpad: Global Mode', () => {
|
||||
|
||||
cy.get('[data-cy="project-card"]')
|
||||
.should('have.length', projectList.length)
|
||||
// TODO: fix most recently updated list ()
|
||||
// https://cypress-io.atlassian.net/browse/UNIFY-646
|
||||
// .then((list) => {
|
||||
// expect(list.get(0)).to.contain(projectList[2])
|
||||
// expect(list.get(0)).to.contain(path.join('cy-projects', path.sep, projectList[2]))
|
||||
// })
|
||||
.then((list) => {
|
||||
expect(list.get(0)).to.contain(projectList[2])
|
||||
expect(list.get(0)).to.contain(getPathForPlatform(path.join('cy-projects', projectList[2])))
|
||||
})
|
||||
})
|
||||
|
||||
it('can open and close the add project dropzone', () => {
|
||||
|
||||
Reference in New Issue
Block a user