Skip to content

Commit

Permalink
fix(tests): move to getter/setter (#12441)
Browse files Browse the repository at this point in the history
* fix(tests): move to getter/setter

* fix

Co-authored-by: Christopher Williams <chris.a.williams@gmail.com>
  • Loading branch information
m1ga and sgtcoolguy authored Mar 25, 2022
1 parent e290733 commit 734c41b
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 122 deletions.
2 changes: 1 addition & 1 deletion tests/Resources/os.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('os', function () {

it('returns "LE" or "BE", value is consistent with Ti.Codec#getNativeByteOrder()', () => {
const byteOrder = os.endianness();
if (Ti.Codec.getNativeByteOrder() === Ti.Codec.BIG_ENDIAN) {
if (Ti.Codec.nativeByteOrder === Ti.Codec.BIG_ENDIAN) {
byteOrder.should.eql('BE');
} else {
byteOrder.should.eql('LE');
Expand Down
2 changes: 1 addition & 1 deletion tests/Resources/ti.buffer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ describe('Titanium.Buffer', function () {
start = 2;
}
should(buffer.length).eql(length);
should(buffer.byteOrder).eql(Ti.Codec.getNativeByteOrder());
should(buffer.byteOrder).eql(Ti.Codec.nativeByteOrder);
should(buffer[start + 1]).eql(97); // a
should(buffer[start + 3]).eql(112); // p
should(buffer[start + 5]).eql(112); // p
Expand Down
10 changes: 5 additions & 5 deletions tests/Resources/ti.codec.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ describe('Titanium.Codec', () => {
dest: buffer,
type: Ti.Codec.TYPE_LONG
});
if (Ti.Codec.getNativeByteOrder() == Ti.Codec.BIG_ENDIAN) { // eslint-disable-line eqeqeq
if (Ti.Codec.nativeByteOrder == Ti.Codec.BIG_ENDIAN) { // eslint-disable-line eqeqeq
for (i = 0; i < 3; i++) {
should(buffer[i]).eql(0);
}
Expand Down Expand Up @@ -546,13 +546,13 @@ describe('Titanium.Codec', () => {
});
});

describe('#getNativeByteOrder', () => {
it('is a Function', () => {
should(Ti.Codec.getNativeByteOrder).be.a.Function();
describe('#nativeByteOrder', () => {
it('is a getter', () => {
should(Ti.Codec).have.a.getter('nativeByteOrder');
});

it('returns one of [Ti.Codec.BIG_ENDIAN,Ti.Codec.LITTLE_ENDIAN]', () => {
should([ Ti.Codec.BIG_ENDIAN, Ti.Codec.LITTLE_ENDIAN ]).containEql(Ti.Codec.getNativeByteOrder());
should([ Ti.Codec.BIG_ENDIAN, Ti.Codec.LITTLE_ENDIAN ]).containEql(Ti.Codec.nativeByteOrder);
});
});

Expand Down
20 changes: 10 additions & 10 deletions tests/Resources/ti.locale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Global', () => {
describe('Titanium.Locale', () => {

// reset back to US english when done
after(() => Ti.Locale.setLanguage('en-US'));
after(() => Ti.Locale.language = 'en-US');

it('exists', () => {
should(Ti.Locale).not.be.undefined();
Expand Down Expand Up @@ -109,7 +109,7 @@ describe('Titanium.Locale', () => {
});

beforeEach(() => {
Ti.Locale.setLanguage('en-US');
Ti.Locale.language = 'en-US';
});

it('returns stored value for found key', () => {
Expand Down Expand Up @@ -137,14 +137,14 @@ describe('Titanium.Locale', () => {

// https://jira.appcelerator.org/browse/TIMOB-26651
it('handles locale/country specific languages (i.e. en-GB vs en-US)', () => {
Ti.Locale.setLanguage('en-GB');
Ti.Locale.language = 'en-GB';
should(Ti.Locale.getString('this_is_my_key')).eql('this is my en-GB value'); // This fails on Windows, gives 'this is my value'
should(L('this_is_my_key')).eql('this is my en-GB value'); // This fails on Windows, gives 'this is my value'
});

// and then this one fails because it's using en-GB strings after we tell it to be ja...
it('handles single segment language (i.e. ja)', () => {
Ti.Locale.setLanguage('ja');
Ti.Locale.language = 'ja';
should(Ti.Locale.getString('this_is_my_key')).eql('これは私の値です');
should(L('this_is_my_key')).eql('これは私の値です');
});
Expand Down Expand Up @@ -278,21 +278,21 @@ describe('Titanium.Locale', () => {
});
});

describe('#setLanguage(String)', () => {
it('is a Function', () => {
should(Ti.Locale.setLanguage).be.a.Function();
describe('#set language(String)', () => {
it('has a setter', () => {
should(Ti.Locale).have.a.setter('language');
});

it('changes .currentLanguage', () => {
Ti.Locale.setLanguage('fr');
Ti.Locale.language = 'fr';
should(Ti.Locale.currentLanguage).eql('fr');
});

// FIXME Get working on iOS, setLangauge doesn't seem to affect currentLocale
it.iosBroken('changes .currentLocale', () => {
Ti.Locale.setLanguage('en-GB');
Ti.Locale.language = 'en-GB';
should(Ti.Locale.currentLocale).eql('en-GB'); // iOS returns 'en-US'
Ti.Locale.setLanguage('fr');
Ti.Locale.language = 'fr';
should(Ti.Locale.currentLocale).eql('fr');
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Resources/ti.network.httpclient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ describe('Titanium.Network.HTTPClient', function () {
});
xhr.onload = function () {
try {
const allHeaders = xhr.getAllResponseHeaders();
const allHeaders = xhr.allResponseHeaders;
should(allHeaders.toLowerCase().indexOf('server:')).be.within(0, 1 / 0);
const header = xhr.getResponseHeader('Server');
should(header.length).be.greaterThan(0);
Expand Down
25 changes: 10 additions & 15 deletions tests/Resources/ti.ui.2dmatrix.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@
const should = require('./utilities/assertions');
const utilities = require('./utilities/utilities');

// FIXME: We're moving the name to Ti.UI.Matrix2D now!
describe('Titanium.UI.2DMatrix', function () {
describe('Titanium.UI.Matrix2D', function () {
it('apiName', function () {
const matrix = Ti.UI.create2DMatrix();
const matrix = Ti.UI.createMatrix2D();
should(matrix).have.readOnlyProperty('apiName').which.is.a.String();
if (utilities.isWindows()) {
should(matrix.apiName).be.eql('Ti.UI.Matrix2D');
} else {
should(matrix.apiName).be.eql('Ti.UI.2DMatrix');
}
should(matrix.apiName).be.eql('Ti.UI.Matrix2D');
});

it('#invert()', function () {
var matrix1 = Ti.UI.create2DMatrix();
var matrix2 = Ti.UI.create2DMatrix();
var matrix1 = Ti.UI.createMatrix2D();
var matrix2 = Ti.UI.createMatrix2D();
should(matrix1.invert()).be.an.Object();
matrix1 = matrix1.scale(2, 2);
should(matrix1.invert()).be.an.Object();
Expand All @@ -38,8 +33,8 @@ describe('Titanium.UI.2DMatrix', function () {
});

it('#multiply()', function () {
var matrix1 = Ti.UI.create2DMatrix();
var matrix2 = Ti.UI.create2DMatrix();
var matrix1 = Ti.UI.createMatrix2D();
var matrix2 = Ti.UI.createMatrix2D();
should(matrix1.multiply(matrix2)).be.an.Object();
should(matrix1.multiply(matrix1)).be.an.Object();
if (utilities.isAndroid()) {
Expand All @@ -60,7 +55,7 @@ describe('Titanium.UI.2DMatrix', function () {
});

it('#rotate()', function () {
var matrix1 = Ti.UI.create2DMatrix();
var matrix1 = Ti.UI.createMatrix2D();
should(matrix1.rotate(0)).be.an.Object();
should(matrix1.rotate(90)).be.an.Object();
should(matrix1.rotate(360)).be.an.Object();
Expand All @@ -70,14 +65,14 @@ describe('Titanium.UI.2DMatrix', function () {
});

it('#scale()', function () {
var matrix1 = Ti.UI.create2DMatrix();
var matrix1 = Ti.UI.createMatrix2D();
should(matrix1.scale(50, 50)).be.an.Object();
should(matrix1.scale(0, -1)).be.an.Object();
should(matrix1.scale(-100, -100)).be.an.Object();
});

it('#translate()', function () {
var matrix1 = Ti.UI.create2DMatrix();
var matrix1 = Ti.UI.createMatrix2D();
should(matrix1.translate(-1, 0)).be.an.Object();
should(matrix1.translate(50, 50)).be.an.Object();
should(matrix1.translate(0, -1)).be.an.Object();
Expand Down
48 changes: 24 additions & 24 deletions tests/Resources/ti.ui.clipboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('Titanium.UI.Clipboard', () => {

it('clears \'text\' data type', () => {
Ti.UI.Clipboard.clearData(); // delete all data
Ti.UI.Clipboard.setText('clearData');
Ti.UI.Clipboard.text = 'clearData';
should(Ti.UI.Clipboard.hasText()).be.true();
Ti.UI.Clipboard.clearData('text');
should(Ti.UI.Clipboard.hasText()).be.false();
Expand All @@ -78,7 +78,7 @@ describe('Titanium.UI.Clipboard', () => {

it('makes hasText() return false after being called', () => {
Ti.UI.Clipboard.clearData(); // delete all data
Ti.UI.Clipboard.setText('clearText');
Ti.UI.Clipboard.text = 'clearText';
should(Ti.UI.Clipboard.hasText()).be.true();
Ti.UI.Clipboard.clearText();
should(Ti.UI.Clipboard.hasText()).be.false();
Expand All @@ -100,7 +100,7 @@ describe('Titanium.UI.Clipboard', () => {

it.android('returns null for non-text data type on Android', () => {
Ti.UI.Clipboard.clearData(); // delete all data
Ti.UI.Clipboard.setText('hi');
Ti.UI.Clipboard.text = 'hi';
should(Ti.UI.Clipboard.getData('color')).be.null();
should(Ti.UI.Clipboard.getData('url')).be.null();
should(Ti.UI.Clipboard.getData('image')).be.null();
Expand Down Expand Up @@ -146,42 +146,42 @@ describe('Titanium.UI.Clipboard', () => {
});
});

describe('#getText()', () => {
it('is a Function', () => {
should(Ti.UI.Clipboard.getText).be.a.Function();
describe('#text', () => {
it('is a getter', () => {
should(Ti.UI.Clipboard).have.a.getter('text');
});

it('returns empty string with empty clipboard', () => {
Ti.UI.Clipboard.clearData(); // delete all data
// should(Ti.UI.Clipboard.getText()).eql(''); // FIXME: undefined on iOS
// should(Ti.UI.Clipboard.text).eql(''); // FIXME: undefined on iOS
});

it('returns given string after setText()', () => {
Ti.UI.Clipboard.clearData(); // delete all data
// should(Ti.UI.Clipboard.getText()).eql(''); // FIXME: undefined on iOS
Ti.UI.Clipboard.setText('setText');
should(Ti.UI.Clipboard.getText()).eql('setText');
// should(Ti.UI.Clipboard.text).eql(''); // FIXME: undefined on iOS
Ti.UI.Clipboard.text = 'setText';
should(Ti.UI.Clipboard.text).eql('setText');
});

it('returns given string after setData(\'text\')', () => {
Ti.UI.Clipboard.clearData(); // delete all data
// should(Ti.UI.Clipboard.getText()).eql(''); // FIXME: undefined on iOS
// should(Ti.UI.Clipboard.text).eql(''); // FIXME: undefined on iOS
Ti.UI.Clipboard.setData('text', 'setData');
should(Ti.UI.Clipboard.getText()).eql('setData');
should(Ti.UI.Clipboard.text).eql('setData');
});

it('returns given string after setData(\'text/plain\')', () => {
Ti.UI.Clipboard.clearData(); // delete all data
// should(Ti.UI.Clipboard.getText()).eql(''); // FIXME: undefined on iOS
// should(Ti.UI.Clipboard.text).eql(''); // FIXME: undefined on iOS
Ti.UI.Clipboard.setData('text/plain', 'setData');
should(Ti.UI.Clipboard.getText()).eql('setData');
should(Ti.UI.Clipboard.text).eql('setData');
});

it.ios('returns given string after setData(\'public.plain-text\')', () => {
Ti.UI.Clipboard.clearData(); // delete all data
// should(Ti.UI.Clipboard.getText()).eql(''); // FIXME: undefined on iOS
// should(Ti.UI.Clipboard.text).eql(''); // FIXME: undefined on iOS
Ti.UI.Clipboard.setData('public.plain-text', 'setData');
should(Ti.UI.Clipboard.getText()).eql('setData');
should(Ti.UI.Clipboard.text).eql('setData');
});
});

Expand Down Expand Up @@ -232,7 +232,7 @@ describe('Titanium.UI.Clipboard', () => {
should(Ti.UI.Clipboard.hasData()).be.false();
should(Ti.UI.Clipboard.hasData('text')).be.false();
should(Ti.UI.Clipboard.hasData('text/plain')).be.false();
Ti.UI.Clipboard.setText('hello there');
Ti.UI.Clipboard.text = 'hello there';
should(Ti.UI.Clipboard.hasData()).be.true();
should(Ti.UI.Clipboard.hasData('text')).be.true();
should(Ti.UI.Clipboard.hasData('text/plain')).be.true();
Expand All @@ -244,7 +244,7 @@ describe('Titanium.UI.Clipboard', () => {
should(Ti.UI.Clipboard.hasData('color')).be.false();
should(Ti.UI.Clipboard.hasData('image')).be.false();
should(Ti.UI.Clipboard.hasData('url')).be.false();
Ti.UI.Clipboard.setText('hello there');
Ti.UI.Clipboard.text = 'hello there';
should(Ti.UI.Clipboard.hasData()).be.true();
should(Ti.UI.Clipboard.hasData('text')).be.true();
should(Ti.UI.Clipboard.hasData('text/plain')).be.true();
Expand Down Expand Up @@ -294,7 +294,7 @@ describe('Titanium.UI.Clipboard', () => {
it('returns true after setText()', () => {
Ti.UI.Clipboard.clearData(); // delete all data
should(Ti.UI.Clipboard.hasText()).be.false();
Ti.UI.Clipboard.setText('I set it!');
Ti.UI.Clipboard.text = 'I set it!';
should(Ti.UI.Clipboard.hasText()).be.true();
});

Expand Down Expand Up @@ -437,7 +437,7 @@ describe('Titanium.UI.Clipboard', () => {

describe('#setText()', () => {
it('is a Function', () => {
should(Ti.UI.Clipboard.setText).be.a.Function();
should(Ti.UI.Clipboard).have.a.getter('text');
});
// TODO: Test with null/undefined/no arg
});
Expand All @@ -449,7 +449,7 @@ describe('Titanium.UI.Clipboard', () => {
should.not.exist(Ti.UI.Clipboard.getText());
Ti.UI.Clipboard.setText('hello');
should(Ti.UI.Clipboard.hasText()).be.true();
should(Ti.UI.Clipboard.getText()).eql('hello');
should(Ti.UI.Clipboard.text).eql('hello');
});

it.ios('Use of named clipboard in iOS', () => {
Expand All @@ -459,13 +459,13 @@ describe('Titanium.UI.Clipboard', () => {
});
should(clipboard1.name).eql('myClipboard');
clipboard1.setText('hello');
should(clipboard1.getText()).eql('hello');
should(clipboard1.text).eql('hello');

const clipboard2 = Ti.UI.createClipboard({
name: 'myClipboard'
});

should(clipboard2.getText()).eql('hello'); // same name, so shares the same text
should(clipboard2.text).eql('hello'); // same name, so shares the same text
});

it.ios('Use of unique named clipboard in iOS', () => {
Expand All @@ -477,7 +477,7 @@ describe('Titanium.UI.Clipboard', () => {
// Uses a GUID for name
should(clipboard.name).match(/[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}/);
should(clipboard.unique).be.true();
should(clipboard.getText()).eql('hello');
should(clipboard.text).eql('hello');
});
});
});
Loading

0 comments on commit 734c41b

Please sign in to comment.