Skip to content

Commit 4082ba7

Browse files
authored
test(build): the tree test reads the picker's ranking instead of a literal block list (#10615)
* test(build): the tree test reads the picker's ranking instead of a literal block list A new example block moved the picker's login-form answer and broke main. Each pinned phrase now pins only the components it must get blocks from; the block order comes from the picker's own ranking over the same signals. * test(build): a pinned component counts only its own blocks
1 parent b993255 commit 4082ba7

1 file changed

Lines changed: 40 additions & 60 deletions

File tree

‎packages/cli/api/build/tree.test.mjs‎

Lines changed: 40 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
* @file build's tree end to end, offline: the network and subprocesses throw,
55
* and build still answers. The block picker changes only the kit's blocks:
66
* the start, its alternatives, and every other field stay build's own, the
7-
* block count is build's own, and the blocks it names are pinned per phrase.
7+
* block count is build's own, the blocks follow the picker's own ranking, and
8+
* each phrase pins the components it must get blocks from.
89
*/
910

1011
import * as fs from 'node:fs';
@@ -100,73 +101,29 @@ const {build} = require('./build.mjs');
100101
const {buildKit} = require('./kit/kit.mjs');
101102
/** @type {typeof import('./_adapter.mjs')} */
102103
const {loadBlockPicker, withListingCache} = require('./_adapter.mjs');
104+
/** @type {typeof import('./kit/signals.mjs')} */
105+
const {kitSignals} = require('./kit/signals.mjs');
106+
/** @type {typeof import('./blocks/blocks.mjs')} */
107+
const {pickBlocks} = require('./blocks/blocks.mjs');
103108

104109
const REPO = path.resolve(
105110
path.dirname(fileURLToPath(import.meta.url)),
106111
'../../../..',
107112
);
108113

109114
/**
110-
* Hand-written phrases and the blocks the picker names for each. The rest of
111-
* the answer carries search results, which change whenever the docs do, so it
112-
* is compared with build's own kit rather than pinned.
115+
* Hand-written phrases and the components each must get blocks from. Which
116+
* blocks the picker names moves whenever the block catalog grows, so the test
117+
* reads the picker's own ranking for the order and pins only the components.
113118
* @type {[string, string[]][]}
114119
*/
115120
const PINNED = [
116-
[
117-
'analytics dashboard with a KPI row and a sortable table',
118-
[
119-
'TableSortableTable',
120-
'TableGridDividersTable',
121-
'TableGroupedRowsTable',
122-
'TableShowcase',
123-
'TableLeadingMarkSelection',
124-
],
125-
],
126-
[
127-
'settings page with notification toggles and a save bar',
128-
[
129-
'SwitchShowcase',
130-
'SwitchSettingsPanel',
131-
'ToggleButtonShowcase',
132-
'ToggleButtonStates',
133-
'SwitchWithDescription',
134-
],
135-
],
136-
[
137-
'empty state for a question bank with an import button',
138-
[
139-
'EmptyStateContainer',
140-
'EmptyStateShowcase',
141-
'EmptyStateCompact',
142-
'EmptyStateActions',
143-
'CommandPaletteEmptyShowcase',
144-
],
145-
],
146-
[
147-
'login form with single sign-on buttons',
148-
[
149-
'ButtonWithIcon',
150-
'CardWithInnerLayout',
151-
'ButtonVariants',
152-
'FormLayoutShowcase',
153-
'FormLayoutMixedControls',
154-
],
155-
],
156-
[
157-
'calendar for booking appointments',
158-
[
159-
'CalendarSingle',
160-
'CalendarShowcase',
161-
'CalendarConstraints',
162-
'CalendarRangeWithValue',
163-
'CalendarTwoMonths',
164-
],
165-
],
166-
[
167-
'kanban board for sprint tasks with a filter bar',
168-
['ToolbarTableFilter', 'PowerSearchShowcase'],
169-
],
121+
['analytics dashboard with a KPI row and a sortable table', ['Table']],
122+
['settings page with notification toggles and a save bar', ['Switch']],
123+
['empty state for a question bank with an import button', ['EmptyState']],
124+
['login form with single sign-on buttons', ['Button', 'FormLayout']],
125+
['calendar for booking appointments', ['Calendar']],
126+
['kanban board for sprint tasks with a filter bar', ['Toolbar']],
170127
];
171128

172129
/** @type {typeof globalThis.fetch} */
@@ -265,7 +222,7 @@ describe('build tree', () => {
265222
expect(loadBlockPicker()).not.toBeNull();
266223
});
267224

268-
for (const [phrase, blocks] of PINNED) {
225+
for (const [phrase, components] of PINNED) {
269226
it(`answers "${phrase}" offline with the picker's blocks`, async () => {
270227
const answer = await build(phrase, {cwd: REPO});
271228
const own = await withListingCache(() => buildKit(phrase, {cwd: REPO}));
@@ -290,7 +247,30 @@ describe('build tree', () => {
290247
const mine = own.data.blocks.find(o => o.name === b.name);
291248
if (mine) expect(mine).toEqual(b);
292249
}
293-
expect(answer.data.blocks.map(b => b.name)).toEqual(blocks);
250+
// Build names the blocks the picker ranks, in its order, whatever blocks
251+
// the catalog holds.
252+
const signals = await withListingCache(() =>
253+
kitSignals(phrase, {cwd: REPO}),
254+
);
255+
const picker = loadBlockPicker();
256+
if (!picker) throw new Error('expected the block picker');
257+
expect(answer.data.blocks.map(b => b.name)).toEqual(
258+
pickBlocks(phrase, signals, picker).names,
259+
);
260+
// Each component the request names gets at least one of its own blocks:
261+
// a block belongs to the longest component name it starts with, as the
262+
// picker reads it.
263+
const byLength = signals.components
264+
.map(c => c.name)
265+
.sort((a, b) => b.length - a.length);
266+
const componentOf = (/** @type {string} */ name) =>
267+
byLength.find(c => name.startsWith(c));
268+
for (const component of components) {
269+
expect(
270+
answer.data.blocks.some(b => componentOf(b.name) === component),
271+
component,
272+
).toBe(true);
273+
}
294274
// Never longer than build's own answer for the same request.
295275
expect(Buffer.byteLength(JSON.stringify(answer))).toBeLessThanOrEqual(
296276
Buffer.byteLength(JSON.stringify(own)),

0 commit comments

Comments
 (0)