Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
Workshop-unit testing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alexander Hammerman
Workshop-unit testing
Commits
ad3e6788
Commit
ad3e6788
authored
2 years ago
by
Alexander Hammerman
Browse files
Options
Downloads
Patches
Plain Diff
Completed component as well as the tests
parent
07685bee
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
workshop/src/App.tsx
+1
-1
1 addition, 1 deletion
workshop/src/App.tsx
workshop/src/__tests__/AmountPicker.test.tsx
+10
-2
10 additions, 2 deletions
workshop/src/__tests__/AmountPicker.test.tsx
workshop/src/components/AmountPicker.tsx
+63
-11
63 additions, 11 deletions
workshop/src/components/AmountPicker.tsx
with
74 additions
and
14 deletions
workshop/src/App.tsx
+
1
−
1
View file @
ad3e6788
...
@@ -2,7 +2,7 @@ import './App.css';
...
@@ -2,7 +2,7 @@ import './App.css';
import
AmountPicker
from
'
./components/AmountPicker
'
;
import
AmountPicker
from
'
./components/AmountPicker
'
;
const
App
=
()
=>
{
const
App
=
()
=>
{
return
<
AmountPicker
></
AmountPicker
>
return
(
<
AmountPicker
></
AmountPicker
>
)
}
}
export
default
App
;
export
default
App
;
This diff is collapsed.
Click to expand it.
workshop/src/__tests__/A
pp
.test.tsx
→
workshop/src/__tests__/A
mountPicker
.test.tsx
+
10
−
2
View file @
ad3e6788
import
{
render
,
screen
}
from
'
@testing-library/react
'
;
import
{
render
,
screen
}
from
'
@testing-library/react
'
;
import
AmountPicker
from
'
../components/AmountPicker
'
;
import
AmountPicker
from
'
../components/AmountPicker
'
;
import
App
from
'
../App
'
;
test
(
'
Testing + button rendering
'
,
()
=>
{
test
(
'
Testing + button rendering
'
,
()
=>
{
render
(<
AmountPicker
/>)
render
(<
AmountPicker
/>)
...
@@ -12,4 +11,13 @@ test('Testing - button rendering', () => {
...
@@ -12,4 +11,13 @@ test('Testing - button rendering', () => {
render
(<
AmountPicker
/>)
render
(<
AmountPicker
/>)
const
decreaseButton
=
screen
.
getByRole
(
'
button
'
,{
name
:
'
-
'
})
const
decreaseButton
=
screen
.
getByRole
(
'
button
'
,{
name
:
'
-
'
})
expect
(
decreaseButton
).
toBeInTheDocument
()
expect
(
decreaseButton
).
toBeInTheDocument
()
});
});
\ No newline at end of file
test
(
'
Testing count rendering
'
,
()
=>
{
render
(<
AmountPicker
/>)
const
count
=
screen
.
getByRole
(
'
spinbutton
'
)
expect
(
count
).
toBeInTheDocument
()
})
//Write your test cases below :)
This diff is collapsed.
Click to expand it.
workshop/src/components/AmountPicker.tsx
+
63
−
11
View file @
ad3e6788
import
Button
from
"
@mui/material/Button
"
import
Button
from
"
@mui/material/Button
"
import
{
useState
}
from
"
react
"
import
{
useState
}
from
"
react
"
import
{
ButtonGroup
,
TextField
}
from
"
@mui/material
"
import
{
TextField
}
from
"
@mui/material
"
import
{
Stack
}
from
"
@mui/system
"
import
{
Stack
}
from
"
@mui/system
"
function
AmountPicker
()
{
function
AmountPicker
()
{
const
[
count
,
setCount
]
=
useState
(
0
)
const
min
=
1
const
max
=
20
const
[
count
,
setCount
]
=
useState
(
1
)
const
[
withDrawn
,
setwithDrawn
]
=
useState
(
0
)
const
increaseCount
=
()
=>
{
const
increaseCount
=
()
=>
{
setCount
(
count
+
1
)
if
(
count
+
1
<
max
)
{
setCount
(
count
+
1
)
}
else
{
setCount
(
max
)
}
}
}
const
decreaseCount
=
()
=>
{
const
decreaseCount
=
()
=>
{
setCount
(
count
-
1
)
if
(
count
-
1
>
min
)
{
setCount
(
count
-
1
)
}
else
{
setCount
(
min
)
}
}
const
withDraw
=
()
=>
{
setwithDrawn
(
withDrawn
+
count
)
}
}
return
(
return
(
<
div
>
<
div
>
<
Stack
spacing
=
{
3
}
>
<
Stack
direction
=
"row"
<
Button
onClick
=
{
increaseCount
}
variant
=
"contained"
>
+
</
Button
>
spacing
=
{
1
}
<
div
>
alignItems
=
'center'
{
count
}
justifyContent
=
'center'
</
div
>
sx
=
{
{
border
:
1
}
}
>
<
Button
onClick
=
{
decreaseCount
}
variant
=
"contained"
>
-
</
Button
>
<
Button
onClick
=
{
decreaseCount
}
variant
=
"contained"
>
-
</
Button
>
<
TextField
type
=
"number"
id
=
"count"
value
=
{
count
}
sx
=
{
{
input
:
{
textAlign
:
'
center
'
}
}
}
onChange
=
{
(
newValue
)
=>
{
if
(
Number
(
newValue
.
target
.
value
)
==
min
)
{
setCount
(
min
)
}
else
if
(
Number
(
newValue
.
target
.
value
)
>
max
)
{
setCount
(
max
)
}
else
{
setCount
(
Number
(
newValue
.
target
.
value
))
}
}
}
>
</
TextField
>
<
Button
onClick
=
{
increaseCount
}
variant
=
"contained"
>
+
</
Button
>
</
Stack
>
<
Stack
spacing
=
{
1
}
alignItems
=
'center'
justifyContent
=
'center'
>
<
Button
variant
=
"contained"
onClick
=
{
withDraw
}
>
Withdraw current amount
</
Button
>
<
div
>
<
p
>
You have withdrawn
</
p
>
<
p
>
{
withDrawn
}
</
p
>
</
div
>
</
Stack
>
</
Stack
>
</
div
>
</
div
>
)
)
}
}
export
default
AmountPicker
export
default
AmountPicker
\ No newline at end of file
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