Skip to content

Commit

Permalink
[TIMOB-25259] Add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Mathews committed Jan 24, 2018
1 parent 524baa0 commit 03c64da
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/Resources/ti.media.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2017 Axway, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* eslint-env mocha */
/* global Ti */
/* eslint no-unused-expressions: "off" */
'use strict';
var should = require('./utilities/assertions'),
utilities = require('./utilities/utilities');

describe('Titanium.Media', function () {

it('apiName', function () {
var media = Ti.Media;
should(media).have.readOnlyProperty('apiName').which.is.a.String;
should(media.apiName).be.eql('Ti.Media');
});

it('takeScreenshot', function (finish) {
should(Ti.Media.takeScreenshot).not.be.undefined;
should(Ti.Media.takeScreenshot).be.a.Function;

// take a screenshot
Ti.Media.takeScreenshot(function (image) {
if (image && image.media) {
finish();
} else {
finish(new Error('failed to obtain screenshot'));
}
});
});

it.android('previewImage', function () {
should(Ti.Media.previewImage).not.be.undefined;
should(Ti.Media.previewImage).be.a.Function;
});

it.android('preview image read/write external storage', function (finish) {

// take a screenshot
Ti.Media.takeScreenshot(function (image) {
if (image && image.media) {
var tmp = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, 'temp.png');

// write to external storage
tmp.write(image.media);

// preview image from external storage
Ti.Media.previewImage({
success: function () {
finish();
},
error: function (e) {
finish(e);
},
image: tmp.read()
});
} else {
finish(new Error('failed to obtain screenshot'));
}
});
});
});

0 comments on commit 03c64da

Please sign in to comment.