-
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.
tests for profile module, fix screenshots
- Loading branch information
1 parent
5aa933b
commit 5a52084
Showing
66 changed files
with
589 additions
and
29 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -57,6 +57,7 @@ module.exports = { | |
globals: { | ||
__IS_DEV__: true, | ||
__API__: true, | ||
__PROJECT__: true, | ||
}, | ||
overrides: [ | ||
{ | ||
|
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.
Binary file modified
BIN
+103 KB
(1000%)
.loki/reference/chrome_iphone7_pages_ProfilePage_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.
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.
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.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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
28 changes: 28 additions & 0 deletions
28
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,28 @@ | ||
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 return error', () => { | ||
const data = { | ||
first: 'Veronika', | ||
lastname: 'Kuznetsova', | ||
age: 25, | ||
currency: Currency.USD, | ||
country: Country.Russia, | ||
city: 'Barnaul', | ||
username: 'admin', | ||
}; | ||
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 return 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); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
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,28 @@ | ||
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 return error', () => { | ||
const data = { | ||
first: 'Veronika', | ||
lastname: 'Kuznetsova', | ||
age: 25, | ||
currency: Currency.USD, | ||
country: Country.Russia, | ||
city: 'Barnaul', | ||
username: 'admin', | ||
}; | ||
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 work with filled state', () => { | ||
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('getProfileReadonly.test', () => { | ||
test('should work with filled state', () => { | ||
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 'entities/Profile'; | ||
import { getProfileValidateErrors } from './getProfileValidateErrors'; | ||
|
||
describe('getProfileValidateErrors.test', () => { | ||
test('should work with filled state', () => { | ||
const state: DeepPartial<StateSchema> = { | ||
profile: { | ||
validateErrors: [ | ||
ValidateProfileError.SERVER_ERROR, | ||
ValidateProfileError.INCORRECT_AGE, | ||
], | ||
}, | ||
}; | ||
expect(getProfileValidateErrors(state as StateSchema)).toEqual([ | ||
ValidateProfileError.SERVER_ERROR, | ||
ValidateProfileError.INCORRECT_AGE, | ||
]); | ||
}); | ||
test('should work with empty state', () => { | ||
const state: DeepPartial<StateSchema> = {}; | ||
expect(getProfileValidateErrors(state as StateSchema)).toEqual(undefined); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
src/entities/Profile/model/selectors/getProfileValidateErrors/getProfileValidateErrors.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,3 @@ | ||
import { StateSchema } from 'app/providers/StoreProvider'; | ||
|
||
export const getProfileValidateErrors = (state: StateSchema) => state.profile?.validateErrors; |
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
import { TestAsyncThunk } from 'shared/lib/tests/TestAsyncThunk/TestAsyncThunk'; | ||
import { Country } from 'entities/Country'; | ||
import { Currency } from 'entities/Currency'; | ||
import { fetchProfileData } from './fetchProfileData'; | ||
|
||
const data = { | ||
first: 'Veronika', | ||
lastname: 'Kuznetsova', | ||
age: 25, | ||
currency: Currency.USD, | ||
country: Country.Russia, | ||
city: 'Barnaul', | ||
username: 'admin', | ||
}; | ||
|
||
describe('fetchProfileData.test', () => { | ||
test('success', 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('error login', async () => { | ||
const thunk = new TestAsyncThunk(fetchProfileData); | ||
thunk.api.get.mockReturnValue(Promise.resolve({ status: 403 })); | ||
const result = await thunk.callThunk(); | ||
|
||
expect(result.meta.requestStatus).toBe('rejected'); | ||
}); | ||
}); |
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 = { | ||
first: 'Veronika', | ||
lastname: 'Kuznetsova', | ||
age: 25, | ||
currency: Currency.USD, | ||
country: Country.Russia, | ||
city: 'Barnaul', | ||
username: 'admin', | ||
}; | ||
|
||
describe('updateProfileData.test', () => { | ||
test('success', 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('error', 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, first: '' }, | ||
}, | ||
}); | ||
const result = await thunk.callThunk(); | ||
|
||
expect(result.meta.requestStatus).toBe('rejected'); | ||
expect(result.payload).toEqual([ | ||
ValidateProfileError.INCORRECT_USER_DATA, | ||
]); | ||
}); | ||
}); |
15 changes: 12 additions & 3 deletions
15
src/entities/Profile/model/services/updateProfileData/updateProfileData.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 |
---|---|---|
@@ -1,26 +1,35 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit'; | ||
import { ThunkConfig } from 'app/providers/StoreProvider'; | ||
import { Profile } from '../../types/profile'; | ||
import { Profile, ValidateProfileError } from '../../types/profile'; | ||
import { getProfileForm } from '../../selectors/getProfileForm/getProfileForm'; | ||
import { validateProfileData } from '../validateProfileData/validateProfileData'; | ||
|
||
export const updateProfileData = createAsyncThunk< | ||
Profile, | ||
void, | ||
ThunkConfig<string> | ||
ThunkConfig<ValidateProfileError[]> | ||
>( | ||
'profile/updateProfileData', | ||
async (_, thunkApi) => { | ||
const { extra, rejectWithValue, getState } = thunkApi; | ||
|
||
const formData = getProfileForm(getState()); | ||
const errors = validateProfileData(formData); | ||
if (errors.length) { | ||
return rejectWithValue(errors); | ||
} | ||
|
||
try { | ||
const response = await extra.api.put<Profile>('/profile', formData); | ||
|
||
if (!response.data) { | ||
throw new Error(); | ||
} | ||
|
||
return response.data; | ||
} catch (e) { | ||
console.log(e); | ||
return rejectWithValue('error'); | ||
return rejectWithValue([ValidateProfileError.SERVER_ERROR]); | ||
} | ||
}, | ||
); |
Oops, something went wrong.