Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
fix(test/refresh): fix current table refreshing test
Browse files Browse the repository at this point in the history
The old version of the test is not appropriate due to logical errors. Test was build to work with
en_EN language while de_DE was specified, so no changes were actually done to the current
translation table. The test is extended to check that old translation keys are deleted and new
translation keys are added by the refresh method.
  • Loading branch information
DWand authored and knalli committed Apr 22, 2015
1 parent 3facb92 commit a298ed8
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions test/unit/service/translate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1522,9 +1522,8 @@ describe('pascalprecht.translate', function () {

beforeEach(module('pascalprecht.translate', function ($translateProvider, $provide) {
$translateProvider
.translations('de_DE', translationMock)
.translations('en_EN', translationMock)
.preferredLanguage('en_EN')
.fallbackLanguage('en_EN')
.useLoader('customLoader');

$provide.factory('customLoader', ['$q', '$timeout', function ($q, $timeout) {
Expand Down Expand Up @@ -1557,19 +1556,27 @@ describe('pascalprecht.translate', function () {
});

it('should refresh the translation table', function () {
var deferred = $q.defer(),
promise = deferred.promise,
value;
var oldvalue, newValue;

function fetchTranslation() {
$translate(['EXISTING_TRANSLATION_ID', 'FOO']).then(function (translations) {
oldValue = translations.EXISTING_TRANSLATION_ID;
newValue = translations.FOO;
});
$rootScope.$digest();
}

fetchTranslation();
expect(oldValue).toEqual('foo');
expect(newValue).toEqual('FOO'); // not found

promise.then(function (translation) {
value = translation;
});
$translate('EXISTING_TRANSLATION_ID').then(function (translationId) {
deferred.resolve(translationId);
});
$translate.refresh();
$timeout.flush();
expect(value).toEqual('EXISTING_TRANSLATION_ID');
$rootScope.$digest();

fetchTranslation();
expect(oldValue).toEqual('EXISTING_TRANSLATION_ID'); // not found
expect(newValue).toEqual('bar');
});

it('should emit $translateRefreshStart event', function () {
Expand Down

0 comments on commit a298ed8

Please sign in to comment.