bmc_hub/tests/test_case_v5_billing_preview_ui.py

21 lines
1.5 KiB
Python
Raw Normal View History

from pathlib import Path
import shutil
import subprocess
import pytest
@pytest.mark.skipif(not shutil.which('node'), reason='Node required')
def test_preview_displays_actual_method_and_review_without_manual_choice():
source=Path('static/js/case-v5.js').read_text()
function=source.split(' async function refreshBillingPreview()',1)[1].split(' function scheduleBillingPreview()',1)[0]
script='''
const assert=require('node:assert/strict');
const hints=[{},{}],previewFields=hints.map(host=>({host:{querySelector:()=>host},minutes:'minutes',description:'description',type:'type'}));
const config={caseId:196},byId=id=>({value:id==='minutes'?'30':id==='description'?'ABA support':'support'});
let result={status:'decided',method:'subscription'};
const fetch=async url=>{assert.match(url,/billing-preview/);assert.match(url,/minutes=30/);return{ok:true,json:async()=>result};};
async function refreshBillingPreview() BODY
(async()=>{await refreshBillingPreview();assert.equal(hints[0].textContent,'Forslag: Fastpris');assert.equal(hints[1].textContent,'Forslag: Fastpris');result={status:'manual_review',method:null};await refreshBillingPreview();assert.equal(hints[0].textContent,'Forslag: Manuel vurdering');result={status:'draft',method:'draft'};await refreshBillingPreview();assert.equal(hints[0].textContent,'Forslag: Kladde');})().catch(e=>{console.error(e);process.exitCode=1;});
'''.replace('BODY',function)
result=subprocess.run(['node','-e',script],capture_output=True,text=True)
assert result.returncode==0,result.stderr