Skip to content

Commit

Permalink
Merge pull request #28772 from owncloud/jstest-reduce-warnings
Browse files Browse the repository at this point in the history
Reduce JS test warnings
  • Loading branch information
Vincent Petry authored Aug 24, 2017
2 parents ad6e52c + 8586152 commit 37f9771
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/files/tests/js/fileUploadSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe('OC.Upload tests', function() {
'<input type="checkbox" id="select_all_files" class="select-all">' +
'<a class="name columntitle" data-sort="name"><span>Name</span><span class="sort-indicator"></span></a>' +
'<span id="selectedActionsList" class="selectedActions hidden">' +
'<a href class="download"><img src="actions/download.svg">Download</a>' +
'<a href class="download"><img/>Download</a>' +
'<a href class="delete-selected">Delete</a></span>' +
'</th>' +
'<th class="hidden column-size"><a class="columntitle" data-sort="size"><span class="sort-indicator"></span></a></th>' +
Expand Down
2 changes: 1 addition & 1 deletion apps/files/tests/js/filelistSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('OCA.Files.FileList tests', function() {
'<input type="checkbox" id="select_all_files" class="select-all checkbox">' +
'<a class="name columntitle" data-sort="name"><span>Name</span><span class="sort-indicator"></span></a>' +
'<span id="selectedActionsList" class="selectedActions hidden">' +
'<a href class="download"><img src="actions/download.svg">Download</a>' +
'<a href class="download"><img/>Download</a>' +
'<a href class="delete-selected">Delete</a></span>' +
'</th>' +
'<th class="hidden column-size"><a class="columntitle" data-sort="size"><span class="sort-indicator"></span></a></th>' +
Expand Down
1 change: 1 addition & 0 deletions core/js/tests/specHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ window.isPhantom = /phantom/i.test(navigator.userAgent);
// reset pop state handlers
OC.Util.History._handlers = [];

$(window).off('beforeunload');
});
})();

5 changes: 5 additions & 0 deletions core/js/tests/specs/coreSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,12 @@ describe('Core base tests', function() {
var $rows = $el.find('.row');
expect($rows.length).toEqual(2);

// when called without arguments, a warning to be logged
// to ask devs to adjust their usage of the API.
// we stub it to avoid polluting the actual console
var warnStub = sinon.stub(console, 'warn');
OC.Notification.hide();
warnStub.restore();

$rows = $el.find('.row');
expect($rows.length).toEqual(1);
Expand Down
20 changes: 16 additions & 4 deletions core/js/tests/specs/l10nSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* See the COPYING-README file.
*
*/

describe('OC.L10N tests', function() {
var TEST_APP = 'jsunittestapp';

Expand All @@ -25,7 +24,7 @@ describe('OC.L10N tests', function() {
'Hello world!': 'Hallo Welt!',
'Hello {name}, the weather is {weather}': 'Hallo {name}, das Wetter ist {weather}',
'sunny': 'sonnig'
});
}, 'nplurals=2; plural=(n != 1);');
});
it('returns untranslated text when no bundle exists', function() {
delete OC.L10N._bundles[TEST_APP];
Expand Down Expand Up @@ -56,12 +55,21 @@ describe('OC.L10N tests', function() {
OC.L10N.register(TEST_APP, {
'sunny': 'sonnig',
'new': 'neu'
});
}, 'nplurals=2; plural=(n != 1);');
expect(t(TEST_APP, 'sunny')).toEqual('sonnig');
expect(t(TEST_APP, 'new')).toEqual('neu');
});
});
describe('plurals', function() {
var warnStub;

beforeEach(function() {
warnStub = sinon.stub(console, 'warn');
});
afterEach(function() {
warnStub.restore();
});

function checkPlurals() {
expect(
n(TEST_APP, 'download %n file', 'download %n files', 0)
Expand All @@ -80,6 +88,7 @@ describe('OC.L10N tests', function() {
it('generates plural for default text when translation does not exist', function() {
OC.L10N.register(TEST_APP, {
});
expect(warnStub.called).toEqual(true);
expect(
n(TEST_APP, 'download %n file', 'download %n files', 0)
).toEqual('download 0 files');
Expand All @@ -98,13 +107,15 @@ describe('OC.L10N tests', function() {
'_download %n file_::_download %n files_':
['%n Datei herunterladen', '%n Dateien herunterladen']
});
expect(warnStub.called).toEqual(true);
checkPlurals();
});
it('generates plural with generated function when forms is specified', function() {
OC.L10N.register(TEST_APP, {
'_download %n file_::_download %n files_':
['%n Datei herunterladen', '%n Dateien herunterladen']
}, 'nplurals=2; plural=(n != 1);');
expect(warnStub.notCalled).toEqual(true);
checkPlurals();
});
it('generates plural with function when forms is specified as function', function() {
Expand All @@ -117,6 +128,7 @@ describe('OC.L10N tests', function() {
plural: (n !== 1) ? 1 : 0
};
});
expect(warnStub.notCalled).toEqual(true);
checkPlurals();
});
});
Expand Down Expand Up @@ -152,7 +164,7 @@ describe('OC.L10N tests', function() {
var callbackStub = sinon.stub();
OC.L10N.register(TEST_APP, {
'Hello world!': 'Hallo Welt!'
});
}, 'nplurals=2; plural=(n != 1);');
OC.L10N.load(TEST_APP, callbackStub).then(promiseStub);
expect(callbackStub.calledOnce).toEqual(true);
expect(promiseStub.calledOnce).toEqual(true);
Expand Down

0 comments on commit 37f9771

Please sign in to comment.