28 lines
1.5 KiB
TypeScript
28 lines
1.5 KiB
TypeScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { taskItemModel } from '../../YouleNexus/assets/framework/presentation/task-item-model.ts';
|
|
const task={taskid:7,title:'一二三四五六七八九',award:3,finish:2,total:5,state:0};
|
|
test('task item preserves title wrapping, reward wording and incomplete progress',()=>{
|
|
const model=taskItemModel(task,0,'房卡');
|
|
assert.equal(model.title,'一二三四五六七八\n九');
|
|
assert.equal(model.reward,'奖励房卡,数量:3');
|
|
assert.equal(model.progress,0.4);assert.equal(model.progressText,'2/5');
|
|
assert.equal(model.showProgress,true);assert.equal(model.showDo,true);assert.equal(model.showClaim,false);assert.equal(model.showClaimed,false);
|
|
assert.equal(taskItemModel(task,1,'房卡').showDo,false);
|
|
});
|
|
test('claimable and claimed states replace progress and action controls',()=>{
|
|
for(const state of [1,2]){
|
|
const model=taskItemModel({...task,state},0,'金币');
|
|
assert.equal(model.showProgress,false);assert.equal(model.showDo,false);
|
|
assert.equal(model.showClaim,state===1);assert.equal(model.showClaimed,state===2);
|
|
}
|
|
});
|
|
test('incomplete tasks reject invalid totals instead of inventing progress',()=>{
|
|
assert.throws(()=>taskItemModel({...task,total:0},0,'房卡'),/total/);
|
|
assert.throws(()=>taskItemModel({...task,finish:NaN},0,'房卡'),/finish/);
|
|
assert.throws(()=>{
|
|
// @ts-expect-error Exercise malformed data at the runtime boundary.
|
|
taskItemModel({...task,title:undefined},0,'房卡');
|
|
},/title/);
|
|
});
|