@@ -7,23 +7,23 @@ import { act } from "react-dom/test-utils";
77
88describe ( 'PlayerDisplay' , ( ) => {
99 class PlayerComponent {
10- addPointsButton ( role ) {
11- return screen . getByLabelText ( `Earn ${ role } Points` ) ;
12- }
13-
14- clickAddPoints ( role : string ) {
15- fireEvent . click ( player . addPointsButton ( role ) ) ;
16- }
17-
10+
1811 addPointsInput ( ) {
1912 return screen . getByLabelText ( 'Add Points' ) ;
2013 }
2114
22- enterAddPointsForm ( value : string ) {
23- act ( ( ) => {
24- fireEvent . change ( this . addPointsInput ( ) , { target : { value : value } } )
25- fireEvent . click ( screen . getByText ( 'Add' ) ) ;
26- } )
15+ async checkTodo ( todo ) {
16+ const checkbox = screen . getByRole ( 'checkbox' , { name : new RegExp ( todo , 'i' ) } ) ;
17+ await act ( async ( ) => {
18+ await userEvent . click ( checkbox ) ;
19+ } ) ;
20+ }
21+
22+ async clickEarnPoints ( ) {
23+ const submitButton = screen . getByText ( 'Earn' ) ;
24+ await act ( async ( ) => {
25+ await userEvent . click ( submitButton ) ;
26+ } ) ;
2727 }
2828
2929 pointsDisplay ( role : string ) {
@@ -38,17 +38,17 @@ describe('PlayerDisplay', () => {
3838 const player = new PlayerComponent ( ) ;
3939
4040 it ( 'shows the players name' , ( ) => {
41- render ( < PlayerDisplay player = { new Player ( "Roger" ) } /> ) ;
41+ render ( < PlayerDisplay player = { new Player ( "Roger" ) } position = "Typing" /> ) ;
4242 expect ( screen . getByRole ( 'listitem' ) ) . toHaveTextContent ( "Roger" ) ;
4343 } ) ;
4444
4545 it ( 'shows the players role' , ( ) => {
46- render ( < PlayerDisplay player = { new Player ( "Roger" ) } /> ) ;
46+ render ( < PlayerDisplay player = { new Player ( "Roger" ) } position = "Typing" /> ) ;
4747 expect ( screen . getByRole ( 'listitem' ) ) . toHaveTextContent ( "Typing" ) ;
4848 } ) ;
4949
5050 it ( 'shows the initial points' , ( ) => {
51- render ( < PlayerDisplay player = { new Player ( "Roger" ) } /> ) ;
51+ render ( < PlayerDisplay player = { new Player ( "Roger" ) } position = "Typing" /> ) ;
5252
5353 function roleInitialized ( role : string ) {
5454 const typerPoints = screen . getByLabelText ( role ) ;
@@ -61,50 +61,39 @@ describe('PlayerDisplay', () => {
6161 roleInitialized ( 'Observing' ) ;
6262 } ) ;
6363
64- it ( 'adds typer points' , ( ) => {
65- render ( < PlayerDisplay player = { new Player ( "Roger" ) } /> ) ;
66- player . clickAddPoints ( 'Typing' ) ;
67- expect ( player . addPointsInput ( ) ) . toBeInTheDocument ( ) ;
68- expect ( player . addPointsInput ( ) ) . toHaveValue ( "0" ) ;
69-
70- player . enterAddPointsForm ( "2" ) ;
71-
72- expect ( player . pointsDisplay ( 'Typing' ) ) . toHaveValue ( "2" ) ;
73- expect ( screen . queryByLabelText ( 'Add Points' ) ) . toBeNull ( ) ;
74- } ) ;
75-
76- it ( 'adds up points' , ( ) => {
77- render ( < PlayerDisplay player = { new Player ( "Roger" ) } /> ) ;
78- player . clickAddPoints ( 'Typing' ) ;
79- player . enterAddPointsForm ( "1" ) ;
80- expect ( player . pointsDisplay ( 'Typing' ) ) . toHaveValue ( "1" ) ;
81-
82- player . clickAddPoints ( 'Typing' ) ;
83- player . enterAddPointsForm ( "2" ) ;
84-
64+
65+ it ( 'adds up points' , async ( ) => {
66+ render ( < PlayerDisplay player = { new Player ( "Roger" ) } position = "Typing" /> ) ;
67+ await player . checkTodo ( "Ask a clarifying question about what to type" ) ;
68+ await player . checkTodo ( "Type something you disagree with" ) ;
69+ await player . checkTodo ( "Use a new keyboard shortcut" ) ;
70+ await player . clickEarnPoints ( ) ;
71+
8572 expect ( player . pointsDisplay ( 'Typing' ) ) . toHaveValue ( "3" ) ;
8673 expect ( screen . getByAltText ( 'Typing Badge' ) ) . toBeInTheDocument ( ) ;
8774 } ) ;
8875
8976 it ( 'cannot select a new role before having a badge' , ( ) => {
90- render ( < PlayerDisplay player = { new Player ( "Roger" ) } /> ) ;
77+ render ( < PlayerDisplay player = { new Player ( "Roger" ) } position = "Typing" /> ) ;
9178
9279 expect ( player . selectNextRole ( ) ) . not . toBeInTheDocument ( )
9380 } ) ;
9481
95- it ( 'can select a new role after earning a badge' , ( ) => {
96- render ( < PlayerDisplay player = { new Player ( "Roger" ) } /> ) ;
97- player . clickAddPoints ( "Talking" ) ;
98- player . enterAddPointsForm ( "3" ) ;
99-
100- expect ( screen . getByAltText ( 'Talking Badge' ) ) . toBeInTheDocument ( ) ;
82+ it ( 'can select a new role after earning a badge' , async ( ) => {
83+ render ( < PlayerDisplay player = { new Player ( "Roger" ) } position = "Typing" /> ) ;
84+ await player . checkTodo ( "Ask a clarifying question about what to type" ) ;
85+ await player . checkTodo ( "Type something you disagree with" ) ;
86+ await player . checkTodo ( "Use a new keyboard shortcut" ) ;
87+ await player . clickEarnPoints ( ) ;
88+
89+ expect ( screen . getByAltText ( 'Typing Badge' ) ) . toBeInTheDocument ( ) ;
10190 expect ( screen . getByRole ( 'listitem' , { name : / R o g e r / i } ) ) . toBeInTheDocument ( ) ;
10291
10392 const availableRoles = screen . getByLabelText ( / a v a i l a b l e r o l e s / i) ;
10493 expect ( availableRoles ) . toBeInTheDocument ( )
10594 const researcherOption = within ( availableRoles ) . getByRole ( 'option' , { name : / r e s e a r c h e r / i } ) ;
10695 fireEvent . select ( researcherOption )
107- userEvent . selectOptions (
96+ await userEvent . selectOptions (
10897 availableRoles ,
10998 researcherOption
11099 )
0 commit comments