Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
greg
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
it-bott-integrasjoner
greg
Commits
8435d589
Commit
8435d589
authored
3 years ago
by
Tore.Brede
Browse files
Options
Downloads
Patches
Plain Diff
Improving testcase
parent
3c278321
No related branches found
No related tags found
1 merge request
!111
Improving testcase
Pipeline
#96928
failed
3 years ago
Stage: venv update
Stage: tests and linting
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/routes/register/index.test.tsx
+28
-27
28 additions, 27 deletions
frontend/src/routes/register/index.test.tsx
frontend/src/routes/register/stepPersonForm.tsx
+1
-0
1 addition, 0 deletions
frontend/src/routes/register/stepPersonForm.tsx
with
29 additions
and
27 deletions
frontend/src/routes/register/index.test.tsx
+
28
−
27
View file @
8435d589
import
React
from
'
react
'
import
React
from
'
react
'
import
{
render
,
waitFor
,
screen
}
from
'
test-utils
'
import
{
render
,
waitFor
,
screen
}
from
'
test-utils
'
import
i18n
from
'
i18next
'
import
{
initReactI18next
}
from
'
react-i18next
'
import
userEvent
from
'
@testing-library/user-event
'
import
userEvent
from
'
@testing-library/user-event
'
import
AdapterDateFns
from
'
@mui/lab/AdapterDateFns
'
import
AdapterDateFns
from
'
@mui/lab/AdapterDateFns
'
import
{
LocalizationProvider
}
from
'
@mui/lab
'
import
{
LocalizationProvider
}
from
'
@mui/lab
'
import
Register
from
'
./index
'
import
Register
from
'
./index
'
import
{
act
}
from
'
@testing-library/react
'
// TODO: can this be initialized in 'test-utils'? should we stub it?
// Mock react-i18next module to return a translation that just returns the key
// see https://react.i18next.com/misc/testing
jest
.
mock
(
'
react-i18next
'
,
()
=>
({
i18n
.
use
(
initReactI18next
).
init
({
useTranslation
:
()
=>
({
lng
:
'
en
'
,
t
:
(
value
:
string
)
=>
value
,
fallbackLng
:
'
en
'
,
i18n
:
{
changeLanguage
:
()
=>
new
Promise
(()
=>
{
}),
},
}),
}))
// Have a common namespace used around the full app
ns
:
[
'
translations
'
],
defaultNS
:
'
translations
'
,
debug
:
false
,
resources
:
{
en
:
{
translations
:
{}
}
},
})
test
(
'
Validation message showing if last name is missing
'
,
async
()
=>
{
test
(
'
Validation message showing if last name is missing
'
,
async
()
=>
{
render
(
render
(
...
@@ -28,21 +24,26 @@ test('Validation message showing if last name is missing', async () => {
...
@@ -28,21 +24,26 @@ test('Validation message showing if last name is missing', async () => {
<
Register
/>
<
Register
/>
</
LocalizationProvider
>)
</
LocalizationProvider
>)
const
firstNameLabel
=
i18n
.
t
(
'
input.firstName
'
).
toString
()
const
firstNameComponent
=
screen
.
getByLabelText
(
firstNameLabel
)
expect
(
firstNameComponent
).
toBeInTheDocument
()
userEvent
.
type
(
firstNameComponent
,
'
Test
'
)
// Try to go to the next step and check that the validation message is showing
// Try to go to the next step and check that the validation message is showing
const
submitButton
=
screen
.
getByTestId
(
'
button-next
'
)
const
submitButton
=
screen
.
getByTestId
(
'
button-next
'
)
userEvent
.
click
(
submitButton
)
userEvent
.
click
(
submitButton
)
const
validationLastName
=
i18n
const
validationMessage
=
await
waitFor
(()
=>
screen
.
getByText
(
'
validation.lastNameRequired
'
))
.
t
(
'
common:validation.lastNameRequired
'
)
.
toString
()
await
waitFor
(()
=>
screen
.
getByText
(
validationLastName
))
const
validationMessage
=
screen
.
getByText
(
validationLastName
)
expect
(
validationMessage
).
toBeInTheDocument
()
expect
(
validationMessage
).
toBeInTheDocument
()
screen
.
queryByText
(
'
validation.lastNameRequired
'
)
const
inputValue
=
'
Test input value
'
// Note that we need to use the test-ID of the input field inside the Material UI TextField-component
userEvent
.
type
(
screen
.
getByTestId
(
'
lastName-input-field
'
),
inputValue
)
expect
(
screen
.
getByDisplayValue
(
inputValue
)).
toBeInTheDocument
()
// Type in text, the message should disappear
screen
.
queryByText
(
'
validation.lastNameRequired
'
)
userEvent
.
click
(
submitButton
)
await
waitFor
((()
=>
{
expect
(
screen
.
queryByText
(
'
validation.lastNameRequired
'
)).
not
.
toBeInTheDocument
()
}))
})
})
This diff is collapsed.
Click to expand it.
frontend/src/routes/register/stepPersonForm.tsx
+
1
−
0
View file @
8435d589
...
@@ -132,6 +132,7 @@ const StepPersonForm = forwardRef((props: StepPersonFormProperties, ref: Ref<Per
...
@@ -132,6 +132,7 @@ const StepPersonForm = forwardRef((props: StepPersonFormProperties, ref: Ref<Per
{
...
register
(
`last_name`
,
{
{
...
register
(
`last_name`
,
{
required
:
t
<
string
>
(
'
validation.lastNameRequired
'
),
required
:
t
<
string
>
(
'
validation.lastNameRequired
'
),
})
}
})
}
inputProps
=
{
{
'
data-testid
'
:
'
lastName-input-field
'
}
}
/>
/>
<
TextField
<
TextField
id
=
'email'
id
=
'email'
...
...
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