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: Make spec row clickable across entire width #22105

Merged
merged 5 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need both the click handler here and the one that emits the @toggleRow event from SpecsListRowItem? Seems like the SpecsListRowItem handler should catch clicks on the RowDirectory at this point.

/>
</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>