mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-18 21:16:47 +00:00
eae8480728
* feat(studio): widen the document, and stop a save from losing it The schema gains what the elements coming after it need: an icon element, a badge that can be restyled rather than only placed, a date and a pair of coordinates on a text binding, and the map's route, pin and road settings. Widening it turned up two ways a book could fail to come back. The mood badge writes its code into the document, and the schema said that code was exactly two characters, from a first draft where it was a country. The real codes are words, so every save was rejected and the read that followed parsed to an empty document: seventeen spreads in, nothing out. Widened to what the badge actually writes, and normalizeBookDocument now drops the elements it cannot read rather than the whole book, so one bad element costs a picture frame instead of a year of work. The other was the body limit. The parser allowed 100kb for everything, and a book with a routed map measures past that, so the save came back 413 and the editor sat on "not saved" with no way forward. Book writes get their own parser at 8mb; everything else keeps the limit it had. * feat(studio): a date, a pair of coordinates and an icon library Three things that had to be drawn by hand before. A journal entry knows when it happened and where, and neither could be put on a page: you read the date off the entry and typed it into a text box, where it then stayed while the entry moved. Both are chips now, next to the title and the story, and both follow their entry the way the others do. The formatting lives in one place so the chip, the template and the resolver cannot drift by a character — coordinates in degrees or decimals, the date in the reader's language. The icons are the whole Lucide set, searchable, placed as a real element with its own colour and stroke rather than as a character in a font. The stroke is deliberately not called strokeWidth: three separate places rescale a field of that name by page width, and an icon whose line thins as the book grows is not what anyone asked for. And the badges finally have their settings. A mood or weather badge could be placed and then only moved: the icon's colour was fixed, the icon could not be turned off, and there was no way to keep the icon and drop the words. All three are switches now, with the colour following the badge unless you say otherwise. * fix(studio): let a placed entry field follow its journal entry again The inspector says a bound field follows the journal entry and that editing it here breaks the link. The first half was not true: nothing ever re-read the entry, so renaming a title in Journey left the old words on the page for good, and the same went for every other bound field. The resolver runs where the journey is loaded and re-reads the fields that still point at an entry. What it will not do is as important as what it does. A field somebody has typed over stays typed over, an entry that is gone leaves its element alone rather than blanking it, and an entry that answers with nothing never wipes what is already on the page. Formatted fields — the date, the coordinates — are only re-read when the format itself changed, which is what keeps this from quietly rewriting books that already exist: an entry whose date was placed as a heading and then set in capitals keeps its capitals. Checked against the real database before it shipped, where the first version overwrote three of them. * feat(studio): start a new book empty, with six layouts to choose from A new journey opened onto a book that had already been laid out, which is the wrong first move: it decides the shape of somebody's book before they have seen it, and undoing it means deleting pages one at a time. A new book starts empty now, and the auto layout runs when it is asked to. The layouts themselves went from two to six, so choosing one is a real choice: what was there covered a photo-heavy spread and a text-heavy one and nothing in between. * fix(studio): hyphenate the export the way the editor does, and set the bleed Two things the press sees and the editor did not. A paragraph broke in different places in the PDF than on screen. The print document is written from scratch and never carried a language, so the browser hyphenated the editor's German and the export's nothing-in- particular. It takes the page's own language now. The wait for the sheet to be ready also covers the images inside SVG, with a ceiling, so a map that is slow to draw does not print half-finished. And the bleed and the safe margin are typeable. Both were baked into every page preset at what a photo-book vendor usually asks for, 3mm and 5mm, with no control anywhere. That is fine until a printer asks for 5 and 10, at which point the book cannot be made here at all: the export carries the wrong bleed and the crop marks sit in the wrong place, which nobody finds until the guillotine has run. * feat(studio): rebuild the inspector The panel on the right had grown by accretion: every element type had added its own controls in whatever shape suited it that day, so the same idea — a colour, a size, a toggle — looked different depending on what you had selected, and long panels were a wall of unlabelled fields. It is one set of controls now, used by every element: foldable sections, a line that holds a label and its control, radio choices, checkboxes, the app's own toggle, and a number field that holds a draft so typing "500" is not read as "5", clamped and written back under the cursor. Duplicated controls were merged rather than deleted; nothing an element could do before it cannot do now. The head carries the element's identity and its actions, so what you have selected is readable without counting fields, and the sections have room to breathe: what was there was correct and unreadable. * feat(studio): a route map worth printing The map in a book was a straight grey line between grey dots on a tile that was chosen for a screen. At print size those tiles are read at roughly four times the resolution they were fetched for, which is why it looked soft next to everything around it. The imagery comes from sources that hold up on paper: NASA's shaded relief and EOX's cloudless Sentinel-2, both licensed for it, picked at a zoom that matches the printer rather than the screen. Tiles are fetched at twice the density where the source offers it, and the seam between them scales with the tile instead of sitting at a fixed fraction of a millimetre, which under editor zoom fell below one device pixel and showed as white threads. The route is drawn rather than plotted. A leg that was never recorded bows, by an amount that grows with its length and turns away from the pole, and it dashes, because an inferred line should not claim to be a track — a recorded track never bows. Both strokes are laid down in two passes, casing then core, so the line stays legible over dark sea and bright desert alike. Legs can follow roads instead, routed leg by leg with the geometry thinned before it is stored, which is the setting a road trip wants and the one a flight cannot have. Stops carry their own first photograph, cut to a circle by a stencil that exists — the first one was written into a defs block that only appears on a map clipped to a coastline, so on an ordinary map it clipped nothing and the photographs sat square on the page. A stop with no photograph of its own is numbered rather than handed one from elsewhere in the journey: a marker at one place showing a picture taken at another is a caption that lies. Whatever the frame, the whole route is inside it. The window takes the frame's aspect, so the fit and the imagery agree instead of one containing what the other covers, and a map dragged narrow no longer cuts off its end. Each linked trip can carry its own map, and a map notices a photograph added to a stop afterwards rather than having to be placed again. * i18n(journey): the new Studio strings, in all 23 locales * test(journey): pin the coverage the map work brought with it The journey domain measures higher than its floor after this round, so the floor follows it up. Only journey moved; the generator's suggestion would have taken memories' functions down a point, and a ratchet that can fall is not a ratchet. * test(studio): cover the thinning that keeps a road route saveable The one path in roadRoute nothing exercised, and the one that matters most: a router answers a long drive with thousands of points at a precision no press can resolve, and all of it goes into the document. Keeping a leg whole is what pushed a real book past the body limit. Both ends have to survive so the line still meets its stops, and the spacing has to stay even, because cutting a run out of the middle would straighten exactly the bends somebody wanted to see.
559 lines
18 KiB
TypeScript
559 lines
18 KiB
TypeScript
import { describe, it, expect, beforeEach } from 'vitest'
|
||
import type { BookDocument, BookElement, JourneyStats } from '@trek/shared'
|
||
import {
|
||
bookBadgeElementSchema, bookCountriesElementSchema, bookListElementSchema,
|
||
bookMapElementSchema, bookPageSetupSchema, bookStatsElementSchema, journeyStatsSchema,
|
||
} from '@trek/shared'
|
||
import { fireEvent, render, screen, within } from '../../helpers/render'
|
||
import { StudioInspector } from '../../../src/components/Studio/StudioInspector'
|
||
import { useStudioStore } from '../../../src/store/studioStore'
|
||
|
||
/**
|
||
* The inspector, on the five travel elements (#1973).
|
||
*
|
||
* The panel was rebuilt: same functions, new structure. Sections fold, booleans
|
||
* are the app's switch instead of a chip, a set of several carries a tick, and
|
||
* duplicate, lock and delete moved out of "Arrange" and into the panel head.
|
||
* Nothing in the suite rendered the inspector at all, so a control that came
|
||
* out of that rebuild wired to nothing would have been found in a printed book
|
||
* rather than here.
|
||
*
|
||
* Two rules for what follows. The whole inspector is mounted rather than the
|
||
* travel half on its own, because the tail every travel element shares, type,
|
||
* colour, position, arrange, is drawn by the outer panel. And what is asserted
|
||
* is the document the store holds, not the markup: the question is whether a
|
||
* control still writes the field it used to write, whichever section it now
|
||
* lives in.
|
||
*/
|
||
|
||
const page = bookPageSetupSchema.parse({
|
||
preset: 'square-210', pageWidth: 210, pageHeight: 210, bleed: 3, safe: 5,
|
||
})
|
||
|
||
const frame = { x: 10, y: 10, w: 120, h: 90 }
|
||
|
||
/** A journey with figures no element below starts out agreeing with. */
|
||
const stats: JourneyStats = journeyStatsSchema.parse({
|
||
journeyId: 1,
|
||
distance: 1234, days: 5, steps: 7, photos: 12, places: 9, furthest: 400,
|
||
countries: [{ code: 'IS', name: 'Iceland', places: 9, firstVisit: '2026-01-01' }],
|
||
points: [
|
||
{ lat: 64.14, lng: -21.94, label: 'Reykjavik', date: '2026-01-01', country: 'IS' },
|
||
{ lat: 65.68, lng: -18.09, label: 'Akureyri', date: '2026-01-04', country: 'IS' },
|
||
],
|
||
start: '2026-01-01', end: '2026-01-05',
|
||
})
|
||
|
||
const mapEl = (over: Record<string, unknown> = {}): BookElement => bookMapElementSchema.parse({
|
||
id: 'm1', kind: 'map', frame, countries: ['IS'],
|
||
points: [{ lat: 64.14, lng: -21.94, label: 'Reykjavik' }],
|
||
...over,
|
||
}) as BookElement
|
||
|
||
const statsEl = (over: Record<string, unknown> = {}): BookElement => bookStatsElementSchema.parse({
|
||
id: 's1', kind: 'stats', frame, ...over,
|
||
}) as BookElement
|
||
|
||
const countriesEl = (over: Record<string, unknown> = {}): BookElement => bookCountriesElementSchema.parse({
|
||
id: 'c1', kind: 'countries', frame, codes: ['IS', 'NO'], names: ['Iceland', 'Norway'], ...over,
|
||
}) as BookElement
|
||
|
||
const badgeEl = (over: Record<string, unknown> = {}): BookElement => bookBadgeElementSchema.parse({
|
||
id: 'b1', kind: 'badge', frame, variant: 'flag', code: 'IS', text: 'ICELAND', ...over,
|
||
}) as BookElement
|
||
|
||
const listEl = (over: Record<string, unknown> = {}): BookElement => bookListElementSchema.parse({
|
||
id: 'l1', kind: 'list', frame,
|
||
items: [{ text: 'Warm all week', tone: 'pro' }, { text: 'Ferry was late', tone: 'con' }],
|
||
proLabel: 'Pros', conLabel: 'Cons',
|
||
...over,
|
||
}) as BookElement
|
||
|
||
function show(el: BookElement, live: JourneyStats | null = null) {
|
||
useStudioStore.getState().load({
|
||
version: 1, title: 'T', page,
|
||
spreads: [{ id: 'sp1', role: 'inner', background: null, elements: [el], parked: [], entryId: null }],
|
||
} as BookDocument)
|
||
useStudioStore.getState().select([el.id])
|
||
return render(
|
||
<StudioInspector
|
||
spreadIndex={0}
|
||
page={page}
|
||
stats={live}
|
||
source={{ entries: [], photos: [], photoEntries: {} }}
|
||
setPageNumbers={() => {}}
|
||
t={k => k}
|
||
locale="en"
|
||
/>,
|
||
)
|
||
}
|
||
|
||
/** The element as the store holds it. Every assertion below reads this. */
|
||
function saved(): Record<string, unknown> {
|
||
return useStudioStore.getState().doc!.spreads[0].elements[0] as unknown as Record<string, unknown>
|
||
}
|
||
|
||
/** One of a few. */
|
||
const pick = (name: string) => fireEvent.click(screen.getByRole('radio', { name }))
|
||
/** One of a set, which carries a tick. */
|
||
const tick = (name: string) => fireEvent.click(screen.getByRole('checkbox', { name }))
|
||
/** A switch, or any plain button: both answer to their accessible name. */
|
||
const press = (name: string) => fireEvent.click(screen.getByRole('button', { name }))
|
||
|
||
/** A section by its heading, since a label can repeat across sections. */
|
||
function section(container: HTMLElement, label: string): HTMLElement {
|
||
const found = [...container.querySelectorAll<HTMLElement>('.st-section')]
|
||
.find(s => s.querySelector('.st-section-label')?.textContent === label)
|
||
if (!found) throw new Error(`no section headed ${label}`)
|
||
return found
|
||
}
|
||
|
||
/** Some sections start folded, so a control inside one has to be uncovered. */
|
||
function open(container: HTMLElement, label: string) {
|
||
fireEvent.click(section(container, label).querySelector('.st-section-head')!)
|
||
}
|
||
|
||
/** The control side of one labelled line inside one section. */
|
||
function lineIn(container: HTMLElement, sectionLabel: string, lineLabel: string): HTMLElement {
|
||
const row = [...section(container, sectionLabel).querySelectorAll<HTMLElement>('.st-line')]
|
||
.find(l => l.querySelector('.st-line-label')?.textContent === lineLabel)
|
||
if (!row) throw new Error(`no line labelled ${lineLabel} under ${sectionLabel}`)
|
||
return row.querySelector<HTMLElement>('.st-line-body')!
|
||
}
|
||
|
||
beforeEach(() => {
|
||
useStudioStore.getState().load({ version: 1, title: 'T', page, spreads: [] } as unknown as BookDocument)
|
||
})
|
||
|
||
describe('the route map', () => {
|
||
it('takes the tiles and the credit from the source it is switched to', () => {
|
||
show(mapEl())
|
||
|
||
pick('journey.studio.mapSourceSatellite')
|
||
|
||
expect(saved().source).toBe('tiles')
|
||
expect(saved().tileUrl).toContain('tiles.maps.eox.at')
|
||
// The credit travels with the source, or the page prints the wrong one —
|
||
// and this one is CC BY, so printing it uncredited is a licence breach
|
||
// rather than a discourtesy.
|
||
expect(saved().attribution).toContain('EOX')
|
||
})
|
||
|
||
/*
|
||
* The planner's own street tiles and Mapbox are no longer offered: one is a
|
||
* street map that reads as a screenshot on paper and whose server asks people
|
||
* not to bulk-fetch, the other needs written permission before anything is
|
||
* printed. Removing an option must not remove a page, though.
|
||
*/
|
||
it('still offers the source a map already uses, even one no longer recommended', () => {
|
||
show(mapEl({
|
||
source: 'tiles',
|
||
tileUrl: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||
attribution: '© OpenStreetMap contributors',
|
||
}))
|
||
|
||
const chip = screen.getByRole('radio', { name: 'journey.studio.mapSourceTiles' })
|
||
expect(chip.getAttribute('aria-checked')).toBe('true')
|
||
})
|
||
|
||
it('does not offer it on a map that never used it', () => {
|
||
show(mapEl())
|
||
expect(screen.queryByRole('radio', { name: 'journey.studio.mapSourceTiles' })).toBeNull()
|
||
expect(screen.queryByRole('radio', { name: 'journey.studio.mapSourceStatic' })).toBeNull()
|
||
})
|
||
|
||
it('writes the drawn style', () => {
|
||
show(mapEl())
|
||
|
||
pick('journey.studio.mapStyle.paper')
|
||
|
||
expect(saved().style).toBe('paper')
|
||
})
|
||
|
||
it('fits the stops rather than the countries, and back again', () => {
|
||
show(mapEl())
|
||
expect(saved().fitToCountries).toBe(true)
|
||
|
||
pick('journey.studio.mapFitStops')
|
||
expect(saved().fitToCountries).toBe(false)
|
||
|
||
pick('journey.studio.mapFitCountry')
|
||
expect(saved().fitToCountries).toBe(true)
|
||
})
|
||
|
||
it('writes how much room is left around what is drawn', () => {
|
||
show(mapEl())
|
||
|
||
pick('journey.studio.mapPadWide')
|
||
expect(saved().fitPadding).toBe(0.5)
|
||
|
||
pick('journey.studio.mapPadTight')
|
||
expect(saved().fitPadding).toBe(0.04)
|
||
})
|
||
|
||
it('cuts the picture to the coastline when the shape is switched', () => {
|
||
show(mapEl())
|
||
|
||
pick('journey.studio.mapClipCountry')
|
||
|
||
expect(saved().clip).toBe('country')
|
||
})
|
||
|
||
/* A country-shaped hole with no country to cut against is a filled box. */
|
||
it('refuses the country shape on a map that knows no countries', () => {
|
||
show(mapEl({ countries: [] }))
|
||
|
||
const chip = screen.getByRole('radio', { name: 'journey.studio.mapClipCountry' })
|
||
expect(chip).toBeDisabled()
|
||
|
||
fireEvent.click(chip)
|
||
expect(saved().clip).toBe('rect')
|
||
})
|
||
|
||
it('writes a zoom from the folded group, and hands it back automatically', () => {
|
||
const { container } = show(mapEl({ source: 'tiles', tileUrl: 'https://tile.example/{z}/{x}/{y}.png' }))
|
||
open(container, 'journey.studio.mapZoom')
|
||
|
||
pick('11')
|
||
expect(saved().zoom).toBe(11)
|
||
|
||
// Automatic is null rather than a number, which is what lets the element
|
||
// choose one that fits the route.
|
||
pick('journey.studio.mapZoomAuto')
|
||
expect(saved().zoom).toBeNull()
|
||
})
|
||
|
||
it('draws each layer, or does not', () => {
|
||
show(mapEl())
|
||
|
||
press('journey.studio.showLand')
|
||
expect(saved().showLand).toBe(false)
|
||
|
||
press('journey.studio.showRoute')
|
||
expect(saved().showRoute).toBe(false)
|
||
|
||
press('journey.studio.showPins')
|
||
expect(saved().showPins).toBe(false)
|
||
|
||
press('journey.studio.showLabels')
|
||
expect(saved().showLabels).toBe(true)
|
||
})
|
||
})
|
||
|
||
describe('the figures', () => {
|
||
it('adds a figure to the set', () => {
|
||
show(statsEl())
|
||
|
||
tick('journey.studio.metric.countries')
|
||
|
||
expect(saved().metrics).toEqual(['distance', 'days', 'steps', 'photos', 'countries'])
|
||
})
|
||
|
||
it('takes one back out', () => {
|
||
show(statsEl())
|
||
|
||
tick('journey.studio.metric.days')
|
||
|
||
expect(saved().metrics).toEqual(['distance', 'steps', 'photos'])
|
||
})
|
||
|
||
/* An empty panel is a blank rectangle nobody could get back out of. */
|
||
it('keeps the last figure', () => {
|
||
show(statsEl({ metrics: ['days'] }))
|
||
|
||
tick('journey.studio.metric.days')
|
||
|
||
expect(saved().metrics).toEqual(['days'])
|
||
})
|
||
|
||
it('writes the layout and the units', () => {
|
||
show(statsEl())
|
||
|
||
pick('journey.studio.layoutRow')
|
||
expect(saved().layout).toBe('row')
|
||
|
||
pick('mi')
|
||
expect(saved().units).toBe('imperial')
|
||
})
|
||
|
||
it('writes the icons switch', () => {
|
||
show(statsEl())
|
||
|
||
press('journey.studio.showIcons')
|
||
|
||
expect(saved().showIcons).toBe(false)
|
||
})
|
||
})
|
||
|
||
describe('the countries', () => {
|
||
it('writes the layout and the alignment', () => {
|
||
show(countriesEl())
|
||
|
||
pick('journey.studio.layoutColumn')
|
||
expect(saved().layout).toBe('column')
|
||
|
||
pick('journey.studio.align.right')
|
||
expect(saved().align).toBe('right')
|
||
})
|
||
|
||
it('writes the three things it draws', () => {
|
||
show(countriesEl())
|
||
|
||
press('journey.studio.showOutline')
|
||
expect(saved().showOutline).toBe(false)
|
||
|
||
press('journey.studio.showFlag')
|
||
expect(saved().showFlag).toBe(true)
|
||
|
||
press('journey.studio.showName')
|
||
expect(saved().showName).toBe(false)
|
||
})
|
||
|
||
it('keeps one name per code when a line is edited', () => {
|
||
show(countriesEl())
|
||
|
||
fireEvent.change(screen.getByLabelText('journey.studio.countryNames'), {
|
||
target: { value: 'Island\nNoreg' },
|
||
})
|
||
|
||
expect(saved().names).toEqual(['Island', 'Noreg'])
|
||
})
|
||
|
||
/*
|
||
* The reason the textarea does not simply store its own lines: a removed line
|
||
* must not shift every name after it onto the wrong outline, and a line
|
||
* nobody has a country for must not be printed at all.
|
||
*/
|
||
it('ignores a line past the last country, and keeps a name whose line is gone', () => {
|
||
show(countriesEl())
|
||
const box = screen.getByLabelText('journey.studio.countryNames')
|
||
|
||
fireEvent.change(box, { target: { value: 'Island\nNoreg\nSverige' } })
|
||
expect(saved().names).toEqual(['Island', 'Noreg'])
|
||
|
||
fireEvent.change(box, { target: { value: 'Island' } })
|
||
expect(saved().names).toEqual(['Island', 'Noreg'])
|
||
})
|
||
})
|
||
|
||
describe('the mark', () => {
|
||
it('writes the words and the caption', () => {
|
||
const { container } = show(badgeEl())
|
||
|
||
fireEvent.change(
|
||
within(lineIn(container, 'journey.studio.marks', 'journey.studio.text')).getByRole('textbox'),
|
||
{ target: { value: 'REYKJAVIK' } },
|
||
)
|
||
expect(saved().text).toBe('REYKJAVIK')
|
||
|
||
fireEvent.change(
|
||
within(lineIn(container, 'journey.studio.marks', 'journey.studio.styleCaption')).getByRole('textbox'),
|
||
{ target: { value: 'Day 1' } },
|
||
)
|
||
expect(saved().sub).toBe('Day 1')
|
||
})
|
||
|
||
it('writes the style, in the panel language rather than in the raw value', () => {
|
||
show(badgeEl())
|
||
|
||
pick('journey.studio.markStyle.chip')
|
||
expect(saved().style).toBe('chip')
|
||
|
||
pick('journey.studio.markStyle.stacked')
|
||
expect(saved().style).toBe('stacked')
|
||
|
||
// These four printed `plain`, `chip` and the rest in all twenty-three
|
||
// languages before, straight out of the value.
|
||
expect(screen.getByRole('radio', { name: 'journey.studio.markStyle.outline' })).toBeTruthy()
|
||
expect(screen.queryByRole('radio', { name: 'outline' })).toBeNull()
|
||
})
|
||
|
||
it('writes the three combinations of picture and words', () => {
|
||
show(badgeEl())
|
||
|
||
pick('journey.studio.iconOnly')
|
||
expect(saved().showIcon).toBe(true)
|
||
expect(saved().showLabel).toBe(false)
|
||
|
||
pick('journey.studio.labelOnly')
|
||
expect(saved().showIcon).toBe(false)
|
||
expect(saved().showLabel).toBe(true)
|
||
|
||
pick('journey.studio.iconAndLabel')
|
||
expect(saved().showIcon).toBe(true)
|
||
expect(saved().showLabel).toBe(true)
|
||
})
|
||
|
||
/* A mark with neither its picture nor its words is a way to lose an element. */
|
||
it('offers no way to switch both off', () => {
|
||
const { container } = show(badgeEl())
|
||
const shows = within(section(container, 'journey.studio.icon')).getAllByRole('radio')
|
||
expect(shows).toHaveLength(3)
|
||
|
||
for (const chip of shows) {
|
||
fireEvent.click(chip)
|
||
expect(saved().showIcon || saved().showLabel).toBe(true)
|
||
}
|
||
})
|
||
|
||
it('writes the icon colour, and stops the icon choosing its own', () => {
|
||
const { container } = show(badgeEl())
|
||
|
||
fireEvent.click(
|
||
within(lineIn(container, 'journey.studio.icon', 'journey.studio.colour'))
|
||
.getByRole('button', { name: '#0f766e' }),
|
||
)
|
||
|
||
expect(saved().iconColor).toBe('#0f766e')
|
||
expect(saved().autoIconColor).toBe(false)
|
||
})
|
||
|
||
it('hands the icon colour back with the automatic switch', () => {
|
||
const { container } = show(badgeEl({ autoIconColor: false, iconColor: '#0f766e' }))
|
||
|
||
fireEvent.click(
|
||
within(section(container, 'journey.studio.icon'))
|
||
.getByRole('button', { name: 'journey.studio.autoColour' }),
|
||
)
|
||
|
||
expect(saved().autoIconColor).toBe(true)
|
||
})
|
||
})
|
||
|
||
describe('the pros and cons list', () => {
|
||
it('writes the layout', () => {
|
||
show(listEl())
|
||
|
||
pick('journey.studio.layoutColumn')
|
||
expect(saved().layout).toBe('stacked')
|
||
|
||
pick('journey.studio.layoutGrid')
|
||
expect(saved().layout).toBe('columns')
|
||
})
|
||
|
||
it('writes the marks switch', () => {
|
||
show(listEl())
|
||
|
||
press('journey.studio.showMarks')
|
||
|
||
expect(saved().showMarks).toBe(false)
|
||
})
|
||
|
||
it('writes both headings', () => {
|
||
show(listEl())
|
||
|
||
fireEvent.change(screen.getByLabelText('journey.editor.pros'), { target: { value: 'Worth it' } })
|
||
expect(saved().proLabel).toBe('Worth it')
|
||
|
||
fireEvent.change(screen.getByLabelText('journey.editor.cons'), { target: { value: 'Less so' } })
|
||
expect(saved().conLabel).toBe('Less so')
|
||
})
|
||
})
|
||
|
||
describe('the tail all five share', () => {
|
||
it('writes the family, and moves the weight to one that family really has', () => {
|
||
const { container } = show(statsEl({ font: 'sans', weight: 700 }))
|
||
open(container, 'journey.studio.typography')
|
||
|
||
// Bebas ships one weight; a bold it does not have prints as a smeared
|
||
// regular, so the request moves rather than being passed through.
|
||
press('Bebas Neue')
|
||
|
||
expect(saved().font).toBe('bebas')
|
||
expect(saved().weight).toBe(400)
|
||
})
|
||
|
||
it('keeps a weight the new family does have', () => {
|
||
const { container } = show(statsEl({ font: 'sans', weight: 500 }))
|
||
open(container, 'journey.studio.typography')
|
||
|
||
press('Lora')
|
||
|
||
expect(saved().font).toBe('serif')
|
||
expect(saved().weight).toBe(500)
|
||
})
|
||
|
||
it('writes the weight', () => {
|
||
const { container } = show(countriesEl())
|
||
open(container, 'journey.studio.typography')
|
||
|
||
pick('500')
|
||
|
||
expect(saved().weight).toBe(500)
|
||
})
|
||
|
||
it('writes the text scale', () => {
|
||
const { container } = show(listEl())
|
||
open(container, 'journey.studio.typography')
|
||
|
||
pick('1.2×')
|
||
|
||
expect(saved().textScale).toBe(1.2)
|
||
})
|
||
|
||
it('writes the accent and the ink, which are two different rows', () => {
|
||
const { container } = show(statsEl())
|
||
|
||
fireEvent.click(
|
||
within(lineIn(container, 'journey.studio.colour', 'journey.studio.accent'))
|
||
.getByRole('button', { name: '#c2410c' }),
|
||
)
|
||
expect(saved().accent).toBe('#c2410c')
|
||
expect(saved().color).toBe('#1a1a1a')
|
||
|
||
fireEvent.click(
|
||
within(lineIn(container, 'journey.studio.colour', 'journey.studio.text'))
|
||
.getByRole('button', { name: '#1e3a8a' }),
|
||
)
|
||
expect(saved().color).toBe('#1e3a8a')
|
||
expect(saved().accent).toBe('#c2410c')
|
||
})
|
||
|
||
/* A chip's words answer to its fill, until somebody chooses otherwise. */
|
||
it('takes a mark off automatic when its ink is picked, and the switch puts it back', () => {
|
||
const { container } = show(badgeEl())
|
||
|
||
fireEvent.click(
|
||
within(lineIn(container, 'journey.studio.colour', 'journey.studio.text'))
|
||
.getByRole('button', { name: '#ffffff' }),
|
||
)
|
||
expect(saved().color).toBe('#ffffff')
|
||
expect(saved().autoColor).toBe(false)
|
||
|
||
fireEvent.click(
|
||
within(section(container, 'journey.studio.colour'))
|
||
.getByRole('button', { name: 'journey.studio.autoColour' }),
|
||
)
|
||
expect(saved().autoColor).toBe(true)
|
||
})
|
||
})
|
||
|
||
describe('an element the journey has moved past', () => {
|
||
it('says so, and offers to bring it up to date', () => {
|
||
show(statsEl(), stats)
|
||
|
||
expect(screen.getByText('journey.studio.staleHint')).toBeTruthy()
|
||
expect(screen.getByRole('button', { name: 'journey.studio.refresh' })).toBeTruthy()
|
||
})
|
||
|
||
it('writes the journey figures as they stand now, and stops asking', () => {
|
||
show(statsEl(), stats)
|
||
|
||
press('journey.studio.refresh')
|
||
|
||
expect(saved().values).toMatchObject({ distance: 1234, days: 5, steps: 7, photos: 12 })
|
||
expect(saved().stale).toBe(false)
|
||
expect(screen.queryByText('journey.studio.staleHint')).toBeNull()
|
||
})
|
||
|
||
/*
|
||
* Compared rather than timestamped: a page showing distance and days does not
|
||
* go stale because somebody fixed a typo in a caption.
|
||
*/
|
||
it('says nothing while the figures it shows still match', () => {
|
||
show(statsEl({ values: { distance: 1234, days: 5, steps: 7, photos: 12 } }), stats)
|
||
|
||
expect(screen.queryByText('journey.studio.staleHint')).toBeNull()
|
||
})
|
||
})
|