Skip to content
Open
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
46 changes: 42 additions & 4 deletions reposilite-frontend/src/components/search/SearchView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import { mount, flushPromises } from '@vue/test-utils'
import type { DOMWrapper, VueWrapper } from '@vue/test-utils'
import { createRouter, createMemoryHistory } from 'vue-router'
import type { Router } from 'vue-router'
import type { Ref } from 'vue'
import type { Component, Ref } from 'vue'
import MdCard from '../md/MdCard.vue'
import MdSideSheet from '../md/MdSideSheet.vue'
import * as session from '../../store/session'
import SearchView from './SearchView.vue'

Expand Down Expand Up @@ -842,18 +844,54 @@ describe('SearchView keyboard', () => {
expect(wrapper.find('[role="dialog"]').exists()).toBe(true)
expect(wrapper.find('[data-test="open-filters"]').attributes('aria-expanded')).toBe('true')

await press(wrapper.find('[data-test="filter-panel"]'), 'Escape')
await press(wrapper.find('[role="dialog"]'), 'Escape')

expect(wrapper.find('[role="dialog"]').exists()).toBe(false)
})

it('draws the filter sheet with the shared side sheet', async () => {
await mountAt('/search')

await wrapper.find('[data-test="open-filters"]').trigger('click')

const sheet = wrapper.findComponent(MdSideSheet as Component)
expect(sheet.exists(), 'the filters open in MdSideSheet, not in a view-drawn overlay').toBe(true)
expect(sheet.find('[data-test="filter-panel"]').exists(), 'the filter contents sit inside the sheet').toBe(true)
expect(sheet.find('[data-test="show-results"]').exists(), 'the sheet keeps its Show results action').toBe(true)
})

it('names the filter sheet by its Filters heading', async () => {
await mountAt('/search')

await wrapper.find('[data-test="open-filters"]').trigger('click')

const sheet = wrapper.find('[role="dialog"]')
const labelId = sheet.attributes('aria-labelledby')
expect(labelId, 'the sheet is labelled by an id').toBeTruthy()
expect(sheet.element.querySelector(`#${labelId}`)?.textContent?.trim()).toBe('Filters')
})

it('returns focus to the Filters trigger when the sheet closes on Escape', async () => {
await mountAt('/search')
const trigger = wrapper.find<HTMLElement>('[data-test="open-filters"]')

trigger.element.focus()
await trigger.trigger('click')
await flushPromises()
await press(wrapper.find('[role="dialog"]'), 'Escape')
await flushPromises()

expect(wrapper.find('[role="dialog"]').exists()).toBe(false)
expect(document.activeElement, 'focus goes back to the button that opened the sheet').toBe(trigger.element)
})
})

describe('SearchView cards', () => {
it('draws the results list as a low md-card without padding', async () => {
await mountAt('/search')

const list = wrapper.find('[data-test="results"]')
expect(list.attributes('data-ingot-component'), 'the results sit on a shared card').toBe('md-card')
expect(wrapper.findAllComponents(MdCard as Component).map(card => card.element as Element), 'the results sit on a shared card').toContain(list.element)
expect(list.attributes('data-variant'), 'the results lie flat on the page').toBe('low')
})

Expand All @@ -862,7 +900,7 @@ describe('SearchView cards', () => {
await mountAt('/search', { client })

const skeleton = wrapper.find('[data-test="skeleton"]')
expect(skeleton.attributes('data-ingot-component'), 'the skeleton sits on a shared card').toBe('md-card')
expect(wrapper.findAllComponents(MdCard as Component).map(card => card.element as Element), 'the skeleton sits on a shared card').toContain(skeleton.element)
expect(skeleton.attributes('data-variant'), 'the skeleton lies flat on the page').toBe('low')
})
})
Expand Down
60 changes: 28 additions & 32 deletions reposilite-frontend/src/components/search/SearchView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import MdSkeleton from '../md/MdSkeleton.vue'
import MdStatePanel from '../md/MdStatePanel.vue'
import MdPage from '../md/MdPage.vue'
import MdSelect from '../md/MdSelect.vue'
import MdSideSheet from '../md/MdSideSheet.vue'
import SearchBar from './SearchBar.vue'
import SearchFilters from './SearchFilters.vue'
import SearchResultRow from './SearchResultRow.vue'
Expand Down Expand Up @@ -342,38 +343,34 @@ const toggleRow = (item: SearchItem) => {
</p>

<div class="mt-6 grid grid-cols-[minmax(0,1fr)] gap-6 large:grid-cols-[minmax(240px,300px)_minmax(0,1fr)] large:items-start">
<!-- Below 1024px the filters are a modal sheet; from there on they are a column beside the results. -->
<!-- Below 1024px the filters are the Filters side sheet; from there on they are a column beside the results. -->
<div
:class="sheetOpen ? 'fixed inset-0 z-40 flex flex-col bg-surface large:static large:z-auto large:bg-transparent' : 'hidden large:block'"
:role="sheetOpen ? 'dialog' : undefined"
:aria-modal="sheetOpen ? 'true' : undefined"
v-if="!sheetOpen"
class="hidden large:block"
:aria-labelledby="filtersTitleId"
data-test="filter-panel"
@keydown.esc="toggleSheet(false)"
>
<div class="flex items-center justify-between px-4 pt-4 large:hidden">
<h2
:id="filtersTitleId"
class="md-title-large text-on-surface"
>
Filters
</h2>
<MdButton
variant="text"
data-test="close-filters"
@click="toggleSheet(false)"
>
Close
</MdButton>
</div>
<h2
v-if="!sheetOpen"
:id="filtersTitleId"
class="sr-only"
>
Filters
</h2>
<div class="flex-1 overflow-y-auto p-4 large:overflow-visible large:p-0">
<SearchFilters
:query="query"
:facets="facets"
:attributes="attributeFacets"
:attribute-labels="facetable"
@change="changeFilter"
@reset="reset"
/>
</div>

<MdSideSheet
v-model:open="sheetOpen"
title="Filters"
>
<div data-test="filter-panel">
<SearchFilters
:query="query"
:facets="facets"
Expand All @@ -383,16 +380,15 @@ const toggleRow = (item: SearchItem) => {
@reset="reset"
/>
</div>
<div class="p-4 large:hidden">
<MdButton
variant="filled"
class="w-full"
@click="toggleSheet(false)"
>
Show results
</MdButton>
</div>
</div>
<MdButton
variant="filled"
class="w-full"
data-test="show-results"
@click="toggleSheet(false)"
>
Show results
</MdButton>
</MdSideSheet>

<section
aria-labelledby="search-results-title"
Expand Down
Loading