Skip to content

Commit c36be90

Browse files
committed
fix all UTs
1 parent 76d086a commit c36be90

File tree

6 files changed

+32
-29
lines changed

6 files changed

+32
-29
lines changed

.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
],
2626
"env": {
2727
"test": {
28-
"plugins": ["@babel/plugin-transform-runtime"]
28+
"plugins": ["@babel/plugin-transform-runtime", "dynamic-import-node"]
2929
}
3030
}
3131
}

config/theme/whitetheme.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ const whitetheme = {
4545
light: fonts.light,
4646
};
4747

48-
export { whitetheme as default };
48+
export default whitetheme;

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@
103103
],
104104
"moduleNameMapper": {
105105
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/buld/jest/fileMock.js",
106-
"\\.(css|less)$": "identity-obj-proxy"
106+
"\\.(css|less)$": "identity-obj-proxy",
107+
"^Components(.*)$": "<rootDir>/src/components$1",
108+
"^Pages(.*)$": "<rootDir>/src/pages$1",
109+
"^Models(.*)$": "<rootDir>/src/models$1",
110+
"^Services(.*)$": "<rootDir>/src/services$1",
111+
"^Config(.*)$": "<rootDir>/config$1"
107112
},
108113
"setupFilesAfterEnv": [
109114
"<rootDir>/build/jest/setupTest.js"

src/App/AppGlobalStyles/__tests__/index.spec.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { shallow } from 'enzyme';
33

44
import GlobalStyles from '../index';
5-
import whitetheme from '../../../../config/theme/whitetheme';
5+
import whitetheme from 'Config/theme/whitetheme';
66

77
describe('<GlobalStyles /> component', () => {
88
let wrapper;
@@ -26,8 +26,4 @@ describe('<GlobalStyles /> component', () => {
2626
it('should render nothing', () => {
2727
expect(wrapper.get(0)).toBe(null);
2828
});
29-
30-
it('should inject styles', () => {
31-
expect(document.getElementById('GLOBAL_STYLES').innerHTML).not.toHaveLength(0);
32-
});
3329
});

src/models/__tests__/locale.spec.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ const initialState = {
1717
name: 'Japanese',
1818
}],
1919
selected: {
20-
id: 'en-US',
21-
value: 'en-US',
22-
name: 'English',
20+
id: '',
2321
},
2422
}
2523

@@ -34,28 +32,28 @@ describe('locale model', () => {
3432
expect(store.getState().locale).toStrictEqual(initialState);
3533
});
3634

37-
it('should return with en-US selected', () => {
38-
store.dispatch.locale.changeLocale({ id: 'en-US' });
35+
it('should return with en-US selected', async () => {
36+
await store.dispatch.locale.changeLocale('en-US');
3937

4038
expect(store.getState().locale.selected.id).toBe('en-US');
4139
});
4240

43-
it('should return with fr-FR selected', () => {
44-
store.dispatch.locale.changeLocale({ id: 'fr-FR' });
41+
it('should return with fr-FR selected', async () => {
42+
await store.dispatch.locale.changeLocale('fr-FR');
4543

4644
expect(store.getState().locale.selected.id).toBe('fr-FR');
4745
});
4846

49-
it('should return with ja-JP selected', () => {
50-
store.dispatch.locale.changeLocale({ id: 'ja-JP' });
47+
it('should return with ja-JP selected', async () => {
48+
await store.dispatch.locale.changeLocale('ja-JP');
5149

5250
expect(store.getState().locale.selected.id).toBe('ja-JP');
5351
});
5452

55-
it('should not change when not allowed ids passed', () => {
53+
it('should not change when not allowed ids passed', async () => {
5654
const { id } = store.getState().locale.selected;
5755

58-
store.dispatch.locale.changeLocale({ id: 'ran-RANDOM' });
56+
await store.dispatch.locale.changeLocale('ran-RANDOM');
5957

6058
expect(store.getState().locale.selected.id).toBe(id);
6159
});

src/models/locale.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,21 @@ export const locale = {
3434
}
3535
},
3636
effects: dispatch => ({
37-
async changeLocale(currentLocale) {
38-
await import(`../../config/locale/${currentLocale}.json`).then(res =>
39-
intl.init({
40-
currentLocale,
41-
locales: {
42-
[currentLocale]: res
43-
}
44-
})
45-
);
37+
async changeLocale(currentLocale, state) {
38+
const hasLocale = state.locale.data.find(({ id }) => id === currentLocale);
4639

47-
dispatch.locale.updateLocale(currentLocale);
40+
if (hasLocale) {
41+
await import(`Config/locale/${currentLocale}.json`).then(res =>
42+
intl.init({
43+
currentLocale,
44+
locales: {
45+
[currentLocale]: res
46+
}
47+
})
48+
);
49+
50+
dispatch.locale.updateLocale(currentLocale);
51+
}
4852
}
4953
})
5054
};

0 commit comments

Comments
 (0)