Skip to content

Commit

Permalink
feat(name): introduces lastName module
Browse files Browse the repository at this point in the history
+ Add lastName module
+ Move firstName tests to its own module folder
+ Add JA locale support
  • Loading branch information
samir-araujo committed Apr 3, 2020
1 parent 34765b8 commit 61dfba8
Show file tree
Hide file tree
Showing 13 changed files with 619 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/name/__tests__/name.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import name from '..';

describe('Name', () => {
it('has firstName module', () => {
it('should have firstName module', () => {
expect(name).toHaveProperty('firstName');
});

it('should have lastName module', () => {
expect(name).toHaveProperty('lastName');
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Locale } from '../../types/locale';
import firstName from '../firstName';
import locales from '../firstName/locales';
import { Locale } from '../../../types/locale';
import firstName from '..';
import locales from '../locales';

describe('Name | firstName', () => {
it('returns a random first name', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/name/firstName/locales/__tests__/locales.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ describe('Name | firstName | Locales', () => {
it('has pt_BR', () => {
expect(locales).toHaveProperty('pt_BR');
});

it('has ja', () => {
expect(locales).toHaveProperty('ja');
});
});
3 changes: 2 additions & 1 deletion src/name/firstName/locales/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { LocaleObject } from '../../../types/locale';
import en from './en/collection';
import ja from './ja/collection';
import pt_BR from './pt_BR/collection';

const locales: LocaleObject<string[]> = { en, pt_BR };
const locales: LocaleObject<string[]> = { en, ja, pt_BR };

export default locales;
23 changes: 23 additions & 0 deletions src/name/firstName/locales/ja/collection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default [
'大和',
'大翔',
'太一',
'心愛',
'愛菜',
'杏',
'樹',
'海翔',
'結愛',
'結菜',
'結衣',
'美咲',
'美羽',
'翼',
'莉子',
'蒼空',
'蓮',
'陸斗',
'陽翔',
'陽菜',
'颯太',
];
3 changes: 2 additions & 1 deletion src/name/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import firstName from './firstName';
import lastName from './lastName';

export default { firstName };
export default { firstName, lastName };
26 changes: 26 additions & 0 deletions src/name/lastName/__tests__/lastName.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Locale } from '../../../types/locale';
import lastName from '..';
import locales from '../locales';

describe('Name | lastName', () => {
it('should return a random last name from given locale', () => {
const name = lastName(Locale.PT_BR);
const { pt_BR } = locales;

expect(pt_BR).toContain(name);
});

it(`should return a random last name in ${Locale.EN} by default`, () => {
const name = lastName();
const { en } = locales;

expect(en).toContain(name);
});

it(`should return a random last name in ${Locale.EN} when given locale is not found`, () => {
const name = lastName(Locale.RU);
const { en } = locales;

expect(en).toContain(name);
});
});
10 changes: 10 additions & 0 deletions src/name/lastName/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Locale } from '../../types/locale';
import getLocale from '../../helpers/getLocale';
import locales from './locales';
import randomArrayElement from '../../helpers/randomArrayElement';

export default function lastName(selectedLocale?: Locale) {
const collection = getLocale(locales, selectedLocale);

return randomArrayElement(collection);
}
15 changes: 15 additions & 0 deletions src/name/lastName/locales/__tests__/locales.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import locales from '..';

describe('Name | lastName | Locales', () => {
it('should have en locale', () => {
expect(locales).toHaveProperty('en');
});

it('should have pt_BR locale', () => {
expect(locales).toHaveProperty('pt_BR');
});

it('should have ja locale', () => {
expect(locales).toHaveProperty('ja');
});
});
Loading

0 comments on commit 61dfba8

Please sign in to comment.