Skip to content

Commit

Permalink
Tst cases Check Go to Game Start, Check Moves List
Browse files Browse the repository at this point in the history
  • Loading branch information
angelannaroby committed Dec 5, 2023
1 parent 0ce5216 commit dc9c687
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 2 deletions.
156 changes: 155 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"devDependencies": {
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/react": "^14.1.2"
"@testing-library/react": "^14.1.2",
"eslint-config-standard": "^17.1.0"
}
}
54 changes: 54 additions & 0 deletions src/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,57 @@ test('test addiing player names button press functionality', () => {
fireEvent.click(square[0])
status = screen.getByText("Next player: testb")
})

test('Check Moves List', async () => {
render(<Game />)
var square = screen.getAllByTestId("square")

// Make a sequence of moves
fireEvent.click(square[0]) // X's move
fireEvent.click(square[3]) // O's move
fireEvent.click(square[1]) // X's move
fireEvent.click(square[4]) // O's move

// Wait for the next tick of the event loop
await new Promise(resolve => setTimeout(resolve, 0))

// Check if the moves list is rendered
var movesList = document.getElementsByClassName("orderedList")[0]
expect(movesList).toBeInTheDocument()

// Check if the list items are rendered based on the number of moves made
var movesCount = 5 // Adjust based on the number of moves made, including the initial state
var listItems = movesList.getElementsByTagName('li')
expect(listItems.length).toBe(movesCount)

// Check if the first list item corresponds to the initial state
var firstListItem = listItems[0]
expect(firstListItem).toHaveTextContent("Go to game start")

// Check if the last list item corresponds to the latest move
var lastListItem = listItems[movesCount - 1]
expect(lastListItem).toHaveTextContent("Go to move #4") // Adjust based on the last move
})

test('Check Go to Game Start', () => {
render(<Game />)

// Make some moves
const square = screen.getAllByTestId("square")
fireEvent.click(square[0])
fireEvent.click(square[3])

// Click "Go to game start" button
const goToGameStartButton = screen.getByText("Go to game start")
fireEvent.click(goToGameStartButton)

// Check if the game state is reset
const status = screen.getByText("Next player: X")
expect(status).toBeInTheDocument()

// Ensure that the initial move is displayed in the moves list
const movesList = document.getElementsByClassName("orderedList")[0]
const listItems = movesList.getElementsByTagName('li')
const firstListItem = listItems[0]
expect(firstListItem).toHaveTextContent("Go to game start")
})

0 comments on commit dc9c687

Please sign in to comment.