Add option to merge extracted strings with existing translations (Thanks to @ocombe)
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
import { expect } from 'chai';
|
||||
|
||||
import { StringCollection } from '../../src/utils/string.collection';
|
||||
|
||||
describe('StringCollection', () => {
|
||||
|
||||
let collection: StringCollection;
|
||||
|
||||
beforeEach(() => {
|
||||
collection = new StringCollection();
|
||||
});
|
||||
|
||||
it('should add item with value', () => {
|
||||
collection.add('key', 'translation');
|
||||
expect(collection.get('key')).to.equal('translation');
|
||||
});
|
||||
|
||||
it('should add item with default value', () => {
|
||||
collection.add('key');
|
||||
expect(collection.get('key')).to.equal('');
|
||||
});
|
||||
|
||||
it('should add array of items with default values', () => {
|
||||
collection.add(['key', 'key2']);
|
||||
expect(collection.count()).to.equal(2);
|
||||
});
|
||||
|
||||
it('should remove item', () => {
|
||||
collection.add('key1').add('key2').remove('key1');
|
||||
expect(collection.count()).to.equal(1);
|
||||
});
|
||||
|
||||
it('should return number of items', () => {
|
||||
collection.add('key1').add('key2');
|
||||
expect(collection.count()).to.equal(2);
|
||||
});
|
||||
|
||||
it('should initialize with array of keys', () => {
|
||||
const newCollection = StringCollection.fromArray(['Hello', 'World']);
|
||||
expect(newCollection.count()).to.equal(2);
|
||||
});
|
||||
|
||||
it('should initialize with key/value pairs', () => {
|
||||
const newCollection = StringCollection.fromObject({'key': 'translation'});
|
||||
expect(newCollection.get('key')).to.equal('translation');
|
||||
});
|
||||
|
||||
it('should merge with other collection', () => {
|
||||
collection.add('Hello');
|
||||
const newCollection = StringCollection.fromArray(['World']);
|
||||
expect(collection.merge(newCollection).count()).to.equal(2);
|
||||
});
|
||||
|
||||
});
|
82
tests/utils/translation.collection.spec.ts
Normal file
82
tests/utils/translation.collection.spec.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import { expect } from 'chai';
|
||||
|
||||
import { TranslationCollection } from '../../src/utils/translation.collection';
|
||||
|
||||
describe('StringCollection', () => {
|
||||
|
||||
let collection: TranslationCollection;
|
||||
|
||||
beforeEach(() => {
|
||||
collection = new TranslationCollection();
|
||||
});
|
||||
|
||||
it('should initialize with key/value pairs', () => {
|
||||
collection = new TranslationCollection({ key1: 'val1', key2: 'val2' });
|
||||
expect(collection.values).to.deep.equal({ key1: 'val1', key2: 'val2' });
|
||||
});
|
||||
|
||||
it('should add key with value', () => {
|
||||
const newCollection = collection.add('theKey', 'theVal');
|
||||
expect(newCollection.get('theKey')).to.equal('theVal');
|
||||
});
|
||||
|
||||
it('should add key with default value', () => {
|
||||
collection = collection.add('theKey');
|
||||
expect(collection.get('theKey')).to.equal('');
|
||||
});
|
||||
|
||||
it('should not mutate collection when adding key', () => {
|
||||
collection.add('theKey', 'theVal');
|
||||
expect(collection.has('theKey')).to.equal(false);
|
||||
});
|
||||
|
||||
it('should add array of keys with default value', () => {
|
||||
collection = collection.addKeys(['key1', 'key2']);
|
||||
expect(collection.values).to.deep.equal({ key1: '', key2: '' });
|
||||
});
|
||||
|
||||
it('should return true when collection has key', () => {
|
||||
collection = collection.add('key');
|
||||
expect(collection.has('key')).to.equal(true);
|
||||
});
|
||||
|
||||
it('should return false when collection does not have key', () => {
|
||||
expect(collection.has('key')).to.equal(false);
|
||||
});
|
||||
|
||||
it('should remove key', () => {
|
||||
collection = new TranslationCollection({ removeThisKey: '' });
|
||||
collection = collection.remove('removeThisKey');
|
||||
expect(collection.has('removeThisKey')).to.equal(false);
|
||||
});
|
||||
|
||||
it('should not mutate collection when removing key', () => {
|
||||
collection = new TranslationCollection({ removeThisKey: '' });
|
||||
collection.remove('removeThisKey');
|
||||
expect(collection.has('removeThisKey')).to.equal(true);
|
||||
});
|
||||
|
||||
it('should return number of keys', () => {
|
||||
collection = collection.addKeys(['key1', 'key2', 'key3']);
|
||||
expect(collection.count()).to.equal(3);
|
||||
});
|
||||
|
||||
it('should merge with other collection', () => {
|
||||
collection = collection.add('oldKey', 'oldVal');
|
||||
const newCollection = new TranslationCollection({ newKey: 'newVal' });
|
||||
expect(collection.union(newCollection).values).to.deep.equal({ oldKey: 'oldVal', newKey: 'newVal' });
|
||||
});
|
||||
|
||||
it('should intersect with passed collection', () => {
|
||||
collection = collection.addKeys(['red', 'green', 'blue']);
|
||||
const newCollection = new TranslationCollection( { red: '', blue: '' });
|
||||
expect(collection.intersect(newCollection).values).to.deep.equal({ red: '', blue: '' });
|
||||
});
|
||||
|
||||
it('should intersect with passed collection and keep original values', () => {
|
||||
collection = new TranslationCollection({ red: 'rød', blue: 'blå' });
|
||||
const newCollection = new TranslationCollection({ red: 'no value', blue: 'also no value' });
|
||||
expect(collection.intersect(newCollection).values).to.deep.equal({ red: 'rød', blue: 'blå' });
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user