mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-02 20:59:56 -05:00
ui: two more labels were painting text with an inline colour, and shorthand hex
Both from review, and both correct. * The tag edit preview and the Flasher's chip badges still wrote the calculated text colour to `color`. That is the same defect the last commit fixed on the tag chip itself: an inline declaration no stylesheet rule can outrank, so night keeps the colour calculated for the fill it has just discarded and a bright fill leaves black text on near-black. The preview is the worse of the two -- it is the preview of the colour being chosen, so it was misrepresenting what the tag would look like at the moment the user picks it. It now shows the tag shape as well. Fixing the first site did not fix these, and the stylesheet comment explaining the night and amber override already named the Flasher. So there is a source guard now: no element carrying `wrolpi-label` may set `color` in its style object. Verified against a planted violation, which it reports by file. * `hexToRGBArray` rejected the shorthand `#fff`, which left the luminance at zero -- a near-white tag was read as black and handed light text. Reachable because tag colours are not only picked in the colour picker: they are stored in a config, and a config is a file a user edits by hand. Three tests were red first, including one asserting the shorthand and the six-digit form of the same colour agree.
This commit is contained in:
parent
d117d92a85
commit
672e7973f6
5 changed files with 115 additions and 7 deletions
|
|
@ -531,3 +531,32 @@ describe('contrastingColor', () => {
|
|||
expect(contrastRatio('#ffffff', '#ffffff')).toBeCloseTo(1, 5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('contrastingColor with shorthand hex', () => {
|
||||
/*
|
||||
* Tag colours reach the UI from the database, and a tags config is a file a user can edit
|
||||
* by hand -- configs are the source of truth in WROLPi -- so a perfectly valid `#fff` can
|
||||
* arrive here. `hexToRGBArray` used to reject anything but six digits, which left the
|
||||
* luminance at zero: a near-white tag was treated as black and given light text.
|
||||
*/
|
||||
|
||||
it('reads a three-digit hex as the colour it is', () => {
|
||||
expect(contrastRatio('#000000', '#fff')).toBeCloseTo(21, 1);
|
||||
expect(contrastRatio('#000000', '#ffffff')).toBeCloseTo(contrastRatio('#000000', '#fff'), 5);
|
||||
});
|
||||
|
||||
it('picks dark text for a near-white shorthand fill', () => {
|
||||
expect(contrastingColor('#fff')).toBe(TAG_TEXT_DARK);
|
||||
});
|
||||
|
||||
it('picks light text for a near-black shorthand fill', () => {
|
||||
expect(contrastingColor('#000')).toBe(TAG_TEXT_LIGHT);
|
||||
});
|
||||
|
||||
it('agrees with the six-digit form of the same colour', () => {
|
||||
for (const [short, long] of [['#fff', '#ffffff'], ['#000', '#000000'],
|
||||
['#f00', '#ff0000'], ['#1b2', '#11bb22']]) {
|
||||
expect(contrastingColor(short)).toBe(contrastingColor(long));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue