Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: label text should be clickable to toggle snapshot highlight #21122

Merged
merged 9 commits into from
Apr 20, 2022
8 changes: 6 additions & 2 deletions packages/app/cypress/e2e/runner/runner.ui.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { loadSpec } from './support/spec-loader'
import defaultMessages from '@packages/frontend-shared/src/locales/en-US.json'

describe('src/cypress/runner', () => {
describe('tests finish with correct state', () => {
Expand Down Expand Up @@ -110,8 +111,10 @@ describe('src/cypress/runner', () => {
.click()
.should('have.class', 'command-is-pinned')

const { highlightsLabel } = defaultMessages.runner.snapshot

// disable highlights
cy.get('[id="toggle-highlights"]')
cy.findByLabelText(highlightsLabel)
.should('have.attr', 'aria-checked', 'true')
.click()
.should('have.attr', 'aria-checked', 'false')
Expand All @@ -123,7 +126,8 @@ describe('src/cypress/runner', () => {
.click()
.should('have.class', 'command-is-pinned')

cy.get('[id="toggle-highlights"]').should('have.attr', 'aria-checked', 'true')
cy.findByLabelText(highlightsLabel)
.should('have.attr', 'aria-checked', 'true')
})

it('correctly resets named snapshot toggle state when pinning new command', () => {
Expand Down
5 changes: 2 additions & 3 deletions packages/app/src/runner/SnapshotControls.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import SnapshotControls from './SnapshotControls.vue'
import { autSnapshot } from '../../cypress/support/fixtures'
import { useSnapshotStore } from './snapshot-store'
import { createEventManager, createTestAutIframe } from '../../cypress/component/support/ctSupport'
import { defaultMessages } from '@cy/i18n'

const snapshotWithSnapshots = { ...autSnapshot }
const snapshotPinned = { ...autSnapshot, snapshots: [] }
Expand Down Expand Up @@ -91,9 +92,7 @@ describe('SnapshotControls', { viewportHeight: 200, viewportWidth: 500 }, () =>

mountSnapshotControls(eventManager, autIframe)
cy.get('body')
.findByText('Highlights')
.should('be.visible')
.findByLabelText('Toggle highlights')
.findByLabelText(defaultMessages.runner.snapshot.highlightsLabel)
.click({ force: true })
})

Expand Down
10 changes: 5 additions & 5 deletions packages/app/src/runner/SnapshotHighlightControls.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<template>
<div class="rounded flex font-medium bg-gray-900 py-2px px-12px text-gray-200 text-14px leading-20px gap-8px items-center">
<label
class="hidden"
for="toggle-highlights"
>{{ t('runner.snapshot.toggleHighlights') }}</label>
<Switch
name="toggle-highlights"
:value="props.value"
size="sm"
@update="emits('toggle')"
/>
{{ t('runner.snapshot.highlightsLabel') }}
<label
for="toggle-highlights"
class="cursor-pointer"
>{{ t('runner.snapshot.highlightsLabel') }}
</label>
</div>
</template>

Expand Down
1 change: 0 additions & 1 deletion packages/frontend-shared/src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,6 @@
"troubleRendering": "if you're having trouble rendering your components properly."
},
"snapshot": {
"toggleHighlights": "Toggle highlights",
"highlightsLabel": "Highlights",
"testsRunningError": "Cannot show Snapshot while tests are running",
"snapshotMissingError": "The snapshot is missing. Displaying current state of the DOM.",
Expand Down