Skip to content

Commit

Permalink
fix: Make spec row clickable across entire width (#22105)
Browse files Browse the repository at this point in the history
* fix: Make spec row clickable across entire width

* Move click-sensitive row action wrapper to surround entire row
* Add styles to highlight spec icon on hocus to match Figma
* Small text highlight style change to match Figma

* Add missing data-cy selector

* Add tests for row expansion behaviors

* Fix directory row styling issues
  • Loading branch information
mike-plummer authored Jun 8, 2022
1 parent e5c1f91 commit 0298b97
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/app/src/specs/RowDirectory.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<button
class="h-full grid gap-8px grid-cols-[14px,16px,auto] items-center focus:outline-transparent"
class="h-full grid gap-8px grid-cols-[14px,16px,auto] items-center focus:outline-none"
:data-cy="`row-directory-depth-${depth}`"
:aria-expanded="expanded"
>
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/specs/SpecItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
data-cy="spec-item"
>
<i-cy-document-blank_x16
class="icon-light-gray-50 icon-dark-gray-200"
class="icon-light-gray-50 icon-dark-gray-200 group-hocus:icon-light-indigo-200 group-hocus:icon-dark-indigo-400"
/>

<div class="text-gray-400 text-indigo-500 group-hocus:text-indigo-600">
<HighlightedText
:text="fileName"
:indexes="indexes.filter((idx) => idx < fileName.length)"
class="font-medium text-indigo-500 group-hocus:text-indigo-600"
class="font-medium text-indigo-500 group-hocus:text-indigo-700"
highlight-classes="text-gray-1000"
/>
<HighlightedText
Expand Down
33 changes: 11 additions & 22 deletions packages/app/src/specs/SpecsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,18 @@
:key="row.index"
:data-cy="row.data.isLeaf ? 'spec-list-file' : 'spec-list-directory'"
:data-cy-row="row.data.data?.baseName"
:is-leaf="row.data.isLeaf"
:route="{ path: '/specs/runner', query: { file: row.data.data?.relative?.replace(/\\/g, '/') } }"
@toggleRow="row.data.toggle"
>
<template #file>
<RouterLink
v-if="row.data.isLeaf && row.data"
:key="row.data.data?.absolute"
class="focus:outline-transparent"
:to="{ path: '/specs/runner', query: { file: row.data.data?.relative?.replace(/\\/g, '/') } }"
data-cy="spec-item-link"
@click.meta.prevent="handleCtrlClick"
@click.ctrl.prevent="handleCtrlClick"
>
<SpecItem
:file-name="row.data.data?.fileName || row.data.name"
:extension="row.data.data?.specFileExtension || ''"
:indexes="row.data.data?.fileIndexes"
:style="{ paddingLeft: `${((row.data.depth - 2) * 10) + 22}px` }"
/>
</RouterLink>
<SpecItem
v-if="row.data.isLeaf"
:file-name="row.data.data?.fileName || row.data.name"
:extension="row.data.data?.specFileExtension || ''"
:indexes="row.data.data?.fileIndexes"
:style="{ paddingLeft: `${((row.data.depth - 2) * 10) + 22}px` }"
/>
<RowDirectory
v-else
Expand All @@ -96,7 +90,7 @@
:style="{ paddingLeft: `${(row.data.depth - 2) * 10}px` }"
:indexes="getDirIndexes(row.data)"
:aria-controls="getIdIfDirectory(row)"
@click="row.data.toggle"
@click.stop="row.data.toggle"
/>
</template>
Expand Down Expand Up @@ -241,11 +235,6 @@ const { containerProps, list, wrapperProps, scrollTo } = useVirtualList(treeSpec
// reset scroll position to top of list
watch(() => treeSpecList.value, () => scrollTo(0))
function handleCtrlClick () {
// noop intended to reduce the chances of opening tests multiple tabs
// which is not a supported state in Cypress
}
function getIdIfDirectory (row) {
if (row.data.isLeaf && row.data) {
return undefined
Expand Down
53 changes: 53 additions & 0 deletions packages/app/src/specs/SpecsListRowItem.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import SpecsListRowItem from './SpecsListRowItem.vue'

describe('SpecItem', () => {
it('renders a SpecsListRowItem as leaf', () => {
const toggleRowHandler = cy.stub()

cy.mount(() => (
<SpecsListRowItem
isLeaf={true}
route={{ path: '/specs/runner', query: { file: '' } }}
onToggleRow={toggleRowHandler}
// @ts-ignore - doesn't know about vSlots
vSlots={{
file: () => <span>File Name</span>,
'git-info': () => <span>Git Info</span>,
}}
/>))

// Clicking directly on file name section should trigger row
cy.get('[data-cy="specs-list-row-file"]').click()
cy.wrap(toggleRowHandler).should('have.callCount', 1)

// Clicking directory on git info section should trigger row
cy.get('[data-cy="specs-list-row-git-info"]').click()
cy.wrap(toggleRowHandler).should('have.callCount', 2)

// Clicking elsewhere on row should trigger row
cy.get('[data-cy="spec-item-link"]').click('right')
cy.wrap(toggleRowHandler).should('have.callCount', 3)
})

it('renders a SpecsListRowItem as non-leaf', () => {
const toggleRowHandler = cy.stub()

cy.mount(() => (
<SpecsListRowItem
isLeaf={false}
onToggleRow={toggleRowHandler}
// @ts-ignore - doesn't know about vSlots
vSlots={{
file: () => <span>Directory Name</span>,
}}
/>))

// Clicking directly on file name section should trigger row
cy.get('[data-cy="specs-list-row-file"]').click()
cy.wrap(toggleRowHandler).should('have.callCount', 1)

// Clicking elsewhere on row should trigger row
cy.get('[data-cy="spec-item-directory"]').click('right')
cy.wrap(toggleRowHandler).should('have.callCount', 2)
})
})
47 changes: 36 additions & 11 deletions packages/app/src/specs/SpecsListRowItem.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
<template>
<div
class="h-full outline-none border-gray-50 ring-inset grid grid-cols-2 group focus-within:ring-indigo-300 focus-within:ring-1 children:cursor-pointer"
data-cy="specs-list-row"
>
<div>
<slot name="file" />
</div>

<div>
<slot name="git-info" />
</div>
<div data-cy="specs-list-row">
<component
:is="isLeaf ? 'RouterLink' : 'div'"
class="h-full outline-none border-gray-50 ring-inset grid grid-cols-2 group focus:outline-transparent focus-within:ring-indigo-300 focus-within:ring-1 children:cursor-pointer"
:to="route"
:data-cy="isLeaf ? 'spec-item-link' : 'spec-item-directory'"
@click="emit('toggleRow')"
@click.meta.prevent="handleCtrlClick"
@click.ctrl.prevent="handleCtrlClick"
>
<div data-cy="specs-list-row-file">
<slot name="file" />
</div>

<div data-cy="specs-list-row-git-info">
<slot name="git-info" />
</div>
</component>
</div>
</template>

<script setup lang="ts">
import type { RouteLocationRaw } from 'vue-router'
defineProps<{
isLeaf: boolean
route?: RouteLocationRaw
}>()
const emit = defineEmits<{
(event: 'toggleRow'): void
}>()
function handleCtrlClick (): void {
// noop intended to reduce the chances of opening tests multiple tabs
// which is not a supported state in Cypress
}
</script>

3 comments on commit 0298b97

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0298b97 Jun 8, 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.1.0/linux-x64/develop-0298b97477b470f89fc66a2a7c223cafb5b94218/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0298b97 Jun 8, 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.1.0/darwin-x64/develop-0298b97477b470f89fc66a2a7c223cafb5b94218/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0298b97 Jun 8, 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.1.0/win32-x64/develop-0298b97477b470f89fc66a2a7c223cafb5b94218/cypress.tgz

Please sign in to comment.