mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
Fixed tests
This commit is contained in:
@@ -46,7 +46,7 @@
|
|||||||
"no-extra-boolean-cast": 1,
|
"no-extra-boolean-cast": 1,
|
||||||
"no-multi-spaces": 2,
|
"no-multi-spaces": 2,
|
||||||
"no-underscore-dangle": 0,
|
"no-underscore-dangle": 0,
|
||||||
"comma-dangle": 2,
|
"comma-dangle": 0,
|
||||||
"camelcase": 0,
|
"camelcase": 0,
|
||||||
"curly": 2,
|
"curly": 2,
|
||||||
"eqeqeq": 2,
|
"eqeqeq": 2,
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,6 @@ import {createConfigFromSource} from './input/config_factory';
|
|||||||
|
|
||||||
function fromSource(config, source, inputConfig = {}) {
|
function fromSource(config, source, inputConfig = {}) {
|
||||||
config = createConfigFromSource(config, inputConfig, source);
|
config = createConfigFromSource(config, inputConfig, source);
|
||||||
console.log(config);
|
|
||||||
const scanner = createScanner();
|
const scanner = createScanner();
|
||||||
return {
|
return {
|
||||||
addEventListener(eventType, cb) {
|
addEventListener(eventType, cb) {
|
||||||
@@ -36,6 +35,7 @@ function fromSource(config, source, inputConfig = {}) {
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
toPromise() {
|
toPromise() {
|
||||||
|
// how to cancel?? timeout!
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
scanner.decodeSingle(config, (result) => {
|
scanner.decodeSingle(config, (result) => {
|
||||||
if (result && result.codeResult && result.codeResult.code) {
|
if (result && result.codeResult && result.codeResult.code) {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ describe('decodeSingle', function () {
|
|||||||
config.readers = readers;
|
config.readers = readers;
|
||||||
Quagga
|
Quagga
|
||||||
.config(config)
|
.config(config)
|
||||||
.fromImage(config.src)
|
.fromSource(config.src)
|
||||||
.addEventListener('processed', function(result){
|
.addEventListener('processed', function(result){
|
||||||
console.log(sample.name);
|
console.log(sample.name);
|
||||||
expect(result.codeResult.code).to.equal(sample.result);
|
expect(result.codeResult.code).to.equal(sample.result);
|
||||||
|
|||||||
+146
-144
@@ -5,173 +5,175 @@ var originalURL,
|
|||||||
video,
|
video,
|
||||||
stream;
|
stream;
|
||||||
|
|
||||||
beforeEach(function() {
|
describe("CameraAccess", () => {
|
||||||
var tracks = [{
|
|
||||||
stop: function() {}
|
|
||||||
}];
|
|
||||||
|
|
||||||
originalURL = window.URL;
|
|
||||||
originalMediaStreamTrack = window.MediaStreamTrack;
|
|
||||||
window.MediaStreamTrack = {};
|
|
||||||
window.URL = {
|
|
||||||
createObjectURL(stream) {
|
|
||||||
return stream;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
stream = {
|
|
||||||
getVideoTracks: function() {
|
|
||||||
return tracks;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
sinon.spy(tracks[0], "stop");
|
|
||||||
|
|
||||||
video = {
|
|
||||||
srcObject: null,
|
|
||||||
addEventListener: function() {},
|
|
||||||
removeEventListener: function() {},
|
|
||||||
setAttribute: sinon.spy(),
|
|
||||||
play: function() {},
|
|
||||||
videoWidth: 320,
|
|
||||||
videoHeight: 480
|
|
||||||
};
|
|
||||||
sinon.stub(video, "addEventListener", function(event, cb) {
|
|
||||||
cb();
|
|
||||||
});
|
|
||||||
sinon.stub(video, "play");
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(function() {
|
|
||||||
window.URL = originalURL;
|
|
||||||
window.MediaStreamTrack = originalMediaStreamTrack;
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('success', function() {
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
sinon.stub(navigator.mediaDevices, "getUserMedia", function(constraints) {
|
var tracks = [{
|
||||||
return Promise.resolve(stream);
|
stop: function() {}
|
||||||
|
}];
|
||||||
|
|
||||||
|
originalURL = window.URL;
|
||||||
|
originalMediaStreamTrack = window.MediaStreamTrack;
|
||||||
|
window.MediaStreamTrack = {};
|
||||||
|
window.URL = {
|
||||||
|
createObjectURL() {
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
stream = {
|
||||||
|
getVideoTracks: function() {
|
||||||
|
return tracks;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
sinon.spy(tracks[0], "stop");
|
||||||
|
|
||||||
|
video = {
|
||||||
|
srcObject: null,
|
||||||
|
addEventListener: function() {},
|
||||||
|
removeEventListener: function() {},
|
||||||
|
setAttribute: sinon.spy(),
|
||||||
|
play: function() {},
|
||||||
|
videoWidth: 320,
|
||||||
|
videoHeight: 480
|
||||||
|
};
|
||||||
|
sinon.stub(video, "addEventListener", function(event, cb) {
|
||||||
|
cb();
|
||||||
});
|
});
|
||||||
|
sinon.stub(video, "play");
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
navigator.mediaDevices.getUserMedia.restore();
|
window.URL = originalURL;
|
||||||
});
|
window.MediaStreamTrack = originalMediaStreamTrack;
|
||||||
describe('request', function () {
|
|
||||||
it('should request the camera', function (done) {
|
|
||||||
CameraAccess.request(video, {})
|
|
||||||
.then(function () {
|
|
||||||
expect(navigator.mediaDevices.getUserMedia.calledOnce).to.equal(true);
|
|
||||||
expect(video.srcObject).to.deep.equal(stream);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should allow deprecated constraints to be used", (done) => {
|
|
||||||
CameraAccess.request(video, {
|
|
||||||
width: 320,
|
|
||||||
height: 240,
|
|
||||||
facing: "user",
|
|
||||||
minAspectRatio: 2,
|
|
||||||
maxAspectRatio: 100
|
|
||||||
})
|
|
||||||
.then(function () {
|
|
||||||
const call = navigator.mediaDevices.getUserMedia.getCall(0),
|
|
||||||
args = call.args;
|
|
||||||
expect(call).to.be.defined;
|
|
||||||
expect(args[0].video.width).to.equal(320);
|
|
||||||
expect(args[0].video.height).to.equal(240);
|
|
||||||
expect(args[0].video.facingMode).to.equal("user");
|
|
||||||
expect(args[0].video.aspectRatio).to.equal(2);
|
|
||||||
expect(args[0].video.facing).not.to.be.defined;
|
|
||||||
expect(args[0].video.minAspectRatio).not.to.be.defined;
|
|
||||||
expect(args[0].video.maxAspectRatio).not.to.be.defined;
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('facingMode fallback in Chrome', () => {
|
describe('success', function() {
|
||||||
beforeEach(() => {
|
|
||||||
window.MediaStreamTrack.getSources = (cb) => {
|
|
||||||
return cb([
|
|
||||||
{kind: "video", facing: "environment", id: "environment"},
|
|
||||||
{kind: "audio", id: "audio"},
|
|
||||||
{kind: "video", facing: "user", id: "user"}
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
window.MediaStreamTrack = {};
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should set deviceId in case facingMode is not supported", (done) => {
|
|
||||||
CameraAccess.request(video, {
|
|
||||||
facing: "user"
|
|
||||||
})
|
|
||||||
.then(function () {
|
|
||||||
const call = navigator.mediaDevices.getUserMedia.getCall(0),
|
|
||||||
args = call.args;
|
|
||||||
expect(call).to.be.defined;
|
|
||||||
expect(args[0].video.facingMode).not.to.be.defined;
|
|
||||||
expect(args[0].video.deviceId).to.equal("user");
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('release', function () {
|
|
||||||
it('should release the camera', function (done) {
|
|
||||||
CameraAccess.request(video, {})
|
|
||||||
.then(function () {
|
|
||||||
expect(video.srcObject).to.deep.equal(stream);
|
|
||||||
CameraAccess.release();
|
|
||||||
expect(video.srcObject.getVideoTracks()).to.have.length(1);
|
|
||||||
expect(video.srcObject.getVideoTracks()[0].stop.calledOnce).to.equal(true);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('failure', function() {
|
|
||||||
describe("permission denied", function(){
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
sinon.stub(navigator.mediaDevices, "getUserMedia", function(constraints, success, failure) {
|
sinon.stub(navigator.mediaDevices, "getUserMedia", function(constraints) {
|
||||||
return Promise.reject(new Error());
|
return Promise.resolve(stream);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
navigator.mediaDevices.getUserMedia.restore();
|
navigator.mediaDevices.getUserMedia.restore();
|
||||||
});
|
});
|
||||||
|
describe('request', function () {
|
||||||
|
it('should request the camera', function (done) {
|
||||||
|
CameraAccess.request(video, {})
|
||||||
|
.then(function () {
|
||||||
|
expect(navigator.mediaDevices.getUserMedia.calledOnce).to.equal(true);
|
||||||
|
expect(video.srcObject).to.deep.equal(stream);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should throw if getUserMedia not available', function(done) {
|
it("should allow deprecated constraints to be used", (done) => {
|
||||||
CameraAccess.request(video, {})
|
CameraAccess.request(video, {
|
||||||
.catch(function (err) {
|
width: 320,
|
||||||
expect(err).to.be.defined;
|
height: 240,
|
||||||
done();
|
facing: "user",
|
||||||
|
minAspectRatio: 2,
|
||||||
|
maxAspectRatio: 100
|
||||||
|
})
|
||||||
|
.then(function () {
|
||||||
|
const call = navigator.mediaDevices.getUserMedia.getCall(0),
|
||||||
|
args = call.args;
|
||||||
|
expect(call).to.be.defined;
|
||||||
|
expect(args[0].video.width).to.equal(320);
|
||||||
|
expect(args[0].video.height).to.equal(240);
|
||||||
|
expect(args[0].video.facingMode).to.equal("user");
|
||||||
|
expect(args[0].video.aspectRatio).to.equal(2);
|
||||||
|
expect(args[0].video.facing).not.to.be.defined;
|
||||||
|
expect(args[0].video.minAspectRatio).not.to.be.defined;
|
||||||
|
expect(args[0].video.maxAspectRatio).not.to.be.defined;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('facingMode fallback in Chrome', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
window.MediaStreamTrack.getSources = (cb) => {
|
||||||
|
return cb([
|
||||||
|
{kind: "video", facing: "environment", id: "environment"},
|
||||||
|
{kind: "audio", id: "audio"},
|
||||||
|
{kind: "video", facing: "user", id: "user"}
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
window.MediaStreamTrack = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should set deviceId in case facingMode is not supported", (done) => {
|
||||||
|
CameraAccess.request(video, {
|
||||||
|
facing: "user"
|
||||||
|
})
|
||||||
|
.then(function () {
|
||||||
|
const call = navigator.mediaDevices.getUserMedia.getCall(0),
|
||||||
|
args = call.args;
|
||||||
|
expect(call).to.be.defined;
|
||||||
|
expect(args[0].video.facingMode).not.to.be.defined;
|
||||||
|
expect(args[0].video.deviceId).to.equal("user");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('release', function () {
|
||||||
|
it('should release the camera', function (done) {
|
||||||
|
CameraAccess.request(video, {})
|
||||||
|
.then(function () {
|
||||||
|
expect(video.srcObject).to.deep.equal(stream);
|
||||||
|
CameraAccess.release();
|
||||||
|
expect(video.srcObject.getVideoTracks()).to.have.length(1);
|
||||||
|
expect(video.srcObject.getVideoTracks()[0].stop.calledOnce).to.equal(true);
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("not available", function(){
|
describe('failure', function() {
|
||||||
var originalGetUserMedia;
|
describe("permission denied", function(){
|
||||||
|
beforeEach(function() {
|
||||||
|
sinon.stub(navigator.mediaDevices, "getUserMedia", function(constraints, success, failure) {
|
||||||
|
return Promise.reject(new Error());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(function() {
|
afterEach(function() {
|
||||||
originalGetUserMedia = navigator.mediaDevices.getUserMedia;
|
navigator.mediaDevices.getUserMedia.restore();
|
||||||
navigator.mediaDevices.getUserMedia = undefined;
|
});
|
||||||
|
|
||||||
|
it('should throw if getUserMedia not available', function(done) {
|
||||||
|
CameraAccess.request(video, {})
|
||||||
|
.catch(function (err) {
|
||||||
|
expect(err).to.be.defined;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
describe("not available", function(){
|
||||||
navigator.mediaDevices.getUserMedia = originalGetUserMedia;
|
var originalGetUserMedia;
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw if getUserMedia not available', function(done) {
|
beforeEach(function() {
|
||||||
CameraAccess.request(video, {})
|
originalGetUserMedia = navigator.mediaDevices.getUserMedia;
|
||||||
.catch((err) => {
|
navigator.mediaDevices.getUserMedia = undefined;
|
||||||
expect(err).to.be.defined;
|
});
|
||||||
done();
|
|
||||||
|
afterEach(function() {
|
||||||
|
navigator.mediaDevices.getUserMedia = originalGetUserMedia;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw if getUserMedia not available', function(done) {
|
||||||
|
CameraAccess.request(video, {})
|
||||||
|
.catch((err) => {
|
||||||
|
expect(err).to.be.defined;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,14 +9,6 @@ MyFileList.prototype.constructor = MyFileList;
|
|||||||
|
|
||||||
const OriginalFileList = window.FileList;
|
const OriginalFileList = window.FileList;
|
||||||
|
|
||||||
beforeEach(function() {
|
|
||||||
window.FileList = MyFileList;
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(function() {
|
|
||||||
window.FileList = OriginalFileList;
|
|
||||||
});
|
|
||||||
|
|
||||||
function expectImageConfig(config) {
|
function expectImageConfig(config) {
|
||||||
expect(config.inputStream.type).to.equal("ImageStream");
|
expect(config.inputStream.type).to.equal("ImageStream");
|
||||||
expect(config.inputStream.sequence).to.equal(false);
|
expect(config.inputStream.sequence).to.equal(false);
|
||||||
@@ -37,6 +29,14 @@ function expectLiveConfig(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("createConfigFromSource", () => {
|
describe("createConfigFromSource", () => {
|
||||||
|
beforeEach(function() {
|
||||||
|
window.FileList = MyFileList;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
window.FileList = OriginalFileList;
|
||||||
|
});
|
||||||
|
|
||||||
it("should create an image config for an image-file", () => {
|
it("should create an image config for an image-file", () => {
|
||||||
const file = new File([], "image.jpg", {type: 'image/jpg'});
|
const file = new File([], "image.jpg", {type: 'image/jpg'});
|
||||||
const config = createConfigFromSource({}, {}, file);
|
const config = createConfigFromSource({}, {}, file);
|
||||||
|
|||||||
@@ -5,99 +5,101 @@ var canvasMock,
|
|||||||
imageSize,
|
imageSize,
|
||||||
config;
|
config;
|
||||||
|
|
||||||
beforeEach(function() {
|
describe("ResultCollector", () => {
|
||||||
imageSize = {x: 320, y: 240};
|
|
||||||
config = {
|
|
||||||
capture: true,
|
|
||||||
capacity: 20,
|
|
||||||
blacklist: [{code: "3574660239843", format: "ean_13"}],
|
|
||||||
filter: function() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
canvasMock = {
|
|
||||||
getContext: function() {
|
|
||||||
return {};
|
|
||||||
},
|
|
||||||
toDataURL: sinon.spy(),
|
|
||||||
width: 0,
|
|
||||||
height: 0
|
|
||||||
};
|
|
||||||
sinon.stub(document, "createElement", function(type) {
|
|
||||||
if (type === "canvas") {
|
|
||||||
return canvasMock;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(function() {
|
|
||||||
document.createElement.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
describe('create', function () {
|
|
||||||
it("should return a new collector", function() {
|
|
||||||
ResultCollector.create(config);
|
|
||||||
expect(document.createElement.calledOnce).to.be.equal(true);
|
|
||||||
expect(document.createElement.getCall(0).args[0]).to.equal("canvas");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('addResult', function() {
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
sinon.stub(ImageDebug, "drawImage", function() {});
|
imageSize = {x: 320, y: 240};
|
||||||
});
|
config = {
|
||||||
|
capture: true,
|
||||||
afterEach(function() {
|
capacity: 20,
|
||||||
ImageDebug.drawImage.restore();
|
blacklist: [{code: "3574660239843", format: "ean_13"}],
|
||||||
});
|
filter: function() {
|
||||||
|
return true;
|
||||||
it("should not add result if capacity is full", function(){
|
}
|
||||||
config.capacity = 1;
|
};
|
||||||
var collector = ResultCollector.create(config);
|
canvasMock = {
|
||||||
collector.addResult([], imageSize, {});
|
getContext: function() {
|
||||||
collector.addResult([], imageSize, {});
|
return {};
|
||||||
collector.addResult([], imageSize, {});
|
},
|
||||||
expect(collector.getResults()).to.have.length(1);
|
toDataURL: sinon.spy(),
|
||||||
});
|
width: 0,
|
||||||
|
height: 0
|
||||||
it("should only add results which match constraints", function(){
|
};
|
||||||
var collector = ResultCollector.create(config),
|
sinon.stub(document, "createElement", function(type) {
|
||||||
results;
|
if (type === "canvas") {
|
||||||
|
return canvasMock;
|
||||||
collector.addResult([], imageSize, {code: "423423443", format: "ean_13"});
|
}
|
||||||
collector.addResult([], imageSize, {code: "3574660239843", format: "ean_13"});
|
|
||||||
collector.addResult([], imageSize, {code: "3574660239843", format: "code_128"});
|
|
||||||
|
|
||||||
results = collector.getResults();
|
|
||||||
expect(results).to.have.length(2);
|
|
||||||
|
|
||||||
results.forEach(function(result) {
|
|
||||||
expect(result).not.to.deep.equal(config.blacklist[0]);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should add result if no filter is set", function() {
|
afterEach(function() {
|
||||||
delete config.filter;
|
document.createElement.restore();
|
||||||
var collector = ResultCollector.create(config);
|
|
||||||
|
|
||||||
collector.addResult([], imageSize, {code: "423423443", format: "ean_13"});
|
|
||||||
expect(collector.getResults()).to.have.length(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not add results if filter returns false", function() {
|
|
||||||
config.filter = () => (false);
|
|
||||||
var collector = ResultCollector.create(config);
|
|
||||||
|
|
||||||
collector.addResult([], imageSize, {code: "423423443", format: "ean_13"});
|
describe('create', function () {
|
||||||
expect(collector.getResults()).to.have.length(0);
|
it("should return a new collector", function() {
|
||||||
|
ResultCollector.create(config);
|
||||||
|
expect(document.createElement.calledOnce).to.be.equal(true);
|
||||||
|
expect(document.createElement.getCall(0).args[0]).to.equal("canvas");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should add result if no blacklist is set", function() {
|
describe('addResult', function() {
|
||||||
delete config.blacklist;
|
beforeEach(function() {
|
||||||
var collector = ResultCollector.create(config);
|
sinon.stub(ImageDebug, "drawImage", function() {});
|
||||||
|
});
|
||||||
|
|
||||||
collector.addResult([], imageSize, {code: "3574660239843", format: "ean_13"});
|
afterEach(function() {
|
||||||
expect(collector.getResults()).to.have.length(1);
|
ImageDebug.drawImage.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not add result if capacity is full", function(){
|
||||||
|
config.capacity = 1;
|
||||||
|
var collector = ResultCollector.create(config);
|
||||||
|
collector.addResult([], imageSize, {});
|
||||||
|
collector.addResult([], imageSize, {});
|
||||||
|
collector.addResult([], imageSize, {});
|
||||||
|
expect(collector.getResults()).to.have.length(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should only add results which match constraints", function(){
|
||||||
|
var collector = ResultCollector.create(config),
|
||||||
|
results;
|
||||||
|
|
||||||
|
collector.addResult([], imageSize, {code: "423423443", format: "ean_13"});
|
||||||
|
collector.addResult([], imageSize, {code: "3574660239843", format: "ean_13"});
|
||||||
|
collector.addResult([], imageSize, {code: "3574660239843", format: "code_128"});
|
||||||
|
|
||||||
|
results = collector.getResults();
|
||||||
|
expect(results).to.have.length(2);
|
||||||
|
|
||||||
|
results.forEach(function(result) {
|
||||||
|
expect(result).not.to.deep.equal(config.blacklist[0]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should add result if no filter is set", function() {
|
||||||
|
delete config.filter;
|
||||||
|
var collector = ResultCollector.create(config);
|
||||||
|
|
||||||
|
collector.addResult([], imageSize, {code: "423423443", format: "ean_13"});
|
||||||
|
expect(collector.getResults()).to.have.length(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not add results if filter returns false", function() {
|
||||||
|
config.filter = () => (false);
|
||||||
|
var collector = ResultCollector.create(config);
|
||||||
|
|
||||||
|
collector.addResult([], imageSize, {code: "423423443", format: "ean_13"});
|
||||||
|
expect(collector.getResults()).to.have.length(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should add result if no blacklist is set", function() {
|
||||||
|
delete config.blacklist;
|
||||||
|
var collector = ResultCollector.create(config);
|
||||||
|
|
||||||
|
collector.addResult([], imageSize, {code: "3574660239843", format: "ean_13"});
|
||||||
|
expect(collector.getResults()).to.have.length(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user