Skip to content
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
7 changes: 5 additions & 2 deletions frontend/src/components/ViewHeader.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script setup lang="ts">
// A page's title row: the heading, the page's actions on the right, and an optional caption under
// the heading inside the row (the period Statistics shows). A line about the page waits behind an
// info button beside the heading. Under it all, the notice that the server cannot be reached, so
// info button beside the heading, shown like the cards' own while "Show info icons" is on
// (Settings > General). Under it all, the notice that the server cannot be reached, so
// every page says so.
// A phone's top bar takes the whole row: the heading with its info button and caption on the left,
// the page's actions as icons on the right. The row itself is then left empty, and hidden.
Expand All @@ -10,6 +11,7 @@ import { useI18n } from 'vue-i18n'
import DetailModal from '@/components/DetailModal.vue'
import OfflineNotice from '@/components/OfflineNotice.vue'
import { useMediaQuery } from '@/composables/useMediaQuery'
import { useUiSettingsStore } from '@/stores/settingsUi'
import { PHONE_MEDIA_QUERY } from '@/utils/viewport'

defineProps<{
Expand All @@ -20,6 +22,7 @@ defineProps<{

const { t } = useI18n()
const isPhone = useMediaQuery(PHONE_MEDIA_QUERY)
const settings = useUiSettingsStore()
const aboutOpen = ref(false)
</script>

Expand All @@ -30,7 +33,7 @@ const aboutOpen = ref(false)
<div class="view-header__title">
<h1>{{ title }}</h1>
<button
v-if="subtitle"
v-if="subtitle && settings.showCardInfoIcons"
type="button"
class="view-header__info"
aria-haspopup="dialog"
Expand Down
26 changes: 23 additions & 3 deletions frontend/src/components/__tests__/ViewHeader.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount } from '@vue/test-utils'
import { createI18n } from 'vue-i18n'
import { h } from 'vue'
import { createPinia, setActivePinia, type Pinia } from 'pinia'
import { h, nextTick } from 'vue'
import ViewHeader from '../ViewHeader.vue'
import en from '@/locales/en.json'
import { useUiSettingsStore } from '@/stores/settingsUi'
import { PHONE_MEDIA_QUERY } from '@/utils/viewport'

vi.mock('@/components/OfflineNotice.vue', () => ({ default: { template: '<div />' } }))

const i18n = createI18n({ legacy: false, locale: 'en', messages: { en } })
let pinia: Pinia

function mountHeader(
props: { title: string; caption?: string; subtitle?: string },
Expand All @@ -18,11 +21,17 @@ function mountHeader(
props,
slots: actions ? { actions } : {},
attachTo: document.body,
global: { plugins: [i18n], stubs: { FontAwesomeIcon: true } },
global: { plugins: [i18n, pinia], stubs: { FontAwesomeIcon: true } },
})
}

describe('ViewHeader', () => {
beforeEach(() => {
localStorage.clear()
pinia = createPinia()
setActivePinia(pinia)
})

afterEach(() => {
vi.unstubAllGlobals()
document.body.innerHTML = ''
Expand All @@ -44,6 +53,17 @@ describe('ViewHeader', () => {
expect(wrapper.find('.view-header__info').exists()).toBe(false)
})

// The cards' info buttons and the page's go together: "Show info icons" in Settings.
it('leaves the info button out while info icons are switched off', async () => {
const wrapper = mountHeader({ title: 'Trip log', subtitle: 'Every trip, for the taxman.' })
expect(wrapper.find('.view-header__info').exists()).toBe(true)

useUiSettingsStore(pinia).showCardInfoIcons = false
await nextTick()

expect(wrapper.find('.view-header__info').exists()).toBe(false)
})

it('opens the line about the page from its info button', async () => {
const wrapper = mountHeader({ title: 'Trip log', subtitle: 'Every trip, for the taxman.' })
const info = wrapper.get('.view-header__info')
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@
},
"dashboard": {
"cardInfoIcons": "Show info icons",
"cardInfoIconsDesc": "Adds a button to each dashboard and statistics card that explains what the card shows.",
"cardInfoIconsDesc": "Adds a button beside each page's title, and to each dashboard and statistics card, that explains what it shows.",
"mapBackdrop": "Map behind the dashboard",
"mapBackdropDesc": "Shows the car's map across the whole dashboard, with the cards over it and the car parked where the location card was. Phones keep the location card."
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@
},
"dashboard": {
"cardInfoIcons": "Mostrar iconos de información",
"cardInfoIconsDesc": "Añade a cada tarjeta del panel y de las estadísticas un botón que explica lo que muestra.",
"cardInfoIconsDesc": "Añade junto al título de cada página, y a cada tarjeta del panel y de las estadísticas, un botón que explica lo que muestra.",
"mapBackdrop": "Mapa detrás del panel",
"mapBackdropDesc": "Muestra el mapa del coche en todo el panel, con las tarjetas encima y el coche aparcado donde estaba la tarjeta de ubicación. En los teléfonos se mantiene la tarjeta de ubicación."
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@
},
"dashboard": {
"cardInfoIcons": "Info-iconen tonen",
"cardInfoIconsDesc": "Voegt aan elke kaart op het dashboard en bij de statistieken een knop toe die uitlegt wat de kaart toont.",
"cardInfoIconsDesc": "Voegt naast de titel van elke pagina, en aan elke kaart op het dashboard en bij de statistieken, een knop toe die uitlegt wat die toont.",
"mapBackdrop": "Kaart achter het dashboard",
"mapBackdropDesc": "Toont de kaart van de auto over het hele dashboard, met de kaarten erboven en de auto geparkeerd waar de locatiekaart stond. Telefoons houden de locatiekaart."
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@
},
"dashboard": {
"cardInfoIcons": "Mostrar ícones de informação",
"cardInfoIconsDesc": "Adiciona a cada cartão do painel e das estatísticas um botão que explica o que o cartão mostra.",
"cardInfoIconsDesc": "Adiciona ao lado do título de cada página, e a cada cartão do painel e das estatísticas, um botão que explica o que mostra.",
"mapBackdrop": "Mapa atrás do painel",
"mapBackdropDesc": "Mostra o mapa do carro em todo o painel, com os cartões por cima e o carro estacionado onde estava o cartão de localização. No telemóvel, o cartão de localização mantém-se."
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@
},
"dashboard": {
"cardInfoIcons": "Mostrar ícones de informação",
"cardInfoIconsDesc": "Adiciona a cada cartão do painel e das estatísticas um botão que explica o que o cartão mostra.",
"cardInfoIconsDesc": "Adiciona ao lado do título de cada página, e a cada cartão do painel e das estatísticas, um botão que explica o que ele mostra.",
"mapBackdrop": "Mapa atrás do painel",
"mapBackdropDesc": "Mostra o mapa do carro em todo o painel, com os cartões por cima e o carro estacionado onde estava o cartão de localização. No celular, o cartão de localização continua."
},
Expand Down
Loading