29 lines
1.2 KiB
JavaScript
29 lines
1.2 KiB
JavaScript
'use strict'
|
|
|
|
const assert = require('assert')
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
const vm = require('vm')
|
|
|
|
const root = path.resolve(__dirname, '..')
|
|
const sandbox = {}
|
|
vm.runInNewContext(fs.readFileSync(path.join(root, 'src', 'gallery-query.js'), 'utf8'), sandbox)
|
|
const query = sandbox.IWBGalleryQuery
|
|
assert.ok(query)
|
|
|
|
const now = 1_700_000_000_000
|
|
const items = [
|
|
{ name: 'old.png', label: 'cat', mtime: now - 31 * 86400e3, w: 100, h: 100 },
|
|
{ name: 'new.png', label: 'Cat poster', mtime: now - 2 * 86400e3, w: 100, h: 200 },
|
|
{ name: 'today.png', label: 'landscape', mtime: now - 2 * 3600e3, w: 200, h: 100 },
|
|
]
|
|
assert.strictEqual(query.filterOutputs(items, { query: 'CAT', now }).length, 2)
|
|
assert.strictEqual(query.filterOutputs(items, { range: '7d', now }).length, 2)
|
|
assert.strictEqual(query.filterOutputs(items, { range: 'today', now }).length, 1)
|
|
assert.deepStrictEqual(query.paginateOutputs(items, 2).map((x) => x.name), ['today.png', 'new.png'])
|
|
const columns = query.queryOutputs(items, { query: '', now, limit: 3, width: 300 }).columns
|
|
assert.strictEqual(columns.buckets.length, 2)
|
|
assert.strictEqual(columns.colW, 146)
|
|
assert.strictEqual(query.rangeMilliseconds('30d'), 30 * 86400e3)
|
|
console.log('gallery query checks passed')
|