From 8766b308ee1ea82553f29859e86d0e102a9f9f67 Mon Sep 17 00:00:00 2001 From: Arthi-chaud Date: Fri, 12 Aug 2022 11:11:57 +0200 Subject: [PATCH] Front: i18n: Tests translation and action dispatch --- front/package.json | 2 ++ front/views/AuthenticationView.test.tsx | 20 +++++++++---- front/views/HomeView.test.tsx | 19 ++++++++++--- front/yarn.lock | 38 ++++++++++++++++++++++++- node_modules/.yarn-integrity | 12 ++++++++ 5 files changed, 81 insertions(+), 10 deletions(-) create mode 100644 node_modules/.yarn-integrity diff --git a/front/package.json b/front/package.json index 01fb05e..a5dad4f 100644 --- a/front/package.json +++ b/front/package.json @@ -33,12 +33,14 @@ "react-native-paper": "^4.12.2", "react-native-safe-area-context": "4.2.4", "react-native-screens": "~3.11.1", + "react-native-testing-library": "^6.0.0", "react-native-web": "0.17.7", "react-query": "^4.0.0", "react-redux": "^8.0.2" }, "devDependencies": { "@babel/core": "^7.12.9", + "@testing-library/react-native": "^11.0.0", "@types/react": "~17.0.21", "@types/react-native": "~0.66.13", "react-test-renderer": "17.0.2", diff --git a/front/views/AuthenticationView.test.tsx b/front/views/AuthenticationView.test.tsx index 56ea9ff..b51e380 100644 --- a/front/views/AuthenticationView.test.tsx +++ b/front/views/AuthenticationView.test.tsx @@ -1,13 +1,23 @@ import React from 'react'; import { Provider } from 'react-redux'; -import TestRenderer from 'react-test-renderer'; +import { fireEvent, render, screen } from '@testing-library/react-native'; import store from '../state/Store'; - import AuthenticationView from '../views/AuthenticationView'; +import { en, fr } from '../i18n/Translations'; +import { useLanguage } from '../state/LanguageSlice'; describe('', () => { - it('has 3 children', () => { - const tree = TestRenderer.create().toJSON(); - expect(tree.children.length).toBe(3); + const view = () => ; + + beforeEach(() => render(view())); + + it('has should display the text in default language', async () => { + expect((await screen.findAllByText(en.signinBtn)).length).toBe(1); + }); + + it('has should display the text in the new language', async () => { + store.dispatch(useLanguage('fr')); + screen.update(view()); + expect((await screen.findAllByText(fr.signinBtn)).length).toBe(1); }); }); \ No newline at end of file diff --git a/front/views/HomeView.test.tsx b/front/views/HomeView.test.tsx index d5558e4..bf0fe2c 100644 --- a/front/views/HomeView.test.tsx +++ b/front/views/HomeView.test.tsx @@ -1,13 +1,24 @@ import React from 'react'; import { Provider } from 'react-redux'; -import TestRenderer from 'react-test-renderer'; import store from '../state/Store'; +import { fireEvent, render, screen } from '@testing-library/react-native'; import HomeView from '../views/HomeView'; +import { en, fr } from '../i18n/Translations'; describe('', () => { - it('has 2 children', () => { - const tree = TestRenderer.create().toJSON(); - expect(tree.children.length).toBe(2); + const view = ; + + beforeEach(() => render(view)); + + it('has should display the text in default language', async () => { + expect((await screen.findAllByText(en.signoutBtn)).length).toBe(1); + }); + + it('has should display the text in the new language', async () => { + fireEvent.press(screen.getByText('Change language')); + expect(store.getState().language.value).toBe('fr'); + screen.update(view); + expect((await screen.findAllByText(fr.signoutBtn)).length).toBe(1); }); }); diff --git a/front/yarn.lock b/front/yarn.lock index e006fc9..1d3780c 100644 --- a/front/yarn.lock +++ b/front/yarn.lock @@ -1571,6 +1571,13 @@ dependencies: "@sinclair/typebox" "^0.23.3" +"@jest/schemas@^28.1.3": + version "28.1.3" + resolved "https://registry.yarnpkg.com/@jest/schemas/-/schemas-28.1.3.tgz#ad8b86a66f11f33619e3d7e1dcddd7f2d40ff905" + integrity sha512-/l/VWsdt/aBXgjshLWOFyFt3IVdYypu5y2Wn2rOO1un6nkqIn8SLXzgIMYXFyYsRWDyF5EthmKJMIdJvk08grg== + dependencies: + "@sinclair/typebox" "^0.24.1" + "@jest/source-map@^26.6.2": version "26.6.2" resolved "https://registry.yarnpkg.com/@jest/source-map/-/source-map-26.6.2.tgz#29af5e1e2e324cafccc936f218309f54ab69d535" @@ -1996,6 +2003,11 @@ resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.23.5.tgz#93f7b9f4e3285a7a9ade7557d9a8d36809cbc47d" integrity sha512-AFBVi/iT4g20DHoujvMH1aEDn8fGJh4xsRGCP6d8RpLPMqsNPvW01Jcn0QysXTsg++/xj25NmJsGyH9xug/wKg== +"@sinclair/typebox@^0.24.1": + version "0.24.27" + resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.24.27.tgz#d55643516a1546174e10da681a8aaa81e757452d" + integrity sha512-K7C7IlQ3zLePEZleUN21ceBA2aLcMnLHTLph8QWk1JK37L90obdpY+QGY8bXMKxf1ht1Z0MNewvXxWv0oGDYFg== + "@sinonjs/commons@^1.7.0": version "1.8.3" resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.8.3.tgz#3802ddd21a50a949b6721ddd72da36e67e7f1b2d" @@ -2015,6 +2027,13 @@ resolved "https://registry.yarnpkg.com/@tanstack/query-core/-/query-core-4.0.10.tgz#cae6f818006616dc72c95c863592f5f68b47548a" integrity sha512-9LsABpZXkWZHi4P1ozRETEDXQocLAxVzQaIhganxbNuz/uA3PsCAJxJTiQrknG5htLMzOF5MqM9G10e6DCxV1A== +"@testing-library/react-native@^11.0.0": + version "11.0.0" + resolved "https://registry.yarnpkg.com/@testing-library/react-native/-/react-native-11.0.0.tgz#604cd14a42331ce01f2b3695aeb9abf73940183b" + integrity sha512-2WZF8P8YYXO5Ka1yzj3TZUg4x6noKU5RuCpx4oAhKBkxkVbrRl1pMCvRIozdTPSiru4rNBmAi074ZJjm2OED5g== + dependencies: + pretty-format "^28.1.3" + "@tootallnate/once@1": version "1.1.2" resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82" @@ -6768,7 +6787,7 @@ pretty-bytes@5.6.0: resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-5.6.0.tgz#356256f643804773c82f64723fe78c92c62beaeb" integrity sha512-FFw039TmrBqFK8ma/7OL3sDz/VytdtJr044/QUJtH0wK9lb9jLq9tJyIxUwtQJHwar2BqtiA4iCWSwo9JLkzFg== -pretty-format@^26.5.2, pretty-format@^26.6.2: +pretty-format@^26.0.1, pretty-format@^26.5.2, pretty-format@^26.6.2: version "26.6.2" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-26.6.2.tgz#e35c2705f14cb7fe2fe94fa078345b444120fc93" integrity sha512-7AeGuCYNGmycyQbCqd/3PWH4eOoX/OiCa0uphp57NVTeAGdJGaAliecxwBDHYQCIvrW7aDBZCYeNTP/WX69mkg== @@ -6797,6 +6816,16 @@ pretty-format@^28.0.0, pretty-format@^28.1.1: ansi-styles "^5.0.0" react-is "^18.0.0" +pretty-format@^28.1.3: + version "28.1.3" + resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-28.1.3.tgz#c9fba8cedf99ce50963a11b27d982a9ae90970d5" + integrity sha512-8gFb/To0OmxHR9+ZTb14Df2vNxdGCX8g1xWGUTqUw5TiZvcQf5sHKObd5UcPyLLyowNwDAMTF3XWOG1B6mxl1Q== + dependencies: + "@jest/schemas" "^28.1.3" + ansi-regex "^5.0.1" + ansi-styles "^5.0.0" + react-is "^18.0.0" + process-nextick-args@~2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" @@ -7003,6 +7032,13 @@ react-native-screens@~3.11.1: react-freeze "^1.0.0" warn-once "^0.1.0" +react-native-testing-library@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/react-native-testing-library/-/react-native-testing-library-6.0.0.tgz#b6e1c2213008dc62bdf28bb1474dfaca9cece058" + integrity sha512-BobXLtlef+gklN6cl6oC20/rnW9lWGj7Yxzzn+fTb+9go0LnGGgJ8DNaJtuW5oS7pOkm1Wq+u+cypALyf32FjA== + dependencies: + pretty-format "^26.0.1" + react-native-web@0.17.7: version "0.17.7" resolved "https://registry.yarnpkg.com/react-native-web/-/react-native-web-0.17.7.tgz#038899dbc94467a0ca0be214b88a30e0c117b176" diff --git a/node_modules/.yarn-integrity b/node_modules/.yarn-integrity new file mode 100644 index 0000000..19ce570 --- /dev/null +++ b/node_modules/.yarn-integrity @@ -0,0 +1,12 @@ +{ + "systemParams": "linux-x64-108", + "modulesFolders": [ + "node_modules" + ], + "flags": [], + "linkedModules": [], + "topLevelPatterns": [], + "lockfileEntries": {}, + "files": [], + "artifacts": {} +} \ No newline at end of file