Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Connect4
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
HOLZINGER Ulysse
Connect4
Commits
b414b903
"README.md" did not exist on "8c788a952f4e9635035b409c7f414bf46b698a84"
Commit
b414b903
authored
Dec 8, 2023
by
HOLZINGER Ulysse
Browse files
Options
Downloads
Patches
Plain Diff
Correction erreurs merge
parent
6c6fc8fa
No related branches found
No related tags found
No related merge requests found
Pipeline
#26410
failed
Dec 8, 2023
Stage: test
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/components/Board.test.js
+11
-31
11 additions, 31 deletions
src/components/Board.test.js
src/components/Cell.test.js
+9
-11
9 additions, 11 deletions
src/components/Cell.test.js
src/test/App.test.js
+1
-1
1 addition, 1 deletion
src/test/App.test.js
with
21 additions
and
43 deletions
src/components/Board.test.js
+
11
−
31
View file @
b414b903
import
React
from
'
react
'
;
import
{
render
,
fireEvent
}
from
'
@testing-library/react
'
;
import
Board
from
'
./Board
'
;
import
Board
from
'
.
./components
/Board
'
;
test
(
'
renders the board with cells
'
,
()
=>
{
const
board
=
[
[
0
,
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
,
0
,
0
]
];
const
{
container
}
=
render
(
<
Board
board
=
{
board
}
handleClick
=
{()
=>
{}}
/>
)
;
const
cells
=
container
.
querySelectorAll
(
'
.cell
'
);
expect
(
cells
.
length
).
toBe
(
6
*
7
);
test
(
'
renders Board component
'
,
()
=>
{
const
board
=
[[
0
,
0
,
0
],
[
0
,
0
,
0
],
[
0
,
0
,
0
]];
render
(
<
Board
board
=
{
board
}
handleClick
=
{()
=>
{}}
/>
)
;
});
test
(
'
calls handleClick when a cell is clicked
'
,
()
=>
{
const
board
=
[
[
0
,
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
,
0
,
0
]
];
const
handleClick
=
jest
.
fn
();
const
{
getByTestId
}
=
render
(
<
Board
board
=
{
board
}
handleClick
=
{
handleClick
}
/>
)
;
test
(
'
calls handleClick prop when a cell is clicked
'
,
()
=>
{
const
handleClickMock
=
jest
.
fn
();
const
board
=
[[
0
,
0
,
0
],
[
0
,
0
,
0
],
[
0
,
0
,
0
]];
const
{
container
}
=
render
(
<
Board
board
=
{
board
}
handleClick
=
{
handleClickMock
}
/>
)
;
const
cell
=
getByTestId
(
'
cell
'
);
fireEvent
.
click
(
cell
);
fireEvent
.
click
(
container
.
querySelector
(
'
.cell
'
));
expect
(
handleClick
).
toHaveBeenCalled
With
(
0
);
// Vérifie si handleClick est appelée avec le bon argument (0 pour la première cellule)
expect
(
handleClick
Mock
).
toHaveBeenCalled
Times
(
1
);
});
This diff is collapsed.
Click to expand it.
src/components/Cell.test.js
+
9
−
11
View file @
b414b903
import
React
from
'
react
'
;
import
{
render
}
from
'
@testing-library/react
'
;
import
Cell
from
'
./Cell
'
;
import
{
render
,
fireEvent
}
from
'
@testing-library/react
'
;
import
Cell
from
'
.
./components
/Cell
'
;
test
(
'
renders the cell with player 1 token
'
,
()
=>
{
const
{
getByTestId
}
=
render
(
<
Cell
value
=
{
1
}
/>
)
;
const
tokenImage
=
getByTestId
(
'
player-1-token
'
);
expect
(
tokenImage
).
toBeInTheDocument
();
test
(
'
renders Cell component
'
,
()
=>
{
render
(
<
Cell
value
=
{
0
}
onClick
=
{()
=>
{}}
/>
)
;
});
test
(
'
renders the cell with player 2 token
'
,
()
=>
{
const
{
getByTestId
}
=
render
(
<
Cell
value
=
{
-
1
}
/>
)
;
test
(
'
calls onClick prop when clicked
'
,
()
=>
{
const
onClickMock
=
jest
.
fn
();
const
{
container
}
=
render
(
<
Cell
value
=
{
0
}
onClick
=
{
onClickMock
}
/>
)
;
fireEvent
.
click
(
container
.
firstChild
);
const
tokenImage
=
getByTestId
(
'
player-2-token
'
);
expect
(
tokenImage
).
toBeInTheDocument
();
expect
(
onClickMock
).
toHaveBeenCalledTimes
(
1
);
});
This diff is collapsed.
Click to expand it.
src/App.test.js
→
src/
test/
App.test.js
+
1
−
1
View file @
b414b903
import
React
from
'
react
'
;
import
{
render
,
fireEvent
,
screen
,
queryByText
,
getByTestId
}
from
'
@testing-library/react
'
;
import
App
from
'
./App
'
;
import
App
from
'
.
.
/App
'
;
const
{
getAllByTestId
,
getByText
}
=
screen
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment