@ngneat/transloco
Version:
The internationalization (i18n) library for Angular
99 lines • 5.83 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 en_1 = require("./mocks/en");
const es_1 = require("./mocks/es");
const scope_en_1 = require("./mocks/scope-en");
const scope_es_1 = require("./mocks/scope-es");
const collectionPath = path.join(__dirname, '../collection.json');
describe('Join', () => {
const schematicRunner = new testing_1.SchematicTestRunner('schematics', collectionPath);
let appTree;
const options = {
translationPath: 'src/assets/i18n',
outDir: 'dist-i18n'
};
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
appTree = yield create_workspace_1.createWorkspace(schematicRunner, appTree);
appTree.create('src/assets/i18n/es.json', JSON.stringify(es_1.default));
appTree.create('src/assets/i18n/en.json', JSON.stringify(en_1.default));
}));
describe('default strategy', () => {
beforeEach(() => {
appTree.create('src/assets/i18n/scope/en.json', JSON.stringify(scope_en_1.default));
appTree.create('src/assets/i18n/scope/es.json', JSON.stringify(scope_es_1.default));
});
it('should merge translation files to dist', () => __awaiter(void 0, void 0, void 0, function* () {
const tree = yield schematicRunner.runSchematicAsync('join', options, appTree).toPromise();
expect(tree.files).toEqual(['/dist-i18n/es.json', '/dist-i18n/en.json']);
}));
it('should merge scopes correctly', () => __awaiter(void 0, void 0, void 0, function* () {
const tree = yield schematicRunner.runSchematicAsync('build', options, appTree).toPromise();
expect(tree.readContent('/dist-i18n/es.json')).toMatchSnapshot();
expect(tree.readContent('/dist-i18n/en.json')).toMatchSnapshot();
}));
it('should delete output files on rerun', () => __awaiter(void 0, void 0, void 0, function* () {
yield schematicRunner.runSchematicAsync('build', options, appTree).toPromise();
const tree = yield schematicRunner.runSchematicAsync('build', options, appTree).toPromise();
expect(tree.files).toEqual(['/dist-i18n/es.json', '/dist-i18n/en.json']);
}));
it('should take default path', () => __awaiter(void 0, void 0, void 0, function* () {
const tree = yield schematicRunner.runSchematicAsync('build', {}, appTree).toPromise();
expect(tree.files).toEqual(['/dist-i18n/es.json', '/dist-i18n/en.json']);
}));
it('should take default project path', () => __awaiter(void 0, void 0, void 0, function* () {
const tree = yield schematicRunner.runSchematicAsync('build', { project: 'bar' }, appTree).toPromise();
expect(tree.files).toEqual(['/dist-i18n/es.json', '/dist-i18n/en.json']);
}));
});
describe('scope map strategy', () => {
function setup(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* () {
setup();
const tree = yield schematicRunner.runSchematicAsync('build', options, appTree).toPromise();
expect(tree.readContent('/dist-i18n/es.json')).toMatchSnapshot();
expect(tree.readContent('/dist-i18n/en.json')).toMatchSnapshot();
}));
it('should use scope map strategy multi scopes', () => __awaiter(void 0, void 0, void 0, function* () {
const scopePathMap = {
scopeA: 'src/app/i18n/scope1',
scopeB: 'src/app/i18n/scope2'
};
setup(scopePathMap);
const tree = yield schematicRunner.runSchematicAsync('build', options, appTree).toPromise();
expect(tree.readContent('/dist-i18n/es.json')).toMatchSnapshot();
expect(tree.readContent('/dist-i18n/en.json')).toMatchSnapshot();
}));
it('should use multi projects scopes', () => __awaiter(void 0, void 0, void 0, function* () {
const scopePathMap = {
libA: 'projects/bar/assets/i18n',
libB: 'projects/baz/assets/i18n'
};
setup(scopePathMap);
const tree = yield schematicRunner.runSchematicAsync('build', options, appTree).toPromise();
expect(tree.readContent('/dist-i18n/es.json')).toMatchSnapshot();
expect(tree.readContent('/dist-i18n/en.json')).toMatchSnapshot();
}));
});
});
//# sourceMappingURL=join.spec.js.map