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
badda247
Commit
badda247
authored
3 years ago
by
Tore.Brede
Browse files
Options
Downloads
Patches
Plain Diff
GREG-138: Fixing failing test
parent
76b4b564
No related branches found
No related tags found
1 merge request
!201
GREG-138: Adding error message if ous or role types cannot be loaded
Pipeline
#103735
passed
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/components/errorReport/index.tsx
+1
-1
1 addition, 1 deletion
frontend/src/components/errorReport/index.tsx
frontend/src/test-utils.tsx
+68
-10
68 additions, 10 deletions
frontend/src/test-utils.tsx
with
69 additions
and
11 deletions
frontend/src/components/errorReport/index.tsx
+
1
−
1
View file @
badda247
...
...
@@ -15,7 +15,7 @@ export default function ServerErrorReport({
statusText
,
errorBodyText
,
}:
ServerErrorReportData
)
{
const
[
t
]
=
useTranslation
([
'
common
'
])
const
{
t
}
=
useTranslation
([
'
common
'
])
return
(
<
Alert
severity
=
"error"
>
<
AlertTitle
>
{
errorHeading
}
</
AlertTitle
>
...
...
This diff is collapsed.
Click to expand it.
frontend/src/test-utils.tsx
+
68
−
10
View file @
badda247
...
...
@@ -19,13 +19,71 @@ export * from '@testing-library/react'
// override render method
export
{
customRender
as
render
}
// Mock react-i18next module to return a translation that just returns the key
jest
.
mock
(
'
react-i18next
'
,
()
=>
({
useTranslation
:
()
=>
({
t
:
(
value
:
string
)
=>
value
,
i18n
:
{
language
:
'
en
'
,
changeLanguage
:
()
=>
new
Promise
(()
=>
{}),
},
}),
}))
// The reason for this complex mock of react-i18next is to make the Trans-component work when running tests
jest
.
mock
(
'
react-i18next
'
,
():
object
=>
{
// Need to require React at this level as well to avoid getting an error
// when running the tests saying that the module factory is not allowed
// to reference out-of-scope variables
// eslint-disable-next-line @typescript-eslint/no-shadow,global-require
const
React
=
require
(
'
react
'
)
const
hasChildren
=
(
node
:
any
):
boolean
=>
node
&&
(
node
.
children
||
(
node
.
props
&&
node
.
props
.
children
))
const
getChildrenFromProps
=
(
node
:
any
):
any
=>
node
.
props
&&
node
.
props
.
children
?
node
.
props
.
children
:
null
const
getChildren
=
(
node
:
any
):
any
=>
node
&&
node
.
children
?
node
.
children
:
getChildrenFromProps
(
node
)
const
renderNodes
=
(
reactNodes
:
any
):
any
=>
{
if
(
typeof
reactNodes
===
'
string
'
)
{
return
reactNodes
}
return
Object
.
keys
(
reactNodes
).
map
((
key
,
i
)
=>
{
const
child
=
reactNodes
[
key
]
if
(
typeof
child
===
'
string
'
)
{
return
child
}
if
(
hasChildren
(
child
))
{
const
inner
=
renderNodes
(
getChildren
(
child
))
// eslint-disable-next-line react/no-array-index-key
return
React
.
cloneElement
(
child
,
{
...
child
.
props
,
key
:
i
},
inner
)
}
const
isElement
=
React
.
isValidElement
(
child
)
if
(
typeof
child
===
'
object
'
&&
!
isElement
)
{
return
Object
.
keys
(
child
).
reduce
(
(
str
,
childKey
)
=>
`
${
str
}${
child
[
childKey
]}
`
,
''
)
}
return
child
})
}
const
useMock
:
any
=
[(
k
:
any
)
=>
k
,
{}]
// Mock react-i18next module to return a translation that just returns the key
useMock
.
t
=
(
k
:
any
)
=>
k
useMock
.
i18n
=
{
// Return "en" as the selected language if the code asks for it
language
:
'
en
'
,
changeLanguage
:
()
=>
new
Promise
(()
=>
{}),
}
return
{
withTranslation
:
()
=>
(
Component
:
any
):
any
=>
(
props
:
any
):
any
=>
<
Component
t
=
{
(
k
:
any
):
any
=>
k
}
{
...
props
}
/>,
Trans
:
({
children
}:
any
)
=>
renderNodes
(
children
),
Translation
:
({
children
}:
any
)
=>
children
((
k
:
any
):
any
=>
k
,
{
i18n
:
{}
}),
useTranslation
:
()
=>
useMock
,
}
})
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