fix(documents): sort newest rows first
This commit is contained in:
33
web/tests/document-center-sort.test.mjs
Normal file
33
web/tests/document-center-sort.test.mjs
Normal file
@@ -0,0 +1,33 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import {
|
||||
compareDocumentRowsByLatestTime,
|
||||
sortDocumentRowsByLatestTime
|
||||
} from '../src/utils/documentCenterSort.js'
|
||||
|
||||
test('document center sorts newest document rows first without mutating input', () => {
|
||||
const rows = [
|
||||
{ documentNo: 'AP-001', sortTime: 1000 },
|
||||
{ documentNo: 'AP-003', sortTime: 3000 },
|
||||
{ documentNo: 'AP-002', sortTime: 2000 }
|
||||
]
|
||||
|
||||
const sortedRows = sortDocumentRowsByLatestTime(rows)
|
||||
|
||||
assert.deepEqual(sortedRows.map((row) => row.documentNo), ['AP-003', 'AP-002', 'AP-001'])
|
||||
assert.deepEqual(rows.map((row) => row.documentNo), ['AP-001', 'AP-003', 'AP-002'])
|
||||
})
|
||||
|
||||
test('document center sort falls back to created time and stable document keys', () => {
|
||||
const rows = [
|
||||
{ documentKey: 'owned:AP-001', documentNo: 'AP-001', sortTime: 1000, createdSortTime: 1000 },
|
||||
{ documentKey: 'owned:AP-002', documentNo: 'AP-002', sortTime: 1000, createdSortTime: 2000 },
|
||||
{ documentKey: 'owned:AP-003', documentNo: 'AP-003', sortTime: 1000, createdSortTime: 2000 }
|
||||
]
|
||||
|
||||
const sortedRows = sortDocumentRowsByLatestTime(rows)
|
||||
|
||||
assert.deepEqual(sortedRows.map((row) => row.documentNo), ['AP-003', 'AP-002', 'AP-001'])
|
||||
assert.equal(compareDocumentRowsByLatestTime(rows[1], rows[2]) > 0, true)
|
||||
})
|
||||
@@ -68,6 +68,7 @@ test('documents center category tabs map to the intended row sources', () => {
|
||||
assert.match(documentsCenterView, /excludeArchivedDocumentRows/)
|
||||
assert.match(documentsCenterView, /approvalRows\.value = excludeArchivedDocumentRows/)
|
||||
assert.match(documentsCenterView, /const nonArchivedRows = computed\(\(\) => mergeDocumentRows\(\[\.\.\.ownedRows\.value, \.\.\.approvalRows\.value\]\)\)/)
|
||||
assert.match(documentsCenterView, /import \{ sortDocumentRowsByLatestTime \} from '..\/utils\/documentCenterSort\.js'/)
|
||||
assert.match(documentsCenterView, /activeScopeTab\.value !== DOCUMENT_SCOPE_ARCHIVE && isArchivedDocumentRow\(row\)/)
|
||||
assert.match(
|
||||
documentsCenterView,
|
||||
@@ -92,6 +93,23 @@ test('documents center category tabs map to the intended row sources', () => {
|
||||
assert.match(documentsCenterView, /return nonArchivedRows\.value/)
|
||||
})
|
||||
|
||||
test('documents center sorts every filtered scope by latest document time before pagination', () => {
|
||||
assert.match(
|
||||
documentsCenterView,
|
||||
/return sortDocumentRowsByLatestTime\(activeScopeRows\.value\.filter\(\(row\) => \{[\s\S]*matchesKeyword && matchesDocumentType && matchesScene && matchesStatus && matchesDateRange[\s\S]*\}\)\)/
|
||||
)
|
||||
assert.match(
|
||||
documentsCenterView,
|
||||
/const createdSortTime = resolveDocumentSortTime\(createdAtSource\)[\s\S]*const updatedSortTime = resolveDocumentSortTime\(updatedAtSource\)/
|
||||
)
|
||||
assert.match(
|
||||
documentsCenterView,
|
||||
/createdSortTime,[\s\S]*updatedSortTime,[\s\S]*sortTime: Math\.max\(createdSortTime, updatedSortTime\)/
|
||||
)
|
||||
assert.match(documentsCenterView, /return sortDocumentRowsByLatestTime\(Array\.from\(rowMap\.values\(\)\)\)/)
|
||||
assert.doesNotMatch(documentsCenterView, /right\.sortTime - left\.sortTime/)
|
||||
})
|
||||
|
||||
test('documents center preserves application document type from mapped requests', () => {
|
||||
assert.match(
|
||||
documentsCenterView,
|
||||
|
||||
Reference in New Issue
Block a user