Skip to content

Commit 948bc02

Browse files
feat: add "dot" version of "new" badge (#25882)
Co-authored-by: astone123 <[email protected]>
1 parent 351413f commit 948bc02

File tree

4 files changed

+73
-5
lines changed

4 files changed

+73
-5
lines changed

cli/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _Released 02/28/2023 (PENDING)_
88
- It is now possible to set `hostOnly` cookies with [`cy.setCookie()`](https://docs.cypress.io/api/commands/setcookie) for a given domain. Addresses [#16856](https://github.com/cypress-io/cypress/issues/16856) and [#17527](https://github.com/cypress-io/cypress/issues/17527).
99
- Added a Public API for third party component libraries to define a Framework Definition, embedding their library into the Cypress onboarding workflow. Learn more [here](https://docs.cypress.io/guides/component-testing/third-party-definitions). Implemented in [#25780](https://github.com/cypress-io/cypress/pull/25780) and closes [#25638](https://github.com/cypress-io/cypress/issues/25638).
1010
- Added a Debug Page tutorial slideshow for projects that are not connected to Cypress Cloud. Addresses [#25768](https://github.com/cypress-io/cypress/issues/25768).
11+
- Updated the "new" status badge for the Debug page navigation link to be less noticeable when the navigation is collapsed. Addresses [#25739](https://github.com/cypress-io/cypress/issues/25739).
1112

1213
**Bugfixes:**
1314

packages/app/cypress/e2e/sidebar_navigation.cy.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,34 @@ describe('Sidebar Navigation', { viewportWidth: 1280 }, () => {
250250
cy.get('.router-link-active').findByText('Debug').should('be.visible')
251251
})
252252

253+
it('Debug "new" notification appears as a dot when nav is collapsed', () => {
254+
cy.findByLabelText('New Debug feature')
255+
.should('be.visible')
256+
.contains('New')
257+
258+
// in expanded state, expect no dot
259+
cy.findByTestId('debug-badge-dot').should('not.exist')
260+
261+
// collapse the nav
262+
cy.findByTestId('toggle-sidebar').click()
263+
264+
// in collapsed state, find the dot
265+
// TODO (Percy): when Percy is enabled for e2e tests
266+
// we can stop testing the class name directly here
267+
cy.findByLabelText('New Debug feature', {
268+
selector: '[data-cy=debug-badge-dot]',
269+
})
270+
.should('be.visible')
271+
.and('have.class', 'bg-jade-500')
272+
.invoke('text')
273+
.should('eq', '')
274+
275+
// go to the Spec Runner route by clicking on a test
276+
cy.contains('a', 'flower.png').click()
277+
278+
cy.findByTestId('debug-badge-dot').should('have.class', 'bg-gray-800')
279+
})
280+
253281
it('Specs sidebar nav link is not active when a test is running', () => {
254282
cy.location('hash').should('equal', '#/specs')
255283
cy.contains('.router-link-exact-active', 'Specs')

packages/app/src/navigation/SidebarNavigation.cy.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,18 @@ describe('SidebarNavigation', () => {
133133
mountComponent()
134134
cy.tick(1000) //wait for debounce
135135

136-
cy.findByLabelText('New Debug feature').should('be.visible').contains('New')
136+
cy.findByLabelText('New Debug feature', {
137+
selector: '[data-cy=debug-badge-dot]',
138+
}).should('be.visible')
139+
137140
cy.percySnapshot('Debug Badge:collapsed')
138141

139142
cy.findByLabelText(defaultMessages.sidebar.toggleLabel.collapsed, {
140143
selector: 'button',
141144
}).click()
142145

146+
cy.tick(1000) //wait for transition
147+
cy.findByLabelText('New Debug feature').should('be.visible').contains('New')
143148
cy.percySnapshot('Debug Badge:expanded badge')
144149
})
145150

@@ -149,7 +154,9 @@ describe('SidebarNavigation', () => {
149154
for (const status of ['NOTESTS', 'RUNNING'] as CloudRunStatus[]) {
150155
mountComponent({ cloudProject: { status, numFailedTests: 0 } })
151156
cy.tick(1000) //wait for debounce
152-
cy.findByLabelText('New Debug feature').should('be.visible').contains('New')
157+
cy.findByLabelText('New Debug feature', {
158+
selector: '[data-cy=debug-badge-dot]',
159+
}).should('be.visible')
153160
}
154161
})
155162

@@ -218,8 +225,9 @@ describe('SidebarNavigation', () => {
218225
mountComponent({ online: false })
219226

220227
cy.tick(1000) //wait for debounce
221-
222-
cy.findByLabelText('New Debug feature').should('be.visible').contains('New')
228+
cy.findByLabelText('New Debug feature', {
229+
selector: '[data-cy=debug-badge-dot]',
230+
}).should('be.visible')
223231
})
224232
})
225233
})

packages/app/src/navigation/SidebarNavigationRow.vue

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,19 @@
4848
{{ name }}
4949
</span>
5050
<span
51-
v-if="badge"
51+
v-if="badge && !showDot"
5252
:aria-label="badge.label"
5353
class="rounded-md font-medium text-white p-4px transition-opacity z-1"
5454
:class="[badgeVariant, badgeColorStyles[badge.status], {'opacity-0': transitioning}]"
5555
>
5656
{{ badge.value }}
5757
</span>
58+
<div
59+
v-else-if="badge && showDot"
60+
:class="[{'opacity-0': transitioning}, dotClass]"
61+
:aria-label="badge.label"
62+
data-cy="debug-badge-dot"
63+
/>
5864
</div>
5965
<template #popper>
6066
{{ name }}
@@ -66,9 +72,14 @@
6672
import { computed, FunctionalComponent, SVGAttributes, watch, ref } from 'vue'
6773
import Tooltip from '@packages/frontend-shared/src/components/Tooltip.vue'
6874
import { promiseTimeout } from '@vueuse/core'
75+
import { useI18n } from '@cy/i18n'
76+
import { useRoute } from 'vue-router'
6977
7078
export type Badge = { value: string, status: 'success' | 'failed' | 'error', label: string }
7179
80+
const { t } = useI18n()
81+
const route = useRoute()
82+
7283
const props = withDefaults(defineProps <{
7384
icon: FunctionalComponent<SVGAttributes>
7485
name: string
@@ -107,6 +118,26 @@ const badgeColorStyles = {
107118
'error': 'bg-warning-500',
108119
}
109120
121+
const showDot = computed(() => {
122+
return props.badge.value === t('sidebar.debug.new') && !props.isNavBarExpanded
123+
})
124+
125+
const dotClass = computed(() => {
126+
const dotColor = route.name === 'SpecRunner' ? 'bg-gray-800' : 'bg-jade-500'
127+
128+
return `${dotColor}
129+
w-10px
130+
h-10px
131+
relative
132+
-bottom-7px
133+
-left-30px
134+
flex-shrink-0
135+
z-1
136+
border-2px
137+
border-gray-1000
138+
rounded-full`
139+
})
140+
110141
const transitioning = ref(false)
111142
112143
// Badge is either absolutely positioned or relative. Since the navbar expands with an animation,

0 commit comments

Comments
 (0)