fix tests
This commit is contained in:
@@ -2,44 +2,36 @@ import React from "react";
|
|||||||
import {fireEvent, render} from "@testing-library/react"
|
import {fireEvent, render} from "@testing-library/react"
|
||||||
import Tulajdonsagok from "./Tulajdonsagok2E";
|
import Tulajdonsagok from "./Tulajdonsagok2E";
|
||||||
import {Faj2E} from "../domain-models/faj2E";
|
import {Faj2E} from "../domain-models/faj2E";
|
||||||
import {TulajdonsagDefaults} from "../domain-models/tulajdonsag2E";
|
|
||||||
import {
|
|
||||||
setEro,
|
|
||||||
} from "../domain-models/characterSlice";
|
|
||||||
import '@testing-library/jest-dom'
|
import '@testing-library/jest-dom'
|
||||||
import {Provider} from "react-redux";
|
import {Provider} from "react-redux";
|
||||||
import store from "../../store";
|
import store from "../../store";
|
||||||
|
|
||||||
describe("render Tulajdonsagok", () => {
|
describe("render Tulajdonsagok", () => {
|
||||||
test('change Ero', async () => {
|
test('change Ero', async () => {
|
||||||
type SetEroAction = ReturnType<typeof setEro>
|
const sut = render(
|
||||||
let invocations: SetEroAction[] = []
|
<Provider store={store} >
|
||||||
const dispatch = (action: SetEroAction) => {
|
<Tulajdonsagok currentFaj={Faj2E.Ember}/>
|
||||||
invocations.push(action)
|
</Provider>)
|
||||||
}
|
|
||||||
const sut = render(<Tulajdonsagok
|
|
||||||
currentFaj={Faj2E.Ember}
|
|
||||||
tulajdonsagok={TulajdonsagDefaults}
|
|
||||||
dispatch={dispatch}
|
|
||||||
/>)
|
|
||||||
const eroInput = await sut.findByTestId("t_ero");
|
const eroInput = await sut.findByTestId("t_ero");
|
||||||
fireEvent.change(eroInput, {target: {value: "20"}})
|
fireEvent.change(eroInput, {target: {value: "18"}})
|
||||||
expect(invocations).toHaveLength(1)
|
const eroInputAfterChange = await sut.findByTestId("t_ero");
|
||||||
const action = invocations[0]
|
expect((eroInputAfterChange as HTMLInputElement).value).toBe("18")
|
||||||
expect(action.payload).toEqual(20)
|
const storedCharacter = store.getState().character2E
|
||||||
|
expect(storedCharacter.tulajdonsagok.t_ero).toBe(18)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('display Ero too low error', async () => {
|
test('display Ero too low error', async () => {
|
||||||
const sut = render(<Tulajdonsagok
|
const sut = render(
|
||||||
currentFaj={Faj2E.Ember}
|
<Provider store={store} >
|
||||||
tulajdonsagok={{...TulajdonsagDefaults, t_ero: 1}}
|
<Tulajdonsagok currentFaj={Faj2E.Ember}/>
|
||||||
dispatch={() => {}}
|
</Provider>)
|
||||||
/>)
|
const eroInput = await sut.findByTestId("t_ero");
|
||||||
|
fireEvent.change(eroInput, {target: {value: "1"}})
|
||||||
const eroError = await sut.findByText("Túl gyenge vagy, nem bírtad felemelni a kezed a jelentkezéshez!");
|
const eroError = await sut.findByText("Túl gyenge vagy, nem bírtad felemelni a kezed a jelentkezéshez!");
|
||||||
expect(eroError).toBeVisible()
|
expect(eroError).toBeVisible()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('change Ero and display Ero too high error with store', async () => {
|
test('display Ero too high error with store', async () => {
|
||||||
const sut = render(
|
const sut = render(
|
||||||
<Provider store={store} >
|
<Provider store={store} >
|
||||||
<Tulajdonsagok currentFaj={Faj2E.Ember}/>
|
<Tulajdonsagok currentFaj={Faj2E.Ember}/>
|
||||||
|
|||||||
Reference in New Issue
Block a user