Skip to content
Astera Technology

Render optional sections from an explicit choice

Keep section choice independent of a legitimate zero value.

Download complete case notes and answer keys ↓

Set the decision and its input

The local document model has an enabled flag and a numeric value. Enabled true with zero must render the Allowance section and output 0. Enabled false with seven must render neither. Testing only whether the number is truthy fails both decisions.

Filled local test worksheet
CaseInput JSON
Base test{"enabled":true,"value":0}
Download editable CSV ↓

Run the supplied comparison

An actual browser document is rendered and queried for section presence and output text. This checks generated structure, not merely a Boolean result stored in a worksheet.

Faulty and required outputs
PathOutput JSON
Faulty path{"sectionPresent":false,"value":null}
Required path{"sectionPresent":true,"value":"0"}
Download editable CSV ↓
Node24.14.1 programme; Playwright1.63 Chromium required
import assert from 'node:assert/strict';
import {createRequire} from 'node:module';
const htmlEscape=s=>String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
async function withPage(action,options={}){
  const require=createRequire(import.meta.url);const {chromium}=require('playwright');
  const browser=await chromium.launch({headless:true});
  try{const context=await browser.newContext(options);const page=await context.newPage();
    const requests=[];await page.route('**/*',route=>{requests.push(route.request().url());return route.abort();});
    return await action(page,context,requests);
  }finally{await browser.close();}
}

const run=async function run(i,corrected=true){
    if(typeof i.enabled!=='boolean')return {held:true};
    if(i.enabled&&!Number.isFinite(i.value))return {held:true};
    return withPage(async page=>{const show=corrected?i.enabled:!!i.value;await page.setContent('<main>'+ (show?'<section id="bonus"><h2>Allowance</h2><output>'+htmlEscape(i.value)+'</output></section>':'')+'</main>');
      return page.evaluate(()=>({sectionPresent:!!document.querySelector('#bonus'),value:document.querySelector('output')?.textContent??null}));});
  };
const cases=[{"input":{"enabled":true,"value":0},"corrected":false,"expected":{"sectionPresent":false,"value":null}},{"input":{"enabled":true,"value":0},"corrected":true,"expected":{"sectionPresent":true,"value":"0"}},{"input":{"enabled":false,"value":7},"corrected":true,"expected":{"sectionPresent":false,"value":null}},{"input":{"enabled":null,"value":0},"corrected":true,"expected":{"held":true}}];
for(const test of cases){const actual=await run(test.input,test.corrected);assert.deepEqual(actual,test.expected);console.log(actual);}
Download runnable example ↓

Choose from the boundary evidence

The disabled-seven case remains absent. A null section choice is held before rendering; a missing decision is not an instruction to hide a zero.

  1. Read the explicit section choice
  2. Render or omit the whole section
  3. Check value and structure separately

Hold an unknown choice before generating a document.

Editable boundary inputs and outputs
ConditionInput JSONExpected output JSON
disabled nonzero value{"enabled":false,"value":7}{"sectionPresent":false,"value":null}
section choice unknown{"enabled":null,"value":0}{"held":true}
Download editable CSV ↓

What must the base enabled-zero output contain?

Show the worked answer

One Allowance section with output text 0. Its presence follows enabled=true, while the value is preserved independently.

Related resources