cmvr-wms/ruoyi-ui-vue3/tests/unit/history-entry-result.test.mjs

25 lines
1.5 KiB
JavaScript
Raw Normal View History

import test from 'node:test'
import assert from 'node:assert/strict'
import {sourceWasRecorded,markRecordedPage,encodeHistoricalFields} from '../../src/utils/history-entry-result.js'
test('timeout recovery requires the exact saved source, not a similar search result',()=>{
assert.equal(sourceWasRecorded([{sourceId:760,saved:true}],760),true)
assert.equal(sourceWasRecorded([{sourceId:1760,saved:true}],760),false)
assert.equal(sourceWasRecorded([{sourceId:760,saved:false}],760),false)
assert.equal(sourceWasRecorded(undefined,760),false)
})
test('a confirmed individual form updates one visible row without duplicate count increments',()=>{
const source=[{sourceId:1,saved:false},{sourceId:2,saved:false}]
const first=markRecordedPage(source,1,true)
assert.deepEqual(first,{changed:true,rows:[source[1]]})
assert.equal(markRecordedPage(first.rows,1,true).changed,false)
const marked=markRecordedPage(source,2,false)
assert.equal(marked.rows[1].saved,true);assert.equal(source[1].saved,false)
assert.equal(markRecordedPage(marked.rows,2,false).changed,false)
})
test('historical text uses lossless UTF-8 transport without disabling the input filter',()=>{
const fields={os:'Windows >=10',data:'<script>alert("x")</script> & 中文🙂',nullable:null,long:'中'.repeat(20000)}
const encoded=encodeHistoricalFields(fields)
assert.match(encoded,/^[A-Za-z0-9+/=]+$/)
assert.deepEqual(JSON.parse(new TextDecoder().decode(Uint8Array.from(atob(encoded),c=>c.charCodeAt(0)))),fields)
})