Skip to content

Commit

Permalink
feat: package manager in update modal (#20123)
Browse files Browse the repository at this point in the history
  • Loading branch information
Barthélémy Ledoux authored Feb 11, 2022
1 parent faa8fb5 commit 9cad97a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/app/cypress/e2e/top-nav.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ describe('App Top Nav Workflows', () => {
cy.findByRole('dialog', { name: 'Upgrade to Cypress 10.1.0' }).as('upgradeModal').within(() => {
cy.validateExternalLink({ name: 'Need help', href: 'https://on.cypress.io' })
cy.contains('You are currently running Version 10.0.0 of Cypress').should('be.visible')
cy.contains('npm install --save-dev cypress@10.1.0').should('be.visible')
cy.contains('npm install -D cypress@10.1.0').should('be.visible')
cy.findByRole('button', { name: 'Close' }).click()
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ describe('<HeaderBarContent />', { viewportWidth: 1000, viewportHeight: 750 }, (
it('shows hint and modal to upgrade to latest version of cypress', () => {
cy.mountFragment(HeaderBar_HeaderBarContentFragmentDoc, {
onResult: (result) => {
if (result.currentProject) {
result.currentProject.packageManager = 'yarn'
}

result.versions = {
__typename: 'VersionData',
current: {
Expand Down Expand Up @@ -161,6 +165,7 @@ describe('<HeaderBarContent />', { viewportWidth: 1000, viewportHeight: 750 }, (

cy.contains(`${defaultMessages.topNav.updateCypress.title} 8.7.0`).should('be.visible')
cy.contains('test-project').should('be.visible')
cy.contains('code', 'yarn add -D cypress').should('be.visible')
cy.percySnapshot('after upgrade modal open')

cy.get('body').type('{esc}') // dismiss modal with keyboard
Expand Down
22 changes: 18 additions & 4 deletions packages/frontend-shared/src/gql-components/topnav/TopNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
:installed-version="versions.current.version"
:latest-version="versions.latest.version"
:project-name="props.gql?.currentProject?.title"
:install-command="installCommand"
@close="showUpdateModal = false"
/>
</template>
Expand Down Expand Up @@ -229,11 +230,11 @@ fragment TopNav on Query {
currentProject {
id
title
packageManager
currentBrowser {
id
displayName
majorVersion
id
displayName
majorVersion
}
...VerticalBrowserListItems
}
Expand Down Expand Up @@ -333,6 +334,19 @@ const resetPrompt = (event) => {
}
}
const installCommand = computed(() => {
switch (props.gql.currentProject?.packageManager) {
case 'npm':
return 'npm install -D '
case 'yarn':
return 'yarn add -D '
case 'pnpm':
return 'pnpm add -D '
default:
return 'npm install -D '
}
})
onKeyStroke(['Enter', ' ', 'Escape'], (event) => {
resetPrompt(event)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,35 @@ describe('<UpdateCypressModal />', { viewportWidth: 1000, viewportHeight: 750 },
it('renders expected content & emits expected events', () => {
const handleClose = cy.stub()

cy.mount(() => <UpdateCypressModal installedVersion={installedVersion} latestVersion={latestVersion} show={true} onClose={handleClose}></UpdateCypressModal>)
cy.mount(() => (<UpdateCypressModal
installedVersion={installedVersion}
latestVersion={latestVersion}
show={true}
onClose={handleClose}
installCommand="npm i "/>))

cy.contains(`${defaultMessages.topNav.updateCypress.title} ${latestVersion}`).should('be.visible')
cy.contains(`${defaultMessages.topNav.updateCypress.currentlyRunning}`.replace('{0}', installedVersion)).should('be.visible')
cy.contains(`${defaultMessages.topNav.updateCypress.pasteToUpgradeGlobal.replace('{0}', defaultMessages.topNav.updateCypress.rememberToCloseInsert)}`).should('be.visible')
cy.contains(defaultMessages.topNav.updateCypress.currentlyRunning
.replace('{0}', installedVersion)).should('be.visible')

cy.contains(defaultMessages.topNav.updateCypress.pasteToUpgradeGlobal
.replace('{0}', defaultMessages.topNav.updateCypress.rememberToCloseInsert)).should('be.visible')

cy.contains(`cypress@${latestVersion}`).should('be.visible')
cy.findByLabelText('Close').click().then(() => {
expect(handleClose).to.have.been.calledOnce
})
})

it('renders project-specific instructions when a project name prop is present', () => {
cy.mount(() => <UpdateCypressModal projectName="test-project" installedVersion={installedVersion} latestVersion={latestVersion} show={true}></UpdateCypressModal>)
cy.contains(`${defaultMessages.topNav.updateCypress.pasteToUpgradeProject.replace('{0}', defaultMessages.topNav.updateCypress.rememberToCloseInsert)}`).should('be.visible')
cy.mount(() => (<UpdateCypressModal
projectName="test-project"
installedVersion={installedVersion}
latestVersion={latestVersion}
show={true}
installCommand="npm i "/>))

cy.contains(defaultMessages.topNav.updateCypress.pasteToUpgradeProject
.replace('{0}', defaultMessages.topNav.updateCypress.rememberToCloseInsert)).should('be.visible')
})
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<StandardModal
class="transition duration-200 transition-all w-680px"
class="transition transition-all w-680px duration-200"
variant="bare"
:title="title"
:model-value="show"
Expand Down Expand Up @@ -38,13 +38,12 @@ import { useI18n } from '@cy/i18n'
const { t } = useI18n()
const props = withDefaults(defineProps<{
installCommand?: string
installCommand: string
installedVersion: string
latestVersion: string
projectName?: string
show: boolean
}>(), {
installCommand: 'npm install --save-dev ',
projectName: '', // in global mode, project won't be populated so an empty string is fine
})
Expand Down

3 comments on commit 9cad97a

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 9cad97a Feb 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.0.0/linux-x64/circle-10.0-release-9cad97a3c838733dd8d8768cd972b0b1204f2ed8/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 9cad97a Feb 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.0.0/win32-x64/circle-10.0-release-9cad97a3c838733dd8d8768cd972b0b1204f2ed8/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 9cad97a Feb 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.0.0/darwin-x64/circle-10.0-release-9cad97a3c838733dd8d8768cd972b0b1204f2ed8/cypress.tgz

Please sign in to comment.