Skip to content

Commit

Permalink
Merge pull request #447 from edeandrea/clear-narration-new-fighters
Browse files Browse the repository at this point in the history
Clear narration when requesting new fighters
  • Loading branch information
holly-cummins authored Dec 8, 2023
2 parents c51724c + ff31c69 commit 3180659
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ function Fight({onFight}) {


const newFighters = () => {
getRandomFighters().then(answer => setFighters(answer))
getRandomFighters().then(answer => {
setFighters(answer)
clearPreviousFight()
})
}

const narrate = () => {
narrateFight(fightResult).then(answer => setNarration(answer))
}

const clearPreviousFight = () => {
setNarration(undefined)
setFightResult(undefined)
}

const fight = () => {
startFight(fighters).then(response => {
setFightResult(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe("the fight visualisation", () => {
})
expect(screen.getByText("Fake hero")).toBeInTheDocument()
expect(screen.getByText("Fake villain")).toBeInTheDocument()
expect(screen.queryByText(/NARRATE THE FIGHT/i)).not.toBeInTheDocument()
})

it("renders a fight button", async () => {
Expand All @@ -103,6 +104,7 @@ describe("the fight visualisation", () => {
expect(screen.getByText(/Winner is/i)).toBeInTheDocument()
// The winner name is in a span by itself but there should be more occurrences of the name count
expect(screen.getAllByText("Fake villain")).toHaveLength(nameCount + 1)
expect(screen.queryByText(/NARRATE THE FIGHT/i)).toBeInTheDocument()
})

it("renders narration when the narrate button is clicked", async () => {
Expand Down

0 comments on commit 3180659

Please sign in to comment.