diff --git a/packages/app/cypress/e2e/runs.cy.ts b/packages/app/cypress/e2e/runs.cy.ts index 1fc8a821b78c..2aac845978c0 100644 --- a/packages/app/cypress/e2e/runs.cy.ts +++ b/packages/app/cypress/e2e/runs.cy.ts @@ -171,6 +171,44 @@ describe('App: Runs', { viewportWidth: 1200 }, () => { }) }) + context('Runs - Create Project', () => { + it('when a project is created, injects new projectId into the config file', () => { + cy.remoteGraphQLIntercept(async (obj) => { + if (obj.operationName === 'SelectCloudProjectModal_CreateCloudProject_cloudProjectCreate') { + obj.result.data!.cloudProjectCreate = { + slug: 'newProjectId', + id: 'newId', + } + } + + return obj.result + }) + + cy.scaffoldProject('launchpad') + cy.openProject('launchpad') + cy.startAppServer('e2e') + cy.loginUser() + cy.visitApp() + + cy.withCtx(async (ctx) => { + const config = await ctx.project.getConfig() + + expect(config.projectId).to.not.equal('newProjectId') + }) + + cy.get('[href="#/runs"]').click() + cy.findByText(defaultMessages.runs.connect.buttonProject).click() + cy.get('button').contains(defaultMessages.runs.connect.modal.selectProject.createProject).click() + cy.findByText(defaultMessages.runs.connectSuccessAlert.title).should('be.visible') + + cy.withCtx(async (ctx) => { + const config = await ctx.project.getConfig() + + expect(config.projectId).to.equal('newProjectId') + }) + }) + }) + context('Runs - Cannot Find Project', () => { beforeEach(() => { cy.scaffoldProject('component-tests') @@ -280,9 +318,33 @@ describe('App: Runs', { viewportWidth: 1200 }, () => { expect(o.testState.cloudProjectRequestAccessWasCalled).to.eql(true) }) }) + + it('updates the button text when the request access button is clicked', () => { + cy.remoteGraphQLIntercept(async (obj, testState) => { + if (obj.operationName === 'Runs_currentProject_cloudProject_batched') { + for (const proj of obj!.result!.data!.cloudProjectsBySlugs) { + proj.__typename = 'CloudProjectUnauthorized' + proj.message = 'Cloud Project Unauthorized' + proj.hasRequestedAccess = false + testState.project = proj + } + } else if (obj.operationName === 'RunsErrorRenderer_RequestAccess_cloudProjectRequestAccess') { + obj!.result!.data!.cloudProjectRequestAccess = { + ...testState.project, + hasRequestedAccess: true, + } + } + + return obj.result + }) + + cy.visitApp('/runs') + cy.findByText(defaultMessages.runs.errors.unauthorized.button).click() + cy.findByText(defaultMessages.runs.errors.unauthorizedRequested.button).should('exist') + }) }) - context('Runs - Unauthorized Project Requested', () => { + context('Runs - Pending authorization to project', () => { beforeEach(() => { cy.scaffoldProject('component-tests') cy.openProject('component-tests') diff --git a/packages/app/src/runs/modals/SelectCloudProjectModal.vue b/packages/app/src/runs/modals/SelectCloudProjectModal.vue index c6ebf4a07946..5f09952ea314 100644 --- a/packages/app/src/runs/modals/SelectCloudProjectModal.vue +++ b/packages/app/src/runs/modals/SelectCloudProjectModal.vue @@ -269,9 +269,11 @@ const setProjectIdMutation = useMutation(SelectCloudProjectModal_SetProjectIdDoc async function createOrConnectProject () { let projectId: string | undefined - if (newProject.value && pickedOrganization.value) { + const isNewProject = Boolean(newProject.value && pickedOrganization.value) + + if (isNewProject) { const { data } = await createCloudProjectMutation.executeMutation({ - orgId: pickedOrganization.value.id, + orgId: pickedOrganization.value!.id, name: projectName.value, public: projectAccess.value === 'public', }) diff --git a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts index 7945dba68d4c..443ba44e621b 100644 --- a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts +++ b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts @@ -585,11 +585,7 @@ export const mutation = mutationType({ projectId: nonNull(stringArg()), }, resolve: async (_, args, ctx) => { - try { - await ctx.actions.project.setProjectIdInConfigFile(args.projectId) - } catch { - // ignore error as not useful for end user to see - } + await ctx.actions.project.setProjectIdInConfigFile(args.projectId) // Wait for the project config to be reloaded await ctx.lifecycleManager.refreshLifecycle()