Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-ui-prototype-preview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fill `{{__proto__}}` blanks in the builder preview and iteration labels consistently with the generated CLI command (#327).
33 changes: 33 additions & 0 deletions dist/ui-interactions.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/ui-interactions.test.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@
}

const arrayVars = [];
const scalarValues = {};
const scalarValues = Object.create(null);

for (const row of rows) {
const vals = splitValues(row.values, row.source);
Expand All @@ -858,7 +858,7 @@
const results = [];
try {
for (const combo of combos) {
const vals = { ...scalarValues };
const vals = Object.assign(Object.create(null), scalarValues);
arrayVars.forEach((v, i) => { vals[v.name] = combo[i]; });
results.push({ values: { ...vals }, expanded: sharedExpand(text, vals) });
}
Expand Down
40 changes: 40 additions & 0 deletions src/ui-interactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,46 @@ test('update zips comma-separated rows in zip mode and renders one iteration per
assert.equal(h.cli(), 'promptargs "Review {{file}} for {{focus}}" --file=a.go,b.go --focus=x,y');
});

test('update fills a scalar __proto__ blank advertised by the CLI command', async () => {
const h = makeHarness(5);
h.tmpl.value = 'Hello {{__proto__}}';
h.addVarRow('__proto__', 'world', 'manual');
h.scheduleUpdate();
await tick(20);
assert.equal(h.previewCount.textContent, '1 result');
assert.equal(h.previewBody.innerHTML,
'<div class="iteration"><div class="expanded-text">Hello world</div></div>');
assert.equal(h.cli(), 'promptargs "Hello {{__proto__}}" --__proto__=world');
});

for (const mode of ['zip', 'cross'] as const) {
for (const values of ['world', 'world,friend']) {
test(`update preserves ${values.includes(',') ? 'array' : 'scalar'} __proto__ values and labels in ${mode} mode`, async () => {
const h = makeHarness(5);
h.loadPreset({ name: 'empty', desc: '', template: '', vars: {}, mode });
h.tmpl.value = 'Hello {{__proto__}} from {{place}}';
h.addVarRow('__proto__', values, 'manual');
h.addVarRow('place', 'here,there', 'manual');
h.scheduleUpdate();
await tick(20);

const expected = values === 'world'
? [['world', 'here'], ['world', 'there']]
: mode === 'zip'
? [['world', 'here'], ['friend', 'there']]
: [['world', 'here'], ['world', 'there'], ['friend', 'here'], ['friend', 'there']];
assert.equal(h.previewCount.textContent, `${expected.length} results`);
assert.equal(h.previewBody.innerHTML, expected.map(([name, place], i) =>
`<div class="iteration"><div class="iter-label">[${i + 1}/${expected.length}] __proto__=${name} place=${place}</div>` +
`<div class="expanded-text">Hello ${name} from ${place}</div></div>`
).join(''));
const crossFlag = mode === 'cross' && values.includes(',') ? ' --cross' : '';
assert.equal(h.cli(),
`promptargs "Hello {{__proto__}} from {{place}}" --__proto__=${values} --place=here,there${crossFlag}`);
});
}
}

test('update with a blank template renders the empty state and a bare command', async () => {
const h = makeHarness(5);
h.addVarRow('name', 'World', 'manual');
Expand Down
4 changes: 2 additions & 2 deletions src/ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@
}

const arrayVars = [];
const scalarValues = {};
const scalarValues = Object.create(null);

for (const row of rows) {
const vals = splitValues(row.values, row.source);
Expand All @@ -858,7 +858,7 @@
const results = [];
try {
for (const combo of combos) {
const vals = { ...scalarValues };
const vals = Object.assign(Object.create(null), scalarValues);
arrayVars.forEach((v, i) => { vals[v.name] = combo[i]; });
results.push({ values: { ...vals }, expanded: sharedExpand(text, vals) });
}
Expand Down
Loading