@ngneat/transloco
Version:
The internationalization (i18n) library for Angular
82 lines • 4.84 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const testing_1 = require("@angular-devkit/schematics/testing");
var mock = jest.mock;
mock('@ngneat/transloco-utils');
const transloco_utils_1 = require("@ngneat/transloco-utils");
const path = require("path");
const create_workspace_1 = require("../utils/create-workspace");
const scope_en_1 = require("./mocks/scope-en");
const scope_es_1 = require("./mocks/scope-es");
const collectionPath = path.join(__dirname, '../collection.json');
describe('Split', () => {
const schematicRunner = new testing_1.SchematicTestRunner('schematics', collectionPath);
let appTree;
const options = {
translationPath: 'src/assets/i18n',
source: 'dist-i18n'
};
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
appTree = yield create_workspace_1.createWorkspace(schematicRunner, appTree);
}));
function setupMerged(enScopeMock, esScopeMock) {
appTree.create(`${options.source}/es.json`, JSON.stringify(esScopeMock));
appTree.create(`${options.source}/en.json`, JSON.stringify(enScopeMock));
}
describe('default strategy', () => {
it('should spill translated root content', () => __awaiter(void 0, void 0, void 0, function* () {
const translatedEn = { hello: 'hello translated' };
const translatedEs = { hello: 'hola translated' };
setupMerged(translatedEn, translatedEs);
appTree.create(`${options.translationPath}/en.json`, '');
appTree.create(`${options.translationPath}/es.json`, '');
const tree = yield schematicRunner.runSchematicAsync('split', options, appTree).toPromise();
const resES = JSON.parse(tree.readContent(`${options.translationPath}/es.json`));
const resEn = JSON.parse(tree.readContent(`${options.translationPath}/en.json`));
expect(resES).toEqual(translatedEs);
expect(resEn).toEqual(translatedEn);
}));
it('should spill translated scope content', () => __awaiter(void 0, void 0, void 0, function* () {
const translatedEn = { scope: { hello: 'hello translated' } };
const translatedEs = { scope: { hello: 'hola translated' } };
setupMerged(translatedEn, translatedEs);
appTree.create(`${options.translationPath}/scope/en.json`, '');
appTree.create(`${options.translationPath}/scope/es.json`, '');
const tree = yield schematicRunner.runSchematicAsync('spill', options, appTree).toPromise();
const resES = JSON.parse(tree.readContent(`${options.translationPath}/scope/es.json`));
const resEn = JSON.parse(tree.readContent(`${options.translationPath}/scope/en.json`));
expect(resES).toEqual(translatedEs.scope);
expect(resEn).toEqual(translatedEn.scope);
}));
});
describe('scope map strategy', () => {
function setupFiles(scopePathMap = { scope: 'src/app/i18n' }) {
Object.values(scopePathMap).forEach(path => {
appTree.create(`${path}/en.json`, JSON.stringify(scope_en_1.default));
appTree.create(`${path}/es.json`, JSON.stringify(scope_es_1.default));
});
transloco_utils_1.getConfig.mockImplementation(() => ({ scopePathMap }));
}
it('should use scope map strategy', () => __awaiter(void 0, void 0, void 0, function* () {
const translatedEn = { scope: { hello: 'hello translated' } };
const translatedEs = { scope: { hello: 'hola translated' } };
setupMerged(translatedEn, translatedEs);
setupFiles({ scope: 'src/app/i18n' });
const tree = yield schematicRunner.runSchematicAsync('spill', options, appTree).toPromise();
const resES = JSON.parse(tree.readContent('src/app/i18n/es.json'));
const resEn = JSON.parse(tree.readContent('src/app/i18n/en.json'));
expect(resES).toEqual(translatedEs.scope);
expect(resEn).toEqual(translatedEn.scope);
}));
});
});
//# sourceMappingURL=split.spec.js.map