From f7599ddc76f6d51e310e2e501cf9cffdc69f0760 Mon Sep 17 00:00:00 2001 From: Shawn Taylor Date: Sun, 27 Feb 2022 20:38:00 -0500 Subject: [PATCH] feat(unify): rearrange settings (#20332) * rearrange settings * add empty states * update tests & add new * appease TS * address PR comments --- packages/app/cypress/e2e/settings.cy.ts | 41 +++++----- .../app/src/runs/CloudConnectButton.cy.tsx | 81 +++++++++++++++++++ packages/app/src/runs/CloudConnectButton.vue | 65 +++++++++++++++ packages/app/src/runs/RunsConnect.cy.tsx | 66 +-------------- packages/app/src/runs/RunsConnect.vue | 44 ++-------- .../app/src/settings/SettingsContainer.cy.tsx | 23 ++++-- .../app/src/settings/SettingsContainer.vue | 33 +++++--- .../src/settings/project/CloudSettings.cy.tsx | 69 ++++++++++++++++ .../src/settings/project/CloudSettings.vue | 45 +++++++++++ .../app/src/settings/project/ProjectId.cy.tsx | 3 +- .../app/src/settings/project/ProjectId.vue | 30 ++++--- .../settings/project/ProjectSettings.cy.tsx | 27 +------ .../src/settings/project/ProjectSettings.vue | 26 ------ .../src/assets/icons/chain-link_x16.svg | 2 +- .../src/assets/icons/object-odometer_x24.svg | 5 ++ .../frontend-shared/src/locales/en-US.json | 4 + 16 files changed, 359 insertions(+), 205 deletions(-) create mode 100644 packages/app/src/runs/CloudConnectButton.cy.tsx create mode 100644 packages/app/src/runs/CloudConnectButton.vue create mode 100644 packages/app/src/settings/project/CloudSettings.cy.tsx create mode 100644 packages/app/src/settings/project/CloudSettings.vue create mode 100644 packages/frontend-shared/src/assets/icons/object-odometer_x24.svg diff --git a/packages/app/cypress/e2e/settings.cy.ts b/packages/app/cypress/e2e/settings.cy.ts index 6a4cae4b0e..4b42130d90 100644 --- a/packages/app/cypress/e2e/settings.cy.ts +++ b/packages/app/cypress/e2e/settings.cy.ts @@ -34,12 +34,12 @@ describe('App: Settings', () => { cy.wait('@ReconfigureProject') }) - describe('Project Settings', () => { + describe('Cloud Settings', () => { it('shows the projectId section when there is a projectId', () => { cy.startAppServer('e2e') cy.visitApp() cy.findByText('Settings').click() - cy.findByText('Project Settings').click() + cy.findByText('Dashboard Settings').click() cy.findByText('Project ID').should('be.visible') }) @@ -49,7 +49,7 @@ describe('App: Settings', () => { cy.visitApp() cy.findByText('Settings').click() - cy.findByText('Project Settings').click() + cy.findByText('Dashboard Settings').click() cy.findByText('Record Key').should('be.visible') }) @@ -59,12 +59,26 @@ describe('App: Settings', () => { cy.visitApp() cy.findByText('Settings').click() - cy.findByText('Project Settings').click() + cy.findByText('Dashboard Settings').click() cy.get('[data-cy="record-key"]').should('contain', '***') cy.get('[aria-label="Record Key Visibility Toggle"]').click() cy.get('[data-cy="record-key"]').should('contain', '2aaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa') }) + it('opens cloud settings when clicking on "Manage Keys"', () => { + cy.startAppServer('e2e') + cy.loginUser() + cy.intercept('mutation-ExternalLink_OpenExternal', { 'data': { 'openExternal': true } }).as('OpenExternal') + cy.__incorrectlyVisitAppWithIntercept('settings') + cy.findByText('Dashboard Settings').click() + cy.findByText('Manage Keys').click() + cy.wait('@OpenExternal') + .its('request.body.variables.url') + .should('equal', 'http:/test.cloud/cloud-project/settings') + }) + }) + + describe('Project Settings', () => { it('shows the Spec Patterns section (default specPattern value)', () => { cy.scaffoldProject('simple-ct') cy.openProject('simple-ct') @@ -144,18 +158,6 @@ describe('App: Settings', () => { // TODO: The Edit button isn't hooked up to do anything when it should trigger the openFileInIDE mutation (https://cypress-io.atlassian.net/browse/UNIFY-1164) it.skip('opens cypress.config.js file after clicking "Edit" button', () => { }) - - it('opens cloud settings when clicking on "Manage Keys"', () => { - cy.startAppServer('e2e') - cy.loginUser() - cy.intercept('mutation-ExternalLink_OpenExternal', { 'data': { 'openExternal': true } }).as('OpenExternal') - cy.__incorrectlyVisitAppWithIntercept('settings') - cy.findByText('Project Settings').click() - cy.findByText('Manage Keys').click() - cy.wait('@OpenExternal') - .its('request.body.variables.url') - .should('equal', 'http:/test.cloud/cloud-project/settings') - }) }) describe('external editor', () => { @@ -232,15 +234,16 @@ describe('App: Settings', () => { }) describe('App: Settings without cloud', () => { - it('hides the projectId section when there is no projectId', () => { + it('the projectId section shows a prompt to connect when there is no projectId', () => { cy.scaffoldProject('simple-ct') cy.openProject('simple-ct') cy.startAppServer('component') cy.visitApp() cy.findByText('Settings').click() - cy.findByText('Project Settings').click() - cy.findByText('Project ID').should('not.exist') + cy.findByText('Dashboard Settings').click() + cy.findByText('Project ID').should('exist') + cy.contains('button', 'Log in to the Cypress Dashboard').should('be.visible') }) it('have returned browsers', () => { diff --git a/packages/app/src/runs/CloudConnectButton.cy.tsx b/packages/app/src/runs/CloudConnectButton.cy.tsx new file mode 100644 index 0000000000..57673c0d86 --- /dev/null +++ b/packages/app/src/runs/CloudConnectButton.cy.tsx @@ -0,0 +1,81 @@ +import CloudConnectButton from './CloudConnectButton.vue' +import { CloudConnectButtonFragmentDoc } from '../generated/graphql-test' +import { CloudUserStubs } from '@packages/frontend-shared/cypress/support/mock-graphql/stubgql-CloudTypes' + +describe('', () => { + it('show user connect if not connected', () => { + cy.mountFragment(CloudConnectButtonFragmentDoc, { + onResult: (result) => { + result.cloudViewer = null + }, + render (gqlVal) { + return
+ }, + }) + + cy.contains('button', 'Log in').should('be.visible') + }) + + const cloudViewer = { + ...CloudUserStubs.me, + organizationControl: null, + organizations: { + __typename: 'CloudOrganizationConnection' as const, + nodes: [ + { + __typename: 'CloudOrganization' as const, + id: '1', + name: 'Test Org', + projects: { + __typename: 'CloudProjectConnection' as const, + nodes: [ + { + __typename: 'CloudProject' as const, + id: '1', + name: 'Test Project', + slug: 'test-project', + }, + ], + }, + }, + { + __typename: 'CloudOrganization' as const, + id: '2', + name: 'Test Org 2', + projects: { + __typename: 'CloudProjectConnection' as const, + nodes: [], + }, + }, + ], + }, + } + + it('show project connect if not connected', () => { + cy.mountFragment(CloudConnectButtonFragmentDoc, { + onResult: (result) => { + result.cloudViewer = cloudViewer + }, + render (gqlVal) { + return
+ }, + }) + + cy.contains('button', 'Connect your project').should('be.visible') + }) + + it('shows connect project dialog', () => { + cy.mountFragment(CloudConnectButtonFragmentDoc, { + onResult: (result) => { + result.cloudViewer = cloudViewer + }, + render (gqlVal) { + return
+ }, + }) + + cy.contains('button', 'Connect your project').click() + cy.get('[role="dialog"]').should('be.visible') + cy.get('[role="dialog"] h2').should('contain', 'Connect Project') + }) +}) diff --git a/packages/app/src/runs/CloudConnectButton.vue b/packages/app/src/runs/CloudConnectButton.vue new file mode 100644 index 0000000000..3a677d9d48 --- /dev/null +++ b/packages/app/src/runs/CloudConnectButton.vue @@ -0,0 +1,65 @@ + + + diff --git a/packages/app/src/runs/RunsConnect.cy.tsx b/packages/app/src/runs/RunsConnect.cy.tsx index 01eff329f9..4e1fedb7fa 100644 --- a/packages/app/src/runs/RunsConnect.cy.tsx +++ b/packages/app/src/runs/RunsConnect.cy.tsx @@ -1,9 +1,8 @@ import RunsConnect from './RunsConnect.vue' import { RunsConnectFragmentDoc } from '../generated/graphql-test' -import { CloudUserStubs } from '@packages/frontend-shared/cypress/support/mock-graphql/stubgql-CloudTypes' describe('', () => { - it('show user connect if not connected', () => { + it('show connect button', () => { cy.mountFragment(RunsConnectFragmentDoc, { onResult: (result) => { result.cloudViewer = null @@ -15,67 +14,4 @@ describe('', () => { cy.contains('button', 'Log in').should('be.visible') }) - - const cloudViewer = { - ...CloudUserStubs.me, - organizationControl: null, - organizations: { - __typename: 'CloudOrganizationConnection' as const, - nodes: [ - { - __typename: 'CloudOrganization' as const, - id: '1', - name: 'Test Org', - projects: { - __typename: 'CloudProjectConnection' as const, - nodes: [ - { - __typename: 'CloudProject' as const, - id: '1', - name: 'Test Project', - slug: 'test-project', - }, - ], - }, - }, - { - __typename: 'CloudOrganization' as const, - id: '2', - name: 'Test Org 2', - projects: { - __typename: 'CloudProjectConnection' as const, - nodes: [], - }, - }, - ], - }, - } - - it('show project connect if not connected', () => { - cy.mountFragment(RunsConnectFragmentDoc, { - onResult: (result) => { - result.cloudViewer = cloudViewer - }, - render (gqlVal) { - return
- }, - }) - - cy.contains('button', 'Connect your project').should('be.visible') - }) - - it('shows connect project dialog', () => { - cy.mountFragment(RunsConnectFragmentDoc, { - onResult: (result) => { - result.cloudViewer = cloudViewer - }, - render (gqlVal) { - return
- }, - }) - - cy.contains('button', 'Connect your project').click() - cy.get('[role="dialog"]').should('be.visible') - cy.get('[role="dialog"] h2').should('contain', 'Connect Project') - }) }) diff --git a/packages/app/src/runs/RunsConnect.vue b/packages/app/src/runs/RunsConnect.vue index f1805c9e06..9b672ac6f8 100644 --- a/packages/app/src/runs/RunsConnect.vue +++ b/packages/app/src/runs/RunsConnect.vue @@ -17,48 +17,28 @@

- - - diff --git a/packages/app/src/settings/project/ProjectId.cy.tsx b/packages/app/src/settings/project/ProjectId.cy.tsx index 4f8bf96cca..a238bfab11 100644 --- a/packages/app/src/settings/project/ProjectId.cy.tsx +++ b/packages/app/src/settings/project/ProjectId.cy.tsx @@ -1,3 +1,4 @@ +import { set } from 'lodash' import { ProjectIdFragmentDoc } from '../../generated/graphql-test' import ProjectId from './ProjectId.vue' @@ -11,7 +12,7 @@ describe('', () => { cy.mountFragment(ProjectIdFragmentDoc, { onResult: (result) => { - result.projectId = givenProjectId + set(result, 'currentProject.projectId', givenProjectId) }, render: (gqlVal) => (
diff --git a/packages/app/src/settings/project/ProjectId.vue b/packages/app/src/settings/project/ProjectId.vue index 63468a76bf..04429b2a57 100644 --- a/packages/app/src/settings/project/ProjectId.vue +++ b/packages/app/src/settings/project/ProjectId.vue @@ -1,6 +1,5 @@ -
+
+ @@ -42,18 +47,21 @@ import SettingsSection from '../SettingsSection.vue' import ExternalLink from '@cy/gql-components/ExternalLink.vue' import CodeBox from './CodeBox.vue' import type { ProjectIdFragment } from '../../generated/graphql' +import CloudConnectButton from '../../runs/CloudConnectButton.vue' const { t } = useI18n() gql` -fragment ProjectId on CurrentProject { - id - projectId -} -` +fragment ProjectId on Query { + currentProject { + id + projectId + } + ...CloudConnectButton +}` const props = defineProps<{ - gql?: ProjectIdFragment | null + gql: ProjectIdFragment }>() diff --git a/packages/app/src/settings/project/ProjectSettings.cy.tsx b/packages/app/src/settings/project/ProjectSettings.cy.tsx index fb62fca97a..8f3d50483c 100644 --- a/packages/app/src/settings/project/ProjectSettings.cy.tsx +++ b/packages/app/src/settings/project/ProjectSettings.cy.tsx @@ -3,7 +3,7 @@ import { ProjectSettingsFragmentDoc } from '../../generated/graphql-test' import ProjectSettings from './ProjectSettings.vue' describe('', () => { - it('displays the project Id, record key, and experiments sections', () => { + it('displays the experiments section', () => { cy.mountFragment(ProjectSettingsFragmentDoc, { render: (gqlVal) => { @@ -15,33 +15,8 @@ describe('', () => { }, }) - cy.findByText(defaultMessages.settingsPage.projectId.title).should('be.visible') - cy.findByText(defaultMessages.settingsPage.recordKey.title).should('be.visible') cy.findByText(defaultMessages.settingsPage.experiments.title).should('be.visible') cy.percySnapshot() }) - - it('hides project Id, and record key when not present', () => { - cy.mountFragment(ProjectSettingsFragmentDoc, { - onResult (ctx) { - if (ctx.currentProject?.cloudProject?.__typename === 'CloudProject') { - ctx.currentProject.projectId = null - ctx.currentProject.cloudProject.recordKeys = [] - } - }, - render: (gqlVal) => { - return ( -
- -
- ) - }, - }) - - cy.findByText(defaultMessages.settingsPage.projectId.title).should('not.exist') - cy.findByText(defaultMessages.settingsPage.recordKey.title).should('not.exist') - - cy.percySnapshot() - }) }) diff --git a/packages/app/src/settings/project/ProjectSettings.vue b/packages/app/src/settings/project/ProjectSettings.vue index 74254a4270..cd64cd6193 100644 --- a/packages/app/src/settings/project/ProjectSettings.vue +++ b/packages/app/src/settings/project/ProjectSettings.vue @@ -1,16 +1,4 @@