feat(scan): add guided Linux agent setup in administration
This commit is contained in:
@@ -4,21 +4,21 @@ const fs = require('node:fs')
|
||||
const vm = require('node:vm')
|
||||
const vue = require('vue')
|
||||
|
||||
async function setup(getJob) {
|
||||
async function setup(getJob, scanData = {}, agents = [{ id: 'agent', active: true, capabilities: { scan: true }, scannerNames: ['fujitsu:ScanSnap iX1600:test'] }]) {
|
||||
const notices = []
|
||||
const requests = []
|
||||
let unmount
|
||||
const context = vm.createContext({
|
||||
ref: vue.ref, reactive: vue.reactive, computed: vue.computed, watch: vue.watch,
|
||||
onBeforeUnmount: handler => { unmount = handler },
|
||||
defineProps: () => ({ scanData: { folder: 'folder-1', type: 'document' } }),
|
||||
defineProps: () => ({ scanData: { folder: 'folder-1', type: 'document', ...scanData } }),
|
||||
defineEmits: () => () => {},
|
||||
useModal: () => ({ close() {} }),
|
||||
useToast: () => ({ add: notice => notices.push(notice) }),
|
||||
setTimeout: callback => queueMicrotask(callback),
|
||||
useNuxtApp: () => ({ $api: async (url, options) => {
|
||||
requests.push({ url, options })
|
||||
if (url === '/api/instance-agents') return { agents: [{ id: 'agent', active: true, capabilities: { scan: true }, scannerNames: ['fujitsu:ScanSnap iX1600:test'] }] }
|
||||
if (url === '/api/instance-agents') return { agents }
|
||||
if (url === '/api/scan-jobs') return { job: { id: 'job' } }
|
||||
return getJob()
|
||||
} }),
|
||||
@@ -70,3 +70,16 @@ test('iX1600 preset resets image settings and normalizes the output filename to
|
||||
assert.equal(ui.run('scanForm.postprocess'), false)
|
||||
assert.equal(ui.run('scanForm.resolution'), 300)
|
||||
})
|
||||
|
||||
test('setup test scan uses the requested agent even when another agent is first', async () => {
|
||||
const agents = ['first', 'configured'].map(id => ({ id, active: true, capabilities: { scan: true }, scannerNames: ['scanner-' + id] }))
|
||||
const ui = await setup(() => ({ job: { status: 'completed' } }), { agentId: 'configured' }, agents)
|
||||
await ui.run('startScan()')
|
||||
assert.equal(ui.requests.find(request => request.url === '/api/scan-jobs').options.body.agentId, 'configured')
|
||||
})
|
||||
|
||||
test('an unavailable setup agent never silently scans with another device', async () => {
|
||||
const ui = await setup(() => ({}), { agentId: 'missing' })
|
||||
await ui.run('startScan()')
|
||||
assert.equal(ui.requests.filter(request => request.url === '/api/scan-jobs').length, 0)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user