@@ -6,7 +6,45 @@ import { fireEvent, render } from "@testing-library/react";
6
6
import { App } from "./App" ;
7
7
8
8
describe ( "<App />" , ( ) => {
9
- test ( "truth" , ( ) => {
10
- expect ( true ) . toBe ( true ) ;
9
+ it ( "should render the text input" , ( ) => {
10
+ let { getByRole } = render ( < App /> ) ;
11
+ expect ( getByRole ( "textbox" ) ) . toBeInTheDocument ( ) ;
12
+ } ) ;
13
+
14
+ it ( "should render the progress slider" , ( ) => {
15
+ let { getByRole } = render ( < App /> ) ;
16
+ expect ( getByRole ( "slider" ) ) . toBeInTheDocument ( ) ;
17
+ } ) ;
18
+
19
+ describe ( "when rendering the completion %" , ( ) => {
20
+ test ( "should initially indicated no time allocated" , ( ) => {
21
+ let { getByText } = render ( < App /> ) ;
22
+ expect ( getByText ( "No time allocated yet" ) ) . toBeInTheDocument ( ) ;
23
+ } ) ;
24
+
25
+ test ( "should read 100% Complete when task time is at max" , ( ) => {
26
+ let { getByRole, getByText, getByLabelText } = render ( < App /> ) ;
27
+ let slider = getByRole ( "slider" ) ;
28
+ let input = getByRole ( "textbox" ) ;
29
+
30
+ userEvent . type ( input , "2" ) ;
31
+ fireEvent . click ( slider ) ;
32
+
33
+ // nudge twice
34
+ fireEvent . keyDown ( slider , { key : "ArrowRight" } ) ;
35
+ fireEvent . keyDown ( slider , { key : "ArrowRight" } ) ;
36
+
37
+ fireEvent . click ( getByLabelText ( "Subtract" ) ) ;
38
+
39
+ expect ( getByText ( "100% complete" ) ) . toBeInTheDocument ( ) ;
40
+ } ) ;
41
+
42
+ test ( "should read 0% Complete when task time is at min" , ( ) => {
43
+ let { getByRole, getByText, getByLabelText, container } = render ( < App /> ) ;
44
+ let input = getByRole ( "textbox" ) ;
45
+ userEvent . type ( input , "2" ) ;
46
+
47
+ expect ( getByText ( "0% complete" ) ) . toBeInTheDocument ( ) ;
48
+ } ) ;
11
49
} ) ;
12
50
} ) ;
0 commit comments