diff options
Diffstat (limited to 'core/js/tests/specs/l10nSpec.js')
-rw-r--r-- | core/js/tests/specs/l10nSpec.js | 78 |
1 files changed, 10 insertions, 68 deletions
diff --git a/core/js/tests/specs/l10nSpec.js b/core/js/tests/specs/l10nSpec.js index 18c1adabea1..bd93a13fe74 100644 --- a/core/js/tests/specs/l10nSpec.js +++ b/core/js/tests/specs/l10nSpec.js @@ -1,22 +1,23 @@ /** - * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com> - * - * This file is licensed under the Affero General Public License version 3 - * or later. - * - * See the COPYING-README file. - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2014 ownCloud Inc. + * SPDX-License-Identifier: AGPL-3.0-or-later */ describe('OC.L10N tests', function() { var TEST_APP = 'jsunittestapp'; beforeEach(function() { - OC.appswebroots[TEST_APP] = OC.getRootPath() + '/apps3/jsunittestapp'; + window._oc_appswebroots[TEST_APP] = OC.getRootPath() + '/apps3/jsunittestapp'; + + window.OC = window.OC ?? {} + window.OC.appswebroots = window.OC.appswebroots || {} + window.OC.appswebroots[TEST_APP] = OC.getRootPath() + '/apps3/jsunittestapp' }); afterEach(function() { OC.L10N._unregister(TEST_APP); - delete OC.appswebroots[TEST_APP]; + delete window._oc_appswebroots[TEST_APP]; + delete window.OC.appswebroots[TEST_APP]; }); describe('text translation', function() { @@ -109,63 +110,4 @@ describe('OC.L10N tests', function() { checkPlurals(); }); }); - describe('async loading of translations', function() { - it('loads bundle for given app and calls callback', function(done) { - var localeStub = sinon.stub(OC, 'getLocale').returns('zh_CN'); - var callbackStub = sinon.stub(); - var promiseStub = sinon.stub(); - var loading = OC.L10N.load(TEST_APP, callbackStub); - expect(callbackStub.notCalled).toEqual(true); - var req = fakeServer.requests[0]; - - loading - .then(promiseStub) - .then(function() { - expect(fakeServer.requests.length).toEqual(1); - expect(req.url).toEqual( - OC.getRootPath() + '/apps3/' + TEST_APP + '/l10n/zh_CN.json' - ); - - expect(callbackStub.calledOnce).toEqual(true); - expect(promiseStub.calledOnce).toEqual(true); - expect(t(TEST_APP, 'Hello world!')).toEqual('你好世界!'); - localeStub.restore(); - }) - .then(done); - - expect(promiseStub.notCalled).toEqual(true); - req.respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify({ - translations: {'Hello world!': '你好世界!'}, - pluralForm: 'nplurals=2; plural=(n != 1);' - }) - ); - }); - it('calls callback if translation already available', function(done) { - var callbackStub = sinon.stub(); - spyOn(console, 'warn'); - OC.L10N.register(TEST_APP, { - 'Hello world!': 'Hallo Welt!' - }); - OC.L10N.load(TEST_APP, callbackStub) - .then(function() { - expect(callbackStub.calledOnce).toEqual(true); - expect(fakeServer.requests.length).toEqual(0); - }) - .then(done); - - }); - it('calls callback if locale is en', function(done) { - var callbackStub = sinon.stub(); - OC.L10N.load(TEST_APP, callbackStub) - .then(function() { - expect(callbackStub.calledOnce).toEqual(true); - expect(fakeServer.requests.length).toEqual(0); - }) - .then(done) - .catch(done); - }); - }); }); |