fix: the robots element follows the Go grammar and keeps a value it cannot parse (WR-24)

parseRobots accepted 2027-02-30 (Date.parse rolls it over) and refused
max-snippet:+5, both unlike classes/robots_value.go. A value it could not
parse showed every group as Inherit and the first click serialised the
empty model, dropping the stored directives. Dates are now checked as
calendar dates, a sign is accepted, and an unparsed value is kept with a
note, the controls off and an explicit Reset.
This commit is contained in:
2026-10-27 15:43:32 +01:00
parent 4ca26e9a89
commit 923d0f9c3a
7 changed files with 121 additions and 10 deletions

View File

@@ -73,11 +73,37 @@ describe('E2 value grammar', () => {
})
it('malformed values are refused like the Go grammar', () => {
for (const bad of [',', 'index,', 'index,noindex', 'follow,nofollow', 'noarchive,noarchive', 'index:1', 'noarchive:yes', 'max-snippet', 'max-snippet:abc', 'max-snippet:-2', 'max-snippet:1.5', 'max-image-preview:huge', 'unavailable_after:2027-13-01', 'unavailable_after:27-01-01', 'none', 'noodp']) {
for (const bad of [',', 'index,', 'index,noindex', 'follow,nofollow', 'noarchive,noarchive', 'index:1', 'noarchive:yes', 'max-snippet', 'max-snippet:abc', 'max-snippet:-2', 'max-snippet:1.5', 'max-image-preview:huge', 'unavailable_after:2027-13-01', 'unavailable_after:27-01-01', 'unavailable_after:2027-02-30', 'unavailable_after:2027-02-29', 'unavailable_after:2027-04-31', 'unavailable_after:2027-01-00', 'max-snippet:+-1', 'none', 'noodp']) {
expect(parseRobots(bad), bad).toBeNull()
}
})
it('accepts what the Go grammar accepts (WR-24): a leap day and a signed number', () => {
expect(serializeRobots(parseRobots('unavailable_after:2028-02-29') as Robots)).toBe('unavailable_after:2028-02-29')
expect(serializeRobots(parseRobots('max-snippet:+5') as Robots)).toBe('max-snippet:5')
expect(serializeRobots(parseRobots('max-video-preview:-1') as Robots)).toBe('max-video-preview:-1')
})
it('a stored value it cannot parse is kept, shown and replaced only by Reset (WR-24)', () => {
const node = document.createElement('golem15-seo-robots') as HTMLElement & { value: string }
node.setAttribute('ui-locale', 'en')
document.body.append(node)
node.value = 'noindex,unavailable_after:2027-02-30'
const seen: string[] = []
node.addEventListener('summer-change', (ev) => seen.push((ev as CustomEvent).detail.value))
expect(node.querySelector('.seo-robots__unparsed')?.textContent).toContain('noindex,unavailable_after:2027-02-30')
const segment = node.querySelector('[data-focus-key="follow-2"]') as HTMLButtonElement
expect(segment.disabled).toBe(true)
segment.click()
expect(seen).toEqual([])
expect(node.value).toBe('noindex,unavailable_after:2027-02-30')
;(node.querySelector('.seo-robots__reset') as HTMLButtonElement).click()
expect(seen).toEqual([''])
expect(node.querySelector('.seo-robots__unparsed')).toBeNull()
;(node.querySelector('[data-focus-key="index-2"]') as HTMLButtonElement).click()
expect(seen).toEqual(['', 'noindex'])
})
it('the element emits the fixed-order value and "" when both groups inherit', () => {
const node = document.createElement('golem15-seo-robots') as HTMLElement & { value: string }
document.body.append(node)