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
5 changes: 5 additions & 0 deletions changelog.d/415.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
section: fixes
---

- **The renderer check “No status text at the endpoints” no longer fails an item for its own name** (#415). An endpoint `POST /Library/Movies/Added`, or a member named `Removed`, failed `quiet-endpoints` at Before and After because its label held a status word. The check now reads status from the parts that state it (`data-change-status`, and the kit's badges, status lines and tabs), where any status word still fails, and elsewhere in an item's text fails only a status word that the item's own ID, label or data doesn't hold.
35 changes: 35 additions & 0 deletions packages/renderers/harness/browser/status-parts.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {expect, test} from '@playwright/test'
import {openStage, type EntitySample} from '@githubnext/projections-renderer-testing/playwright'
import {harnessInspector} from '@githubnext/projections-renderer-harness/playwright'

/**
* The probe records the text of an entity's status parts (`data-change-status`, the kit's badges, status lines and
* tabs) apart from its name, so `quiet-endpoints` reads a status word in a badge as status and one in a name as a name.
*/
test('the probe reads status parts apart from an entity’s name', async ({page}, testInfo) => {
test.skip(testInfo.project.name !== 'chromium-desktop', 'The probe reads the DOM, the same in every engine.')
const stage = await openStage(page, harnessInspector(), {scenario: 'graph/npm-react-update', progress: 1, comparisonMode: 'diff'})
await stage.frame.locator('.pk').evaluate(root => {
const probe = document.createElement('div')
probe.innerHTML = `
<div data-entity-id="probe:named" class="badge">POST /Library/Movies/Added</div>
<div data-entity-id="probe:badged"><span>Removed</span><span class="badge added"><span>Added</span></span></div>
<div data-entity-id="probe:worded"><span data-change-status="modified">Modified</span></div>
<div data-entity-id="probe:faded"><span class="pk-status-text" style="opacity: 0">Renamed</span></div>
<div data-entity-id="probe:parent"><span data-entity-id="probe:child" class="badge">Removed</span></div>
<div data-entity-id="probe:spoken"><span style="position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%)"><span class="badge">Added</span></span></div>`
root.append(probe)
})
const samples = new Map((await stage.measure<EntitySample[]>('samples')).map(sample => [sample.id, sample]))
const status = (id: string) => samples.get(id)?.status
// The entity element itself is never a status part, whatever its class.
expect(status('probe:named')).toEqual([])
expect(samples.get('probe:badged')?.text).toBe('Removed Added')
expect(status('probe:badged')).toEqual(['Added'])
expect(status('probe:worded')).toEqual(['Modified'])
// A faded status part, or one only assistive technology hears, shows nothing.
expect(status('probe:faded')).toEqual([])
expect(status('probe:spoken')).toEqual([])
// A nested entity is never its parent's status part, whatever its class.
expect(status('probe:parent')).toEqual([])
})
3 changes: 2 additions & 1 deletion packages/renderers/testing/src/checks/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ export const checkDescriptions: Record<CheckId, string> = {
'Change status appears in reserved space: at every sampled progress, and in the diff, each entity has the same box with highlighting on and off.',
'status-text':
'While a change is emphasized, its entity states its status as text (Added, Removed, Modified, Renamed or Moved), visibly or for assistive technology, never by color alone.',
'quiet-endpoints': "At both endpoints, with the host's default highlighting, no entity shows status text.",
'quiet-endpoints':
"At both endpoints, with the host's default highlighting, no entity shows status text: no status word (Added, Removed, Modified, Renamed or Moved) in a part that states status (data-change-status, or the kit's badges, status lines and tabs), nor elsewhere in its text unless its own ID, label or data holds the word, as a route /Movies/Added does.",
'content-top':
"The renderer draws no header of its own (the host shows the title, schema and counts): its first entity, canvas or marked content region (data-projections-content) starts within the stage padding of the frame top (the host's stage-inset, else 12 px, or its stage-inset-top where that is more), at full and phone width. A zoomable canvas (a scroll container marked data-zoom) counts as a whole, since it opens fitted (or at the text floor) and centres what it draws.",
'stage-insets':
Expand Down
46 changes: 45 additions & 1 deletion packages/renderers/testing/src/checks/comparison/endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// The checks of a comparison's endpoints: neutral at progress 0 and 1, with no status text.
import type {EntitySample, StageSubject} from '../../types.js'
import {Skip, progressModes, limit, samples, label, type Checks} from '../support.js'
import {acrossRevisions, difference, looks} from './support.js'
import {statusWords} from './status.js'
Expand Down Expand Up @@ -62,13 +63,56 @@ export const endpointChecks: Pick<Checks, 'neutral-endpoints' | 'quiet-endpoints
throw new Skip('The renderer presents comparisons only in diff mode, which has no endpoints.')
}
const failures: string[] = []
const named = ownText(subject)
for (const progress of [0, 1]) {
await driver.load(subject, {progress})
for (const sample of (await samples(driver)).values()) {
const word = statusWords.exec(sample.text)?.[0]
const word = shownStatus(sample, named)
if (word) failures.push(`At ${label(progress)}, "${sample.key}" shows "${word}"; endpoints carry no status.`)
}
}
return failures.slice(0, limit)
},
}

/**
* The status word an entity shows, if any: one in a part that states status (`EntitySample.status`), or else one in
* its text that its own ID, label and data don't hold, so a route `/Movies/Added` or a member `Removed` is its name.
*/
function shownStatus(sample: EntitySample, named: (id: string) => readonly string[]): string | undefined {
for (const text of sample.status ?? []) {
const word = statusWords.exec(text)?.[0]
if (word) return word
}
for (const [word] of sample.text.matchAll(new RegExp(statusWords.source, 'gu'))) {
const whole = new RegExp(`\\b${word}\\b`, 'u')
if (!named(sample.id).some(text => whole.test(text))) return word
}
return undefined
}

/**
* Every string the items (entities and relationships) with an ID hold in either revision, with the ID itself: items
* indexed once, and each one's strings collected the first time a status word asks for them.
*/
function ownText(subject: Extract<StageSubject, {mode: 'comparison'}>): (id: string) => readonly string[] {
const items = new Map<string, unknown[]>()
for (const extraction of [subject.before, subject.after]) {
for (const item of [...extraction.entities, ...extraction.relationships]) items.set(item.id, [...(items.get(item.id) ?? []), item])
}
const collected = new Map<string, string[]>()
return id => {
let texts = collected.get(id)
if (texts) return texts
texts = [id]
// Data may nest JSON to any depth, so it is walked without recursion.
const pending = [...(items.get(id) ?? [])]
while (pending.length) {
const value = pending.pop()
if (typeof value === 'string') texts.push(value)
else if (typeof value === 'object' && value !== null) pending.push(...(Object.values(value) as unknown[]))
}
collected.set(id, texts)
return texts
}
}
28 changes: 28 additions & 0 deletions packages/renderers/testing/src/measure/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,40 @@ export function entitySamples(root: Element = document.body): EntitySample[] {
box: [round(box.left), round(box.top), round(box.width), round(box.height)],
opacity: Math.round(effectiveOpacity(element) * 100) / 100,
...paintOf(element),
status: statusTexts(element),
parts: [...new Set([...element.querySelectorAll('[data-entity-id]')].map(part => part.getAttribute('data-entity-id')!))],
})
}
return samples
}

/** Parts that state a change's status: the kit's status words (`data-change-status`), badges, status lines and tabs. */
const statusMarks = '[data-change-status], .badge, .pk-status-text, .pk-status-tab, .pk-svg-status, .pk-change-status'

/**
* The visible text of each status part of an entity element, outermost parts only and not its nested entities'. The
* element itself is never one, whatever its class: its text is its name; nor is a nested entity.
*/
function statusTexts(element: Element): string[] {
return [...element.querySelectorAll(statusMarks)]
.filter(
part =>
!part.hasAttribute('data-entity-id') &&
part.parentElement?.closest(`${statusMarks}, [data-entity-id]`) === element &&
!hiddenWithin(part, element),
)
.map(part => paintOf(part).text)
.filter(text => text !== '')
}

/** Whether a part, or anything around it up to `element`, is shown only to assistive technology (`sr-only`). */
function hiddenWithin(part: Element, element: Element): boolean {
for (let node: Element | null = part; node && node !== element; node = node.parentElement) {
if (visuallyHidden(node, getComputedStyle(node))) return true
}
return visuallyHidden(element, getComputedStyle(element))
}

/** IDs of visible entities: nested ones (parts) first, then units. */
export function visibleEntities(root: Element = document.body): string[] {
const all = [...root.querySelectorAll('[data-entity-id]')].filter(visible)
Expand Down
6 changes: 6 additions & 0 deletions packages/renderers/testing/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ export interface EntitySample {
opacity: number
paint: string
text: string
/**
* The visible text of each part that states a change's status (`data-change-status`, or the kit's badges, status
* lines and tabs); also in `text`. `quiet-endpoints` reads a status word here as status, and one elsewhere in
* `text` as status only when the item's own ID, label and data don't hold it.
*/
status?: string[]
/** IDs of entity elements nested inside it (a unit's parts), whose emphasis it may show. */
parts: string[]
/**
Expand Down
50 changes: 50 additions & 0 deletions packages/renderers/testing/test/helpers.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,56 @@ test('stable-layout compares two diffs once each frame has the height its render
assert.equal(result.status, 'pass', result.details.join('\n'))
})

test('quiet-endpoints reads status from status parts, not from an item’s own name', async () => {
const route = 'endpoint:POST /Library/Movies/Added'
const named = {
mode: 'comparison',
before: {...extraction([]), entities: [{id: route, kind: 'endpoint', label: 'POST /Library/Movies/Added'}]},
after: {
...extraction([]),
entities: [
{id: route, kind: 'endpoint', label: 'POST /Library/Movies/Added'},
{id: 'member:ChangeKind.Removed', kind: 'member', label: 'Removed'},
{id: 'job:nightly', kind: 'job', label: 'nightly', data: {steps: [{run: {when: {on: {kind: {name: 'Modified'}}}}}]}},
],
},
comparison: {
protocolVersion: 0,
changes: [
{id: 'member:ChangeKind.Removed', collection: 'entities', before: [], after: ['member:ChangeKind.Removed'], status: 'added'},
],
steps: [{changes: ['member:ChangeKind.Removed']}],
},
}
const run = async drawn => {
const driver = fakeDriver(['side-by-side']).driver
driver.measure = async call =>
call === 'samples'
? drawn.map(sample => ({box: [0, 0, 10, 10], opacity: 1, paint: 'plain', parts: [], categories: {}, ...sample}))
: []
return (await runChecks(driver, named, {checks: ['quiet-endpoints']}))[0]
}
// Labels that hold status words are names, at both endpoints.
const names = await run([
{key: route, id: route, text: 'POST /Library/Movies/Added', status: []},
{key: 'member:ChangeKind.Removed', id: 'member:ChangeKind.Removed', text: 'Removed', status: []},
// However deep its data holds the word.
{key: 'job:nightly', id: 'job:nightly', text: 'nightly Modified', status: []},
])
assert.equal(names.status, 'pass', names.details.join('\n'))
// A status badge fails, even beside a name holding the same word.
const badged = await run([{key: route, id: route, text: 'POST /Library/Movies/Added Added', status: ['Added']}])
assert.equal(badged.status, 'fail')
assert.match(
badged.details[0],
/At Before \(progress 0\), "endpoint:POST \/Library\/Movies\/Added" shows "Added"; endpoints carry no status\./u,
)
// Status text the item's name doesn't hold still fails, marked or not.
const loose = await run([{key: 'member:ChangeKind.Removed', id: 'member:ChangeKind.Removed', text: 'Removed Added', status: []}])
assert.equal(loose.status, 'fail')
assert.match(loose.details[0], /shows "Added"/u)
})

test('checks run per declared comparison mode', async () => {
const status = results => Object.fromEntries(results.map(result => [result.id, result.status]))
const diffOnly = fakeDriver(['diff'])
Expand Down
Loading