|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import type { LocaleDefinition } from '../../src'; |
| 3 | +import { mergeLocales } from '../../src/utils/merge-locales'; |
| 4 | + |
| 5 | +describe('mergeLocales', () => { |
| 6 | + it('should not overwrite entries', () => { |
| 7 | + const locale1: LocaleDefinition = { |
| 8 | + title: 'a', |
| 9 | + person: { firstName: ['a'] }, |
| 10 | + finance: { credit_card: { visa: ['a'] } }, |
| 11 | + }; |
| 12 | + const locale2: LocaleDefinition = { |
| 13 | + title: 'b', |
| 14 | + person: { firstName: ['b'] }, |
| 15 | + finance: { credit_card: { mastercard: ['b'] } }, |
| 16 | + }; |
| 17 | + const locale3: LocaleDefinition = { |
| 18 | + title: 'c', |
| 19 | + person: { firstName: ['c'] }, |
| 20 | + finance: { credit_card: {} }, |
| 21 | + }; |
| 22 | + |
| 23 | + const merged = mergeLocales([locale1, locale2, locale3]); |
| 24 | + |
| 25 | + expect(merged).toEqual({ |
| 26 | + title: 'a', |
| 27 | + person: { firstName: ['a'] }, |
| 28 | + finance: { credit_card: { visa: ['a'] } }, |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should extend categories', () => { |
| 33 | + const locale1: LocaleDefinition = { |
| 34 | + title: 'a', |
| 35 | + location: { city: ['a'] }, |
| 36 | + person: { first_name: ['a'] }, |
| 37 | + }; |
| 38 | + const locale2: LocaleDefinition = { |
| 39 | + title: 'b', |
| 40 | + animal: { cat: ['b'] }, |
| 41 | + person: { last_name: ['b'] }, |
| 42 | + }; |
| 43 | + const locale3: LocaleDefinition = { |
| 44 | + title: 'c', |
| 45 | + color: { human: ['c'] }, |
| 46 | + person: {}, |
| 47 | + }; |
| 48 | + |
| 49 | + const merged = mergeLocales([locale1, locale2, locale3]); |
| 50 | + |
| 51 | + expect(merged).toEqual({ |
| 52 | + title: 'a', |
| 53 | + animal: { cat: ['b'] }, |
| 54 | + color: { human: ['c'] }, |
| 55 | + location: { city: ['a'] }, |
| 56 | + person: { first_name: ['a'], last_name: ['b'] }, |
| 57 | + }); |
| 58 | + }); |
| 59 | +}); |
0 commit comments