From 673d15fb36ac1cab72a82d9938d1e7eb4f0060c7 Mon Sep 17 00:00:00 2001 From: David Munechika Date: Thu, 17 Mar 2022 12:29:04 -0400 Subject: [PATCH 01/13] add test for create project --- packages/app/cypress/e2e/runs.cy.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/app/cypress/e2e/runs.cy.ts b/packages/app/cypress/e2e/runs.cy.ts index 716802d57885..89f0acff5744 100644 --- a/packages/app/cypress/e2e/runs.cy.ts +++ b/packages/app/cypress/e2e/runs.cy.ts @@ -170,6 +170,22 @@ describe('App: Runs', { viewportWidth: 1200 }, () => { cy.findByText(defaultMessages.runs.connect.modal.selectProject.connectProject).click() cy.get('[data-cy="runs"]') }) + + it('inserts a projectId into their `cypress.config.js` file after clicking Create Project', () => { + cy.__incorrectlyVisitAppWithIntercept('/runs') + cy.intercept('mutation-SelectCloudProjectModal_CreateCloudProjectDocument').as('CreateCloudProject') + + cy.findByText(defaultMessages.runs.errors.notfound.button).click() + cy.get('[aria-modal="true"]').should('exist') + cy.get('[data-cy="selectProject"] button').click() + cy.findByText('Mock Project').click() + cy.findByText(defaultMessages.runs.connect.modal.selectProject.createNewProject).click() + cy.get('button').contains('Create project').click() + + cy.wait('@CreateCloudProject').then((interception: Interception) => { + expect(interception.request.url).to.include('graphql/mutation-SelectCloudProjectModal_CreateCloudProjectDocument') + }) + }) }) context('Runs - Unauthorized Project', () => { From 5ba1dd811960a92ee890743b7e1525b2f470ee50 Mon Sep 17 00:00:00 2001 From: Rachel Date: Thu, 31 Mar 2022 11:17:04 -0700 Subject: [PATCH 02/13] Clean up test names --- packages/app/cypress/e2e/runs.cy.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/app/cypress/e2e/runs.cy.ts b/packages/app/cypress/e2e/runs.cy.ts index b5424ae64902..c58b14f8caf2 100644 --- a/packages/app/cypress/e2e/runs.cy.ts +++ b/packages/app/cypress/e2e/runs.cy.ts @@ -292,7 +292,7 @@ describe('App: Runs', { viewportWidth: 1200 }, () => { }) }) - context('Runs - Unauthorized Project Requested', () => { + context('Runs - Has requested access to unauthorized project', () => { beforeEach(() => { cy.withCtx(async (ctx) => { await ctx.actions.file.writeFileInProject('cypress.config.js', 'module.exports = {\'projectId\': \'abcdef\' }') @@ -319,7 +319,7 @@ describe('App: Runs', { viewportWidth: 1200 }, () => { cy.get('[href="#/runs"]').click() }) - it('if project Id is specified in config file that is not accessible, shows call to action', () => { + it('if project Id is specified in config file that is not accessible, shows request is in process', () => { cy.findByText(defaultMessages.runs.errors.unauthorizedRequested.button).should('be.visible') }) }) From 3106447bff10b5a781f89c5d33a8ce63aa9fd17b Mon Sep 17 00:00:00 2001 From: Rachel Date: Fri, 1 Apr 2022 12:40:30 -0700 Subject: [PATCH 03/13] add test for button click --- packages/app/cypress/e2e/runs.cy.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/app/cypress/e2e/runs.cy.ts b/packages/app/cypress/e2e/runs.cy.ts index c58b14f8caf2..b35336afbe95 100644 --- a/packages/app/cypress/e2e/runs.cy.ts +++ b/packages/app/cypress/e2e/runs.cy.ts @@ -290,6 +290,32 @@ 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 + } + } + + 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 - Has requested access to unauthorized project', () => { From 816dfbd94e0e83cd0b2456eaec317d8560d069fe Mon Sep 17 00:00:00 2001 From: Rachel Date: Fri, 1 Apr 2022 12:45:12 -0700 Subject: [PATCH 04/13] use else if --- packages/app/cypress/e2e/runs.cy.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/app/cypress/e2e/runs.cy.ts b/packages/app/cypress/e2e/runs.cy.ts index b35336afbe95..1b857b7c4a83 100644 --- a/packages/app/cypress/e2e/runs.cy.ts +++ b/packages/app/cypress/e2e/runs.cy.ts @@ -300,9 +300,7 @@ describe('App: Runs', { viewportWidth: 1200 }, () => { proj.hasRequestedAccess = false testState.project = proj } - } - - if (obj.operationName === 'RunsErrorRenderer_RequestAccess_cloudProjectRequestAccess') { + } else if (obj.operationName === 'RunsErrorRenderer_RequestAccess_cloudProjectRequestAccess') { obj!.result!.data!.cloudProjectRequestAccess = { ...testState.project, hasRequestedAccess: true, From 6b6d08692e197f552d1f843d1d6fe3ea2486ec6d Mon Sep 17 00:00:00 2001 From: Rachel Date: Fri, 1 Apr 2022 12:49:36 -0700 Subject: [PATCH 05/13] clean up diffs --- packages/app/cypress/e2e/runs.cy.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/app/cypress/e2e/runs.cy.ts b/packages/app/cypress/e2e/runs.cy.ts index 1b857b7c4a83..317316e8b055 100644 --- a/packages/app/cypress/e2e/runs.cy.ts +++ b/packages/app/cypress/e2e/runs.cy.ts @@ -316,7 +316,7 @@ describe('App: Runs', { viewportWidth: 1200 }, () => { }) }) - context('Runs - Has requested access to unauthorized project', () => { + context('Runs - Unauthorized Project Requested', () => { beforeEach(() => { cy.withCtx(async (ctx) => { await ctx.actions.file.writeFileInProject('cypress.config.js', 'module.exports = {\'projectId\': \'abcdef\' }') @@ -343,7 +343,7 @@ describe('App: Runs', { viewportWidth: 1200 }, () => { cy.get('[href="#/runs"]').click() }) - it('if project Id is specified in config file that is not accessible, shows request is in process', () => { + it('if project Id is specified in config file that is not accessible, shows call to action', () => { cy.findByText(defaultMessages.runs.errors.unauthorizedRequested.button).should('be.visible') }) }) From 0fa60958ebc4cac845468e7764aa430046b87381 Mon Sep 17 00:00:00 2001 From: Rachel Date: Sun, 3 Apr 2022 22:54:11 -0700 Subject: [PATCH 06/13] add config file test --- packages/app/cypress/e2e/runs.cy.ts | 56 +++++++++++++------ .../runs/modals/SelectCloudProjectModal.vue | 4 +- .../schemaTypes/objectTypes/gql-Mutation.ts | 6 +- 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/packages/app/cypress/e2e/runs.cy.ts b/packages/app/cypress/e2e/runs.cy.ts index 7c9954e3f437..fcc1b4cfc453 100644 --- a/packages/app/cypress/e2e/runs.cy.ts +++ b/packages/app/cypress/e2e/runs.cy.ts @@ -171,6 +171,46 @@ describe('App: Runs', { viewportWidth: 1200 }, () => { }) }) + context('Runs - Create Project', () => { + it('when a project is created, injects new projectId into the config file', () => { + const newProjectId = Math.random().toString() + + 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') @@ -219,22 +259,6 @@ describe('App: Runs', { viewportWidth: 1200 }, () => { cy.findByText(defaultMessages.runs.connect.modal.selectProject.connectProject).click() cy.get('[data-cy="runs"]') }) - - it('inserts a projectId into their `cypress.config.js` file after clicking Create Project', () => { - cy.__incorrectlyVisitAppWithIntercept('/runs') - cy.intercept('mutation-SelectCloudProjectModal_CreateCloudProjectDocument').as('CreateCloudProject') - - cy.findByText(defaultMessages.runs.errors.notfound.button).click() - cy.get('[aria-modal="true"]').should('exist') - cy.get('[data-cy="selectProject"] button').click() - cy.findByText('Mock Project').click() - cy.findByText(defaultMessages.runs.connect.modal.selectProject.createNewProject).click() - cy.get('button').contains('Create project').click() - - cy.wait('@CreateCloudProject').then((interception: Interception) => { - expect(interception.request.url).to.include('graphql/mutation-SelectCloudProjectModal_CreateCloudProjectDocument') - }) - }) }) context('Runs - Unauthorized Project', () => { diff --git a/packages/app/src/runs/modals/SelectCloudProjectModal.vue b/packages/app/src/runs/modals/SelectCloudProjectModal.vue index c6ebf4a07946..a110ffbc89fc 100644 --- a/packages/app/src/runs/modals/SelectCloudProjectModal.vue +++ b/packages/app/src/runs/modals/SelectCloudProjectModal.vue @@ -269,7 +269,9 @@ 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, name: projectName.value, diff --git a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts index 3c3fa0d5ce0d..d851625cf346 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() From 7d7495b4b2bfa50a2e26ccf55b72a22c4f60f74a Mon Sep 17 00:00:00 2001 From: Rachel Date: Sun, 3 Apr 2022 23:06:43 -0700 Subject: [PATCH 07/13] resolve check-ts error --- packages/app/src/runs/modals/SelectCloudProjectModal.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app/src/runs/modals/SelectCloudProjectModal.vue b/packages/app/src/runs/modals/SelectCloudProjectModal.vue index a110ffbc89fc..5f09952ea314 100644 --- a/packages/app/src/runs/modals/SelectCloudProjectModal.vue +++ b/packages/app/src/runs/modals/SelectCloudProjectModal.vue @@ -273,7 +273,7 @@ async function createOrConnectProject () { if (isNewProject) { const { data } = await createCloudProjectMutation.executeMutation({ - orgId: pickedOrganization.value.id, + orgId: pickedOrganization.value!.id, name: projectName.value, public: projectAccess.value === 'public', }) From de425ff26efbf939efd8648621beccb7634f26b5 Mon Sep 17 00:00:00 2001 From: Rachel Date: Sun, 3 Apr 2022 23:58:08 -0700 Subject: [PATCH 08/13] try setting projectId inside gql intercept --- packages/app/cypress/e2e/runs.cy.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/app/cypress/e2e/runs.cy.ts b/packages/app/cypress/e2e/runs.cy.ts index fcc1b4cfc453..569764550807 100644 --- a/packages/app/cypress/e2e/runs.cy.ts +++ b/packages/app/cypress/e2e/runs.cy.ts @@ -173,10 +173,11 @@ describe('App: Runs', { viewportWidth: 1200 }, () => { context('Runs - Create Project', () => { it('when a project is created, injects new projectId into the config file', () => { - const newProjectId = Math.random().toString() + let newProjectId cy.remoteGraphQLIntercept(async (obj) => { if (obj.operationName === 'SelectCloudProjectModal_CreateCloudProject_cloudProjectCreate') { + newProjectId = Math.random().toString() obj.result.data!.cloudProjectCreate = { slug: newProjectId, id: 'newId', From f50b4987b4f41893a3d33fbc51ba79637ec9cc37 Mon Sep 17 00:00:00 2001 From: Rachel Date: Mon, 4 Apr 2022 00:30:14 -0700 Subject: [PATCH 09/13] do not use variable for newProjectId --- packages/app/cypress/e2e/runs.cy.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/app/cypress/e2e/runs.cy.ts b/packages/app/cypress/e2e/runs.cy.ts index 569764550807..45d6d4670233 100644 --- a/packages/app/cypress/e2e/runs.cy.ts +++ b/packages/app/cypress/e2e/runs.cy.ts @@ -173,13 +173,10 @@ describe('App: Runs', { viewportWidth: 1200 }, () => { context('Runs - Create Project', () => { it('when a project is created, injects new projectId into the config file', () => { - let newProjectId - cy.remoteGraphQLIntercept(async (obj) => { if (obj.operationName === 'SelectCloudProjectModal_CreateCloudProject_cloudProjectCreate') { - newProjectId = Math.random().toString() obj.result.data!.cloudProjectCreate = { - slug: newProjectId, + slug: 'newProjectId', id: 'newId', } } @@ -196,7 +193,7 @@ describe('App: Runs', { viewportWidth: 1200 }, () => { cy.withCtx(async (ctx) => { const config = await ctx.project.getConfig() - expect(config.projectId).to.not.equal(newProjectId) + expect(config.projectId).to.not.equal('newProjectId') }) cy.get('[href="#/runs"]').click() @@ -207,7 +204,7 @@ describe('App: Runs', { viewportWidth: 1200 }, () => { cy.withCtx(async (ctx) => { const config = await ctx.project.getConfig() - expect(config.projectId).to.equal(newProjectId) + expect(config.projectId).to.equal('newProjectId') }) }) }) From 9914d2a4122de62ed5547a14e2771b8704b05fa7 Mon Sep 17 00:00:00 2001 From: Rachel Date: Mon, 4 Apr 2022 13:43:02 -0700 Subject: [PATCH 10/13] dummy push From 25fe7a6f042c4829927fe680142eff6fdf0f0db9 Mon Sep 17 00:00:00 2001 From: Rachel Date: Mon, 4 Apr 2022 14:11:18 -0700 Subject: [PATCH 11/13] dummy push From 68d562d67bc92d0997673697a5ab65d2eda6ad85 Mon Sep 17 00:00:00 2001 From: Rachel Date: Mon, 4 Apr 2022 14:43:41 -0700 Subject: [PATCH 12/13] dummy push From f6509ed9e54de23a2910328e783a1b7feb3c5e4d Mon Sep 17 00:00:00 2001 From: Rachel Date: Wed, 6 Apr 2022 10:01:34 -0700 Subject: [PATCH 13/13] rename test context --- packages/app/cypress/e2e/runs.cy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app/cypress/e2e/runs.cy.ts b/packages/app/cypress/e2e/runs.cy.ts index 45d6d4670233..2aac845978c0 100644 --- a/packages/app/cypress/e2e/runs.cy.ts +++ b/packages/app/cypress/e2e/runs.cy.ts @@ -344,7 +344,7 @@ describe('App: Runs', { viewportWidth: 1200 }, () => { }) }) - context('Runs - Unauthorized Project Requested', () => { + context('Runs - Pending authorization to project', () => { beforeEach(() => { cy.scaffoldProject('component-tests') cy.openProject('component-tests')