This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
132 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import * as Promise from 'bluebird'; | ||
import { expect } from 'chai'; | ||
import * as chai from 'chai'; | ||
import * as chaiAsPromised from 'chai-as-promised'; | ||
import * as sinon from 'sinon'; | ||
import { buildCameraOptions } from '../src/buildCameraOptions'; | ||
import { Camera } from '../src/Camera'; | ||
import { mockCordovaCamera } from './mocks/camera'; | ||
import { resolveLocalFileSystemURL } from './mocks/file'; | ||
|
||
declare var global: any; | ||
|
||
chai.use(chaiAsPromised); | ||
|
||
describe('Camera', function() { | ||
const subject = new Camera(function() { | ||
return { quality: 80 }; | ||
}); | ||
|
||
describe('init', function() { | ||
it('should take a function to partially supply options', function() { | ||
return expect(subject.initPromise).to.eventually.have.property('quality', 80); | ||
}); | ||
}); | ||
describe('cleanup', function() { | ||
it('should call the cordova cleanup function', function() { | ||
return subject.cleanup().then(function() { | ||
sinon.assert.called(mockCordovaCamera.cleanup); | ||
}); | ||
}); | ||
}); | ||
describe('capture', function() { | ||
it('return a local uri when successful', function() { | ||
return subject.capture().then(result => { | ||
expect(result).to.deep.equal({ | ||
type: 'uri', | ||
value: 'some-uri' | ||
}); | ||
sinon.assert.called(resolveLocalFileSystemURL); | ||
}); | ||
}); | ||
|
||
it('should return a base64 data-uri when not a local file', function() { | ||
// replace cordova file function to call error callback | ||
const failingResolveLocalFileSystemURL = sinon.stub().callsArg(2); | ||
global.window.resolveLocalFileSystemURL = failingResolveLocalFileSystemURL; | ||
|
||
return subject.capture().then(result => { | ||
sinon.assert.called(failingResolveLocalFileSystemURL); | ||
expect(result).to.deep.equal({ | ||
value: 'data:image/jpg;base64,some-uri', | ||
type: 'base64' | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { expect } from 'chai'; | ||
import { buildCameraOptions } from '../src/buildCameraOptions'; | ||
import { mockCordovaCamera } from './mocks/camera'; | ||
|
||
describe('buildCameraOptions', function() { | ||
it('should accept a given camera object', function() { | ||
return expect(buildCameraOptions(mockCordovaCamera)).to.be.ok; | ||
}); | ||
it('should return a configuration object', function() { | ||
const opts = buildCameraOptions(mockCordovaCamera); | ||
expect(opts).to.have.property('quality'); | ||
expect(opts).to.have.property('sourceType'); | ||
expect(opts).to.have.property('destinationType'); | ||
expect(opts).to.have.property('encodingType'); | ||
expect(opts).to.have.property('mediaType'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="mocha" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { stub } from 'sinon'; | ||
export const mockCordovaCamera = { | ||
// properties | ||
DestinationType: { | ||
FILE_URI: 1 | ||
}, | ||
EncodingType: { | ||
JPEG: 1 | ||
}, | ||
PictureSourceType: { | ||
CAMERA: 1 | ||
}, | ||
MediaType: { | ||
PICTURE: 1 | ||
}, | ||
// methods | ||
cleanup: stub().callsArgAsync(0), | ||
getPicture: stub().callsArgWithAsync(0, 'some-uri') | ||
}; | ||
|
||
declare var global: any; | ||
global.window = global.window || {}; | ||
global.navigator = global.navigator || {}; | ||
global.window.navigator = global.navigator; | ||
|
||
global.window.camera = mockCordovaCamera; | ||
global.navigator.camera = mockCordovaCamera; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { stub } from 'sinon'; | ||
declare var global: any; | ||
|
||
export const resolveLocalFileSystemURL = stub().callsArgAsync(1); | ||
|
||
global.window = global.window || {}; | ||
global.window.resolveLocalFileSystemURL = resolveLocalFileSystemURL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters