Skip to content

Commit 2c769d1

Browse files
committed
test(system): add cases
1 parent 6475e44 commit 2c769d1

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

jest.setup.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
jest.mock('@/i18n', () => ({
22
t: (v) => v,
3+
changeLanguage: () => {},
34
}));

src/plugins/storage.ts

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ interface IStorage {
1010

1111
class Storage implements IStorage {
1212
setLanguage(language: EnumLanguage) {
13-
console.log('set lss lang', language);
1413
return Storage.set('language', language);
1514
}
1615

src/store/sagas/auth.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ describe('Auth saga flow', () => {
7171
};
7272

7373
return expectSaga(watchAuth, authService)
74+
.provide([
75+
[matchers.apply.fn(storage.setToken), undefined],
76+
[matchers.apply.fn(storage.setRefreshToken), undefined],
77+
])
7478
.dispatch(AuthActions.setAuthInfo(actionPayload))
7579
.call(storage.setToken, actionPayload.token)
7680
.call(storage.setRefreshToken, actionPayload.refreshToken)

src/store/sagas/system.spec.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { expectSaga } from 'redux-saga-test-plan';
2+
import * as matchers from 'redux-saga-test-plan/matchers';
3+
4+
import { watchSystem } from '@store/sagas/system';
5+
import { SystemActions } from '@store/actions';
6+
import { EnumLanguage } from '@type/entities';
7+
import i18n from '@/i18n';
8+
import { storage } from '@plugins/storage';
9+
import { LANGUAGE_CODES } from '@/constants';
10+
11+
describe('System saga flow', () => {
12+
it('set language', () => {
13+
const mockData = EnumLanguage.French;
14+
15+
return expectSaga(watchSystem)
16+
.provide([
17+
[matchers.apply.fn(storage.setLanguage), {
18+
data: mockData,
19+
}],
20+
])
21+
.dispatch(SystemActions.setLanguage(mockData))
22+
.apply(i18n, i18n.changeLanguage, [LANGUAGE_CODES[mockData]])
23+
.apply(storage, storage.setLanguage, [mockData])
24+
.silentRun();
25+
});
26+
it('fetch language', () => {
27+
const mockData = EnumLanguage.French;
28+
29+
return expectSaga(watchSystem)
30+
.provide([
31+
[matchers.apply.fn(storage.getLanguage), mockData],
32+
])
33+
.dispatch(SystemActions.fetchLanguage())
34+
.put(SystemActions.setLanguage(mockData))
35+
.silentRun();
36+
});
37+
});

0 commit comments

Comments
 (0)