- (feat) add concept of post processors
- (feat) add 'key as default value' post processor (closes #109) - (chore) move clean functionality to a post processor - (chore) move sort functionality to a post processor - (refactor) get rid of leading underscore on protected properties/methods
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { expect } from 'chai';
|
||||
|
||||
import { PostProcessorInterface } from '../../src/post-processors/post-processor.interface';
|
||||
import { KeyAsDefaultValuePostProcessor } from '../../src/post-processors/key-as-default-value.post-processor';
|
||||
import { TranslationCollection } from '../../src/utils/translation.collection';
|
||||
|
||||
describe('KeyAsDefaultValuePostProcessor', () => {
|
||||
|
||||
let processor: PostProcessorInterface;
|
||||
|
||||
beforeEach(() => {
|
||||
processor = new KeyAsDefaultValuePostProcessor();
|
||||
});
|
||||
|
||||
it('should use key as default value', () => {
|
||||
const collection = new TranslationCollection({
|
||||
'I have no value': '',
|
||||
'I am already translated': 'Jeg er allerede oversat',
|
||||
'Use this key as value as well': ''
|
||||
});
|
||||
const extracted = new TranslationCollection();
|
||||
const existing = new TranslationCollection();
|
||||
|
||||
expect(processor.process(collection, extracted, existing).values).to.deep.equal({
|
||||
'I have no value': 'I have no value',
|
||||
'I am already translated': 'Jeg er allerede oversat',
|
||||
'Use this key as value as well': 'Use this key as value as well'
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,36 @@
|
||||
import { expect } from 'chai';
|
||||
|
||||
import { PostProcessorInterface } from '../../src/post-processors/post-processor.interface';
|
||||
import { PurgeObsoleteKeysPostProcessor } from '../../src/post-processors/purge-obsolete-keys.post-processor';
|
||||
import { TranslationCollection } from '../../src/utils/translation.collection';
|
||||
|
||||
describe('KeyAsDefaultValuePostProcessor', () => {
|
||||
|
||||
let processor: PostProcessorInterface;
|
||||
|
||||
beforeEach(() => {
|
||||
processor = new PurgeObsoleteKeysPostProcessor();
|
||||
});
|
||||
|
||||
it('should purge obsolete keys', () => {
|
||||
const collection = new TranslationCollection({
|
||||
'I am completely new': '',
|
||||
'I already exist': '',
|
||||
'I already exist but was not present in extract': ''
|
||||
});
|
||||
const extracted = new TranslationCollection({
|
||||
'I am completely new': '',
|
||||
'I already exist': ''
|
||||
});
|
||||
const existing = new TranslationCollection({
|
||||
'I already exist': '',
|
||||
'I already exist but was not present in extract': ''
|
||||
});
|
||||
|
||||
expect(processor.process(collection, extracted, existing).values).to.deep.equal({
|
||||
'I am completely new': '',
|
||||
'I already exist': ''
|
||||
});
|
||||
});
|
||||
|
||||
});
|
33
tests/post-processors/sort-by-key.post-processor.spec.ts
Normal file
33
tests/post-processors/sort-by-key.post-processor.spec.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { expect } from 'chai';
|
||||
|
||||
import { PostProcessorInterface } from '../../src/post-processors/post-processor.interface';
|
||||
import { SortByKeyPostProcessor } from '../../src/post-processors/sort-by-key.post-processor';
|
||||
import { TranslationCollection } from '../../src/utils/translation.collection';
|
||||
|
||||
describe('SortByKeyPostProcessor', () => {
|
||||
|
||||
let processor: PostProcessorInterface;
|
||||
|
||||
beforeEach(() => {
|
||||
processor = new SortByKeyPostProcessor();
|
||||
});
|
||||
|
||||
it('should sort keys alphanumerically', () => {
|
||||
const collection = new TranslationCollection({
|
||||
'z': 'last value',
|
||||
'a': 'a value',
|
||||
'9': 'a numeric key',
|
||||
'b': 'another value'
|
||||
});
|
||||
const extracted = new TranslationCollection();
|
||||
const existing = new TranslationCollection();
|
||||
|
||||
expect(processor.process(collection, extracted, existing).values).to.deep.equal({
|
||||
'9': 'a numeric key',
|
||||
'a': 'a value',
|
||||
'b': 'another value',
|
||||
'z': 'last value'
|
||||
});
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user