-
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 redux toolkit \ counter tests
- Loading branch information
Showing
11 changed files
with
113 additions
and
14 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { DeepPartial } from '@reduxjs/toolkit'; | ||
import { StateSchema } from 'app/providers/StoreProvider'; | ||
import { getCounter } from './getCounter'; | ||
|
||
describe('getCounter', () => { | ||
test('should return counter value', () => { | ||
const state:DeepPartial<StateSchema> = { | ||
counter: { value: 10 }, | ||
}; | ||
expect(getCounter(state as StateSchema)).toEqual({ value: 10 }); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
src/entities/Counter/model/selectors/getCounterValue/getCounterValue.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,13 @@ | ||
import { getCounterValue } from 'entities/Counter/model/selectors/getCounterValue/getCounterValue'; | ||
import { DeepPartial } from '@reduxjs/toolkit'; | ||
import { StateSchema } from 'app/providers/StoreProvider'; | ||
|
||
describe('getCounterValue.test', () => { | ||
test('get counter value', () => { | ||
const state:DeepPartial<StateSchema> = { | ||
counter: { value: 10 }, | ||
}; | ||
|
||
expect(getCounterValue(state as StateSchema)).toEqual(10); | ||
}); | ||
}); |
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 { CounterSchema } from 'entities/Counter'; | ||
import { counterActions, counterReducer } from './counterSlice'; | ||
|
||
describe('counterSlise.test', () => { | ||
test('decrement', () => { | ||
const state: CounterSchema = { | ||
value: 10, | ||
}; | ||
expect(counterReducer(state, counterActions.decrement)).toEqual({ | ||
value: 9, | ||
}); | ||
}); | ||
|
||
test('increment', () => { | ||
const state: CounterSchema = { | ||
value: 10, | ||
}; | ||
expect(counterReducer(state, counterActions.increment)).toEqual({ | ||
value: 11, | ||
}); | ||
}); | ||
|
||
test('should work with empty state', () => { | ||
expect(counterReducer(undefined, counterActions.increment)).toEqual({ | ||
value: 1, | ||
}); | ||
}); | ||
}); |
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 { fireEvent, screen } from '@testing-library/react'; | ||
import { componentRender } from 'shared/lib/tests/componentRender/componentRender'; | ||
import { Counter } from './Counter'; | ||
|
||
describe('Counter', () => { | ||
test('with only first param', () => { | ||
componentRender(<Counter />, { | ||
initialState: { counter: { value: 10 } }, | ||
}); | ||
expect(screen.getByTestId('value-title')).toHaveTextContent('10'); | ||
}); | ||
|
||
test('increment param click', () => { | ||
componentRender(<Counter />, { | ||
initialState: { counter: { value: 10 } }, | ||
}); | ||
const toggleBtn = screen.getByTestId('increment-btn'); | ||
fireEvent.click(toggleBtn); | ||
expect(screen.getByTestId('value-title')).toHaveTextContent('11'); | ||
}); | ||
|
||
test('decrement param click', () => { | ||
componentRender(<Counter />, { | ||
initialState: { counter: { value: 10 } }, | ||
}); | ||
const toggleBtn = screen.getByTestId('decrement-btn'); | ||
fireEvent.click(toggleBtn); | ||
expect(screen.getByTestId('value-title')).toHaveTextContent('9'); | ||
}); | ||
}); |
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