ReviewOS

also looking at this

stacks/commshq

refactor(ui): adopt shared workspace badges

#17
Merged glennmichael123 wants to merge refactor/commshq-shared-controls into main
5 files +118 -9
tests/Unit/shared-badges.test.tsadded+95-0
Changes to tests/Unit/shared-badges.test.ts
@@ -0,0 +1,95 @@
1import { describe, expect, test } from 'bun:test'
2import { readFileSync } from 'node:fs'
3import { resolve } from 'node:path'
4import theme from '../../config/crosswind'
5import { processComponents } from '../../node_modules/@stacksjs/stx/dist/component-renderer.js'
6import { loadCssEngine } from '../../node_modules/@stacksjs/stx/dist/dev-server/ts-css.js'
7import { mergeCssConfig } from '../../node_modules/@stacksjs/stx/dist/ts-css-config.js'
8
9const root = resolve(import.meta.dir, '../..')
10
11describe('shared workspace badges', () => {
12 for (const [component, samples] of [
13 ['CommandCenter', [{ text: '+18.4%', item: { change: '+18.4%' } }]],
14 ['WorkspaceSurface', [{ text: 'Complete', record: { status: 'Complete' } }, { text: 'On', check: { state: 'On' } }]],
15 ] as const) {
16 test(`${component} uses quiet shared badges and preserves its status text`, async () => {
17 const file = resolve(root, `resources/components/CommsHQ/${component}.stx`)
18 const badges = readFileSync(file, 'utf8').match(/<Badge\b[^]*?<\/Badge>/g) || []
19 expect(badges).toHaveLength(samples.length)
20 for (const [index, badge] of badges.entries()) {
21 const html = await processComponents(badge, {
22 ...samples[index],
23 __importedComponents: new Map([['badge', resolve(root, 'node_modules/@stacksjs/components/src/ui/badge/Badge.stx')]]),
24 }, file, { componentsDir: resolve(root, 'resources/components') }, new Set())
25 expect(html).toContain(samples[index].text)
26 expect(html).not.toContain('<Badge')
27 expect(html).not.toContain('[Component Error')
28 expect(html).not.toContain('aria-live=')
29 expect(html).not.toContain('x-cloak')
30 }
31 })
32 }
33
34 test('audience consent renders through Badge without becoming a live announcement', async () => {
35 const file = resolve(root, 'resources/components/CommsHQ/AudienceWorkspace.stx')
36 const source = readFileSync(file, 'utf8')
37 const badges = source.match(/<Badge\b[^]*?<\/Badge>/g) || []
38 expect(badges).toHaveLength(2)
39 for (const badge of badges) {
40 const dependencies = new Set<string>()
41 const html = await processComponents(badge, {
42 contact: { state: 'SMS consented' },
43 __importedComponents: new Map([['badge', resolve(root, 'node_modules/@stacksjs/components/src/ui/badge/Badge.stx')]]),
44 }, file, { componentsDir: resolve(root, 'resources/components') }, dependencies)
45 expect([...dependencies]).toContain(resolve(root, 'node_modules/@stacksjs/components/src/ui/badge/Badge.stx'))
46 expect(html).toContain('SMS consented')
47 expect(html).toContain('audience-consent-badge')
48 expect(html).not.toContain('<Badge')
49 expect(html).not.toContain('[Component Error')
50 expect(html).not.toContain('role="status"')
51 expect(html).not.toContain('aria-live=')
52 expect(html).not.toContain('<button')
53 }
54 expect(source).toMatch(/<dd>\s*<Badge[^]*?<\/Badge>\s*<\/dd>/)
55 })
56
57 test('audience badge utilities preserve the existing light and dark consent palette', async () => {
58 const engine = await loadCssEngine()
59 if (!engine) throw new Error('The installed STX CSS engine is required')
60 const generator = new engine.CSSGenerator(mergeCssConfig(engine.defaultConfig || engine.config, theme).config)
61 generator.generate('audience-consent-badge')
62 const css = generator.toCSS(false, false)
63 expect(css).toContain('.audience-consent-badge')
64 expect(css).toContain('font-weight: 700 !important')
65 expect(css).toContain('#466833 !important')
66 expect(css).toContain('#edf5e8 !important')
67 expect(css).toContain('#acd294 !important')
68 expect(css).toContain('0.625rem !important')
69 expect(css).toContain('0.25rem !important')
70 expect(css).toContain('.dark')
71 // Desktop table cells previously used inline pills, unlike mobile cards.
72 expect(css).toContain('display: inline !important')
73 expect(css).toContain('640px')
74 })
75
76 test('workspace badge utilities retain the compact typography and contextual colors', async () => {
77 const engine = await loadCssEngine()
78 if (!engine) throw new Error('The installed STX CSS engine is required')
79 for (const [shortcut, declarations] of [
80 ['workspace-change-badge', ['#42652e', '#a8d28e', '#eef5e8', '11px', '0.625rem']],
81 ['workspace-record-badge', ['#466833', '#acd294', '#eef5e8', '10px']],
82 ['workspace-check-badge', ['#bfe2ab', '10px']],
83 ] as const) {
84 const generator = new engine.CSSGenerator(mergeCssConfig(engine.defaultConfig || engine.config, theme).config)
85 generator.generate(shortcut)
86 const css = generator.toCSS(false, false)
87 expect(css).toContain(`.${shortcut}`)
88 for (const declaration of declarations) expect(css).toContain(`${declaration} !important`)
89 expect(css).toContain('font-weight: 700 !important')
90 expect(css).toContain('line-height: inherit !important')
91 expect(css).toContain('display: flex !important')
92 expect(css).toContain('0.25rem !important')
93 }
94 })
95})