Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*!
* Copyright (c) 2022-2025 Digital Bazaar, Inc. All rights reserved.
*/

// Helper to load image as Promise
export function loadImage(src) {
return new Promise((resolve, reject) => {
const img = new Image();
img.onload = () => resolve(img);
img.onerror = () => reject(new Error('Failed to load image'));
img.src = src;
});
}

Binary file added test/images/pdf417/001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/images/pdf417/002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/images/pdf417/003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/images/qr_code/001.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/images/qr_code/002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions test/mockData.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@vuelidate/core": "^2.0.3",
"@vuelidate/validators": "^2.0.4",
"@vueuse/core": "^10.9.0",
"@zxing/library": "^0.21.3",
"vue": "^3.4.21",
"vue-router": "^4.3.0"
}
Expand Down
12 changes: 12 additions & 0 deletions test/test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ config.karma.config.webpack.resolve = {
path.resolve(__dirname, 'node_modules')
]
};
config.karma.config.files.push({
pattern: 'images/qr_code/**/*.*',
included: false,
served: true,
watched: false
});
config.karma.config.files.push({
pattern: 'images/pdf417/**/*.*',
included: false,
served: true,
watched: false
});
89 changes: 85 additions & 4 deletions test/web/10-api.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,92 @@
/*!
* Copyright (c) 2022-2025 Digital Bazaar, Inc. All rights reserved.
*/
import * as helpers from '../helpers.js';
import {BrowserPDF417Reader} from '@zxing/library';
import mockData from '../mockData.js';
import '@bedrock/vue-barcode-scanner';

describe('FIXME API', function() {
describe('FIXME API', function() {
it('should test something', async () => {
describe('QR Codes', function() {
// check if BarcodeDetector is supported
const {BarcodeDetector} = globalThis;
if(!BarcodeDetector) {
console.warn('Barcode Detector is not supported.');
this.skip();
return;
}
const barcodeType = 'qr_code';
const formats = [barcodeType];
const barcodeDetector = new BarcodeDetector({formats});

// list all images to test from images directory
const pathToBarcodes = '/base/images/qr_code/';
const imageNames = ['001.gif', '002.png'];

// test each image in imageNames
for(const imageName of imageNames) {
it(`should detect QR code text from ${imageName}`, async function() {
// load image
const imageUrl = pathToBarcodes + imageName;
const img = await helpers.loadImage(imageUrl);
// detect barcode
const barcodes = await barcodeDetector.detect(img);
if(barcodes.length === 0) {
throw new Error('No QR code detected');
}
// assert barcode's specific text
const barcodeText = barcodes[0].rawValue;
if(!mockData[barcodeType][imageName]) {
throw new Error(`Missing mockData text value for: ${imageName}`);
}
if(barcodeText !== mockData[barcodeType][imageName]) {
throw new Error(`Unexpected QR code content: ${barcodeText}`);
}
});
}
});

describe.only('PDF417', function() {
// check if BarcodeDetector is supported
const {BarcodeDetector} = globalThis;
if(!BarcodeDetector) {
console.warn('Barcode Detector is not supported.');
this.skip();
return;
}
const barcodeType = 'pdf417';
const formats = [barcodeType];
const barcodeDetector = new BarcodeDetector({formats});

// list all images to test from images directory
const pathToBarcodes = '/base/images/pdf417/';
const imageNames = ['001.png', '002.png', '003.png'];

// test each image in imageNames
for(const imageName of imageNames) {
it(`should detect PDF417 text from ${imageName}`, async function() {
// load image
const imageUrl = pathToBarcodes + imageName;
const img = await helpers.loadImage(imageUrl);

// detect barcode
const barcodes = await barcodeDetector.detect(img);
if(barcodes.length === 0) {
throw new Error('No PDF417 detected');
}
// assert barcode's specific text
let barcodeText = barcodes[0].rawValue;
if(!mockData[barcodeType][imageName]) {
throw new Error(`Missing mockData text value for: ${imageName}`);
}
if(!barcodeText) {
const reader = new BrowserPDF417Reader();
const result = await reader.decodeFromImageElement(img);
barcodeText = result.getText();
console.log('USED ZXING LIBRARY --------------->');
}
if(barcodeText !== mockData[barcodeType][imageName]) {
throw new Error(`Unexpected PDF417 content: ${barcodeText}`);
}
});
});
}
});
Loading