Phone hit kit: read the className expression, not its source text
Some checks failed
Build pull request / Build pull request (pull_request) Has been cancelled
Some checks failed
Build pull request / Build pull request (pull_request) Has been cancelled
A PhoneHit name inside a string, built by concatenation, behind ?:/&&/||/??, or followed by a props spread that can override className no longer satisfies the pin. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
54ac1ba480
commit
d13cbc9b2e
2 changed files with 88 additions and 2 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { drawnPx, expectSizeTie, iconButtons } from './phoneHitTestKit';
|
||||
import { drawnPx, expectSizeTie, iconButtons, phoneHitOf } from './phoneHitTestKit';
|
||||
|
||||
describe('phone hit test kit', () => {
|
||||
it('reads <IconButton only, not a longer component name', () => {
|
||||
|
|
@ -38,4 +38,49 @@ describe('phone hit test kit', () => {
|
|||
it('fails a file with no IconButton, which would otherwise pass vacuously', () => {
|
||||
expect(() => expectSizeTie('styles/PhoneHit.css.ts')).toThrow(/no IconButton/);
|
||||
});
|
||||
|
||||
describe('phoneHitOf reads the imported class, applied unconditionally', () => {
|
||||
const tag = (expr: string) => `<IconButton size="300" className={${expr}}>`;
|
||||
|
||||
it('accepts the bare identifier and merges that always include it', () => {
|
||||
expect(phoneHitOf(tag('PhoneHitSpread26'))).toBe('PhoneHitSpread26');
|
||||
expect(phoneHitOf(tag('classNames(PhoneHitRoom36, css.other)'))).toBe('PhoneHitRoom36');
|
||||
expect(phoneHitOf(tag('`${PhoneHit} ${css.other}`'))).toBe('PhoneHit');
|
||||
expect(phoneHitOf(tag("[PhoneHit, 'a b'].join(' ')"))).toBe('PhoneHit');
|
||||
expect(phoneHitOf(tag('classNames(css.a, { [css.b]: on }, PhoneHit)'))).toBe('PhoneHit');
|
||||
});
|
||||
|
||||
it('rejects the name as a string literal', () => {
|
||||
expect(phoneHitOf(tag("'PhoneHitSpread26'"))).toBeNull();
|
||||
expect(phoneHitOf(tag('`PhoneHitSpread26`'))).toBeNull();
|
||||
});
|
||||
|
||||
it('rejects a name built by concatenation', () => {
|
||||
expect(phoneHitOf(tag('"PhoneHitSpread26" + "x"'))).toBeNull();
|
||||
expect(phoneHitOf(tag("'PhoneHit' + 'Spread26'"))).toBeNull();
|
||||
});
|
||||
|
||||
it('rejects a conditionally applied name', () => {
|
||||
expect(phoneHitOf(tag('cond ? PhoneHitSpread26 : undefined'))).toBeNull();
|
||||
expect(phoneHitOf(tag('cond && PhoneHitSpread26'))).toBeNull();
|
||||
expect(phoneHitOf(tag('cond || PhoneHitSpread26'))).toBeNull();
|
||||
expect(phoneHitOf(tag('maybe ?? PhoneHitSpread26'))).toBeNull();
|
||||
expect(phoneHitOf(tag("classNames(cond ? PhoneHit : '', css.a)"))).toBeNull();
|
||||
});
|
||||
|
||||
it('rejects a member of another object and a tag without className', () => {
|
||||
expect(phoneHitOf(tag('other.PhoneHit'))).toBeNull();
|
||||
expect(phoneHitOf('<IconButton size="300">')).toBeNull();
|
||||
});
|
||||
|
||||
it('rejects a spread after className, which can override it, and accepts one before', () => {
|
||||
expect(phoneHitOf('<IconButton className={PhoneHit} {...props}>')).toBeNull();
|
||||
expect(phoneHitOf('<IconButton className={PhoneHit} size="300" {...props} />')).toBeNull();
|
||||
expect(phoneHitOf('<IconButton {...props} className={PhoneHit}>')).toBe('PhoneHit');
|
||||
});
|
||||
|
||||
it('reads a className past braces inside strings', () => {
|
||||
expect(phoneHitOf(tag("classNames('{', PhoneHit)"))).toBe('PhoneHit');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue