-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add profile slice, thunks, selectors tests
- Loading branch information
Showing
81 changed files
with
383 additions
and
4 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-16.5 KB
(44%)
.loki/reference/chrome_iphone7_pages_NotFoundPage_Normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-16.3 KB
(33%)
.loki/reference/chrome_iphone7_shared_AppLink_Primary_Dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-16.2 KB
(33%)
.loki/reference/chrome_iphone7_shared_AppLink_Secondary_Dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-16.4 KB
(32%)
.loki/reference/chrome_iphone7_shared_Button_Background_Inverted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-15.9 KB
(33%)
.loki/reference/chrome_iphone7_shared_Button_Background_Theme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-16 KB
(33%)
.loki/reference/chrome_iphone7_shared_Button_Clear_Inverted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-17.1 KB
(32%)
.loki/reference/chrome_iphone7_shared_Button_Outline_Dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-16.7 KB
(32%)
.loki/reference/chrome_iphone7_shared_Button_Outline_Size_L.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-16.7 KB
(32%)
.loki/reference/chrome_iphone7_shared_Button_Outline_Size_XL.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Binary file modified
BIN
-15.4 KB
(41%)
.loki/reference/chrome_iphone7_shared_ThemeSwitcher_Dark.png
Oops, something went wrong.
Binary file modified
BIN
-15.1 KB
(41%)
.loki/reference/chrome_iphone7_shared_ThemeSwitcher_Normal.png
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Diff not rendered.
Diff not rendered.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file modified
BIN
-9.58 KB
(39%)
.loki/reference/chrome_laptop_shared_AppLink_Primary_Dark.png
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file modified
BIN
-9.62 KB
(39%)
.loki/reference/chrome_laptop_shared_AppLink_Secondary_Dark.png
Oops, something went wrong.
Binary file modified
BIN
-9.91 KB
(39%)
.loki/reference/chrome_laptop_shared_Button_Background_Inverted.png
Oops, something went wrong.
Binary file modified
BIN
-9.71 KB
(39%)
.loki/reference/chrome_laptop_shared_Button_Background_Theme.png
Oops, something went wrong.
Oops, something went wrong.
Binary file modified
BIN
-9.71 KB
(39%)
.loki/reference/chrome_laptop_shared_Button_Clear_Inverted.png
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file modified
BIN
-10.2 KB
(38%)
.loki/reference/chrome_laptop_shared_Button_Outline_Size_L.png
Oops, something went wrong.
Binary file modified
BIN
-10.2 KB
(38%)
.loki/reference/chrome_laptop_shared_Button_Outline_Size_XL.png
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file modified
BIN
-9.22 KB
(46%)
.loki/reference/chrome_laptop_shared_ThemeSwitcher_Normal.png
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Diff not rendered.
Diff not rendered.
29 changes: 29 additions & 0 deletions
29
src/entities/Profile/model/selectors/getProfileData/getProfileData.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { StateSchema } from 'app/providers/StoreProvider'; | ||
import { Country } from 'entities/Country'; | ||
import { Currency } from 'entities/Currency'; | ||
import { getProfileData } from './getProfileData'; | ||
|
||
describe('getProfileData.test', () => { | ||
test('should get profile data', () => { | ||
const data = { | ||
username: 'test', | ||
first: 'test firstname', | ||
lastname: 'test lastname', | ||
age: 20, | ||
country: Country.Armenia, | ||
currency: Currency.EUR, | ||
avatar: 'https://pic.rutubelist.ru/user/3b/27/3b2758ad5492a76b578f7ee072e4e894.jpg', | ||
city: 'yaroslavl', | ||
}; | ||
const state: DeepPartial<StateSchema> = { | ||
profile: { | ||
data, | ||
}, | ||
}; | ||
expect(getProfileData(state as StateSchema)).toEqual(data); | ||
}); | ||
test('should work with empty state', () => { | ||
const state: DeepPartial<StateSchema> = {}; | ||
expect(getProfileData(state as StateSchema)).toEqual(undefined); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
src/entities/Profile/model/selectors/getProfileError/getProfileError.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { StateSchema } from 'app/providers/StoreProvider'; | ||
import { getProfileError } from './getProfileError'; | ||
|
||
describe('getProfileError.test', () => { | ||
test('should get profile error', () => { | ||
const state: DeepPartial<StateSchema> = { | ||
profile: { | ||
error: '123', | ||
}, | ||
}; | ||
expect(getProfileError(state as StateSchema)).toEqual('123'); | ||
}); | ||
test('should work with empty state', () => { | ||
const state: DeepPartial<StateSchema> = {}; | ||
expect(getProfileError(state as StateSchema)).toEqual(undefined); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
src/entities/Profile/model/selectors/getProfileForm/getProfileForm.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { StateSchema } from 'app/providers/StoreProvider'; | ||
import { Country } from 'entities/Country'; | ||
import { Currency } from 'entities/Currency'; | ||
import { getProfileForm } from './getProfileForm'; | ||
|
||
describe('getProfileForm.test', () => { | ||
test('should get profile form data', () => { | ||
const data = { | ||
username: 'test', | ||
first: 'test firstname', | ||
lastname: 'test lastname', | ||
age: 20, | ||
country: Country.Armenia, | ||
currency: Currency.EUR, | ||
avatar: | ||
'https://pic.rutubelist.ru/user/3b/27/3b2758ad5492a76b578f7ee072e4e894.jpg', | ||
city: 'yaroslavl', | ||
}; | ||
const state: DeepPartial<StateSchema> = { | ||
profile: { | ||
form: data, | ||
}, | ||
}; | ||
expect(getProfileForm(state as StateSchema)).toEqual(data); | ||
}); | ||
test('should work with empty state', () => { | ||
const state: DeepPartial<StateSchema> = {}; | ||
expect(getProfileForm(state as StateSchema)).toEqual(undefined); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
src/entities/Profile/model/selectors/getProfileIsLoading/getProfileisLoading.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { StateSchema } from 'app/providers/StoreProvider'; | ||
import { getProfileIsLoading } from './getProfileIsLoading'; | ||
|
||
describe('getProfileIsLoading.test', () => { | ||
test('should get profile isLoading', () => { | ||
const state: DeepPartial<StateSchema> = { | ||
profile: { | ||
isLoading: true, | ||
}, | ||
}; | ||
expect(getProfileIsLoading(state as StateSchema)).toEqual(true); | ||
}); | ||
test('should work with empty state', () => { | ||
const state: DeepPartial<StateSchema> = {}; | ||
expect(getProfileIsLoading(state as StateSchema)).toEqual(undefined); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
src/entities/Profile/model/selectors/getProfileReadonly/getProfileReadonly.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { StateSchema } from 'app/providers/StoreProvider'; | ||
import { getProfileReadonly } from './getProfileReadonly'; | ||
|
||
describe('getProfileIsLoading.test', () => { | ||
test('should get profile isLoading', () => { | ||
const state: DeepPartial<StateSchema> = { | ||
profile: { | ||
readonly: true, | ||
}, | ||
}; | ||
expect(getProfileReadonly(state as StateSchema)).toEqual(true); | ||
}); | ||
test('should work with empty state', () => { | ||
const state: DeepPartial<StateSchema> = {}; | ||
expect(getProfileReadonly(state as StateSchema)).toEqual(undefined); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
...ntities/Profile/model/selectors/getProfileValidateErrors/getProfileValidateErrors.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { StateSchema } from 'app/providers/StoreProvider'; | ||
import { ValidateProfileError } from '../../types/profile'; | ||
import { getProfileValidateErrors } from './getProfileValidateErrors'; | ||
|
||
describe('getProfileIsLoading.test', () => { | ||
test('should get profile isLoading', () => { | ||
const state: DeepPartial<StateSchema> = { | ||
profile: { | ||
validateErrors: [ | ||
ValidateProfileError.SERVER_ERROR, | ||
ValidateProfileError.INCORRECT_USER_DATA, | ||
], | ||
}, | ||
}; | ||
expect(getProfileValidateErrors(state as StateSchema)).toEqual([ | ||
ValidateProfileError.SERVER_ERROR, | ||
ValidateProfileError.INCORRECT_USER_DATA, | ||
]); | ||
}); | ||
test('should work with empty state', () => { | ||
const state: DeepPartial<StateSchema> = {}; | ||
expect(getProfileValidateErrors(state as StateSchema)).toEqual(undefined); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
src/entities/Profile/model/services/fetchProfileData/fetchProfileData.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { userActions } from 'entities/User'; | ||
import { TestAsyncThunk } from 'shared/lib/tests/TestAsyncThunk/TestAsyncThunk'; | ||
import { Country } from 'entities/Country'; | ||
import { Currency } from 'entities/Currency'; | ||
import { fetchProfileData } from './fetchProfileData'; | ||
|
||
const data = { | ||
username: 'test', | ||
first: 'test firstname', | ||
lastname: 'test lastname', | ||
age: 20, | ||
country: Country.Armenia, | ||
currency: Currency.EUR, | ||
avatar: 'https://pic.rutubelist.ru/user/3b/27/3b2758ad5492a76b578f7ee072e4e894.jpg', | ||
city: 'yaroslavl', | ||
}; | ||
|
||
describe('fetchProfileData.test', () => { | ||
test('fetchProfileData async thunk test', async () => { | ||
const thunk = new TestAsyncThunk(fetchProfileData); | ||
|
||
thunk.api.get.mockReturnValue(Promise.resolve({ data })); | ||
|
||
const result = await thunk.callThunk(); | ||
|
||
expect(thunk.api.get).toHaveBeenCalled(); | ||
expect(result.meta.requestStatus).toBe('fulfilled'); | ||
expect(result.payload).toEqual(data); | ||
}); | ||
|
||
test('fetchProfileData async error thunk test', async () => { | ||
const thunk = new TestAsyncThunk(fetchProfileData); | ||
thunk.api.get.mockReturnValue(Promise.resolve({ status: 403 })); | ||
|
||
const result = await thunk.callThunk(); | ||
|
||
expect(thunk.api.get).toHaveBeenCalled(); | ||
expect(result.meta.requestStatus).toBe('rejected'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/entities/Profile/model/services/updateProfileData/updateProfileData.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { TestAsyncThunk } from 'shared/lib/tests/TestAsyncThunk/TestAsyncThunk'; | ||
import { Country } from 'entities/Country'; | ||
import { Currency } from 'entities/Currency'; | ||
import { ValidateProfileError } from 'entities/Profile'; | ||
import { updateProfileData } from './updateProfileData'; | ||
|
||
const data = { | ||
username: 'test', | ||
first: 'test firstname', | ||
lastname: 'test lastname', | ||
age: 20, | ||
country: Country.Armenia, | ||
currency: Currency.EUR, | ||
avatar: | ||
'https://pic.rutubelist.ru/user/3b/27/3b2758ad5492a76b578f7ee072e4e894.jpg', | ||
city: 'yaroslavl', | ||
}; | ||
|
||
describe('updateProfileData.test', () => { | ||
test('updateProfileData async thunk test', async () => { | ||
const thunk = new TestAsyncThunk(updateProfileData, { | ||
profile: { | ||
form: data, | ||
}, | ||
}); | ||
|
||
thunk.api.put.mockReturnValue(Promise.resolve({ data })); | ||
|
||
const result = await thunk.callThunk(); | ||
|
||
expect(thunk.api.put).toHaveBeenCalled(); | ||
expect(result.meta.requestStatus).toBe('fulfilled'); | ||
expect(result.payload).toEqual(data); | ||
}); | ||
|
||
test('updateProfileData async error thunk test', async () => { | ||
const thunk = new TestAsyncThunk(updateProfileData, { | ||
profile: { | ||
form: data, | ||
}, | ||
}); | ||
thunk.api.put.mockReturnValue(Promise.resolve({ status: 403 })); | ||
|
||
const result = await thunk.callThunk(); | ||
|
||
expect(result.meta.requestStatus).toBe('rejected'); | ||
expect(result.payload).toEqual([ValidateProfileError.SERVER_ERROR]); | ||
}); | ||
|
||
test('validate error', async () => { | ||
const thunk = new TestAsyncThunk(updateProfileData, { | ||
profile: { | ||
form: { ...data, lastname: '' }, | ||
}, | ||
}); | ||
thunk.api.put.mockReturnValue(Promise.resolve({ status: 403 })); | ||
|
||
const result = await thunk.callThunk(); | ||
|
||
expect(result.meta.requestStatus).toBe('rejected'); | ||
expect(result.payload).toEqual([ValidateProfileError.INCORRECT_USER_DATA]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/entities/Profile/model/services/validateProfileData/validateProfileData.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Country } from 'entities/Country'; | ||
import { Currency } from 'entities/Currency'; | ||
import { validateProfileData } from 'entities/Profile/model/services/validateProfileData/validateProfileData'; | ||
import { ValidateProfileError } from 'entities/Profile'; | ||
|
||
const data = { | ||
username: 'test', | ||
first: 'test firstname', | ||
lastname: 'test lastname', | ||
age: 20, | ||
country: Country.Armenia, | ||
currency: Currency.EUR, | ||
avatar: | ||
'https://pic.rutubelist.ru/user/3b/27/3b2758ad5492a76b578f7ee072e4e894.jpg', | ||
city: 'yaroslavl', | ||
}; | ||
|
||
describe('validateProfileData.test', () => { | ||
test('validateProfileData async thunk test', async () => { | ||
const result = validateProfileData(data); | ||
|
||
expect(result).toEqual([]); | ||
}); | ||
|
||
test('validateProfileData with errors test (first, lastname)', async () => { | ||
const result = validateProfileData({ ...data, first: '', lastname: '' }); | ||
|
||
expect(result).toEqual([ValidateProfileError.INCORRECT_USER_DATA]); | ||
}); | ||
|
||
test('validateProfileData with errors test (age)', async () => { | ||
const result = validateProfileData({ ...data, age: undefined }); | ||
|
||
expect(result).toEqual([ValidateProfileError.INCORRECT_AGE]); | ||
}); | ||
|
||
test('validateProfileData with errors test (country)', async () => { | ||
const result = validateProfileData({ ...data, country: undefined }); | ||
|
||
expect(result).toEqual([ValidateProfileError.INCORRECT_COUNTRY]); | ||
}); | ||
|
||
test('validateProfileData with errors test (all)', async () => { | ||
const result = validateProfileData({}); | ||
|
||
expect(result).toEqual([ | ||
ValidateProfileError.INCORRECT_USER_DATA, | ||
ValidateProfileError.INCORRECT_AGE, | ||
ValidateProfileError.INCORRECT_COUNTRY, | ||
]); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
src/entities/Profile/model/services/validateProfileData/validateProfileData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.