Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
Ludwig Frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
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
Container 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
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ASTRON SDC
Ludwig Frontend
Merge requests
!36
Improve coverage + small refactorings
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Improve coverage + small refactorings
SDC-1338/add-coverage
into
main
Overview
0
Commits
18
Pipelines
5
Changes
15
Open
Robbie Luijben
requested to merge
SDC-1338/add-coverage
into
main
10 months ago
Overview
0
Commits
18
Pipelines
5
Changes
15
Expand
0
0
Merge request reports
Compare
main
version 3
157eea10
10 months ago
version 2
a429cb20
10 months ago
version 1
e84697fc
10 months ago
main (HEAD)
and
latest version
latest version
75b549e2
18 commits,
10 months ago
version 3
157eea10
17 commits,
10 months ago
version 2
a429cb20
16 commits,
10 months ago
version 1
e84697fc
15 commits,
10 months ago
15 files
+
534
−
67
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
15
Search (e.g. *.vue) (Ctrl+P)
src/__tests__/component/Abstract.test.tsx
0 → 100644
+
91
−
0
Options
import
createFetchMock
from
"
vitest-fetch-mock
"
;
import
{
vi
}
from
"
vitest
"
;
import
{
render
,
waitFor
}
from
"
@testing-library/react
"
;
import
Abstract
from
"
src/components/Abstract/Abstract
"
;
import
{
afterEach
,
beforeEach
,
describe
,
expect
,
it
}
from
"
vitest
"
;
import
{
createFetchResponse
,
user
}
from
"
../utils
"
;
import
Proposal
from
"
src/api/models/Proposal
"
;
describe
(
"
Abstract
"
,
async
()
=>
{
const
fetchMocker
=
createFetchMock
(
vi
);
beforeEach
(()
=>
fetchMocker
.
enableMocks
());
afterEach
(()
=>
fetchMocker
.
resetMocks
());
const
successMock
=
()
=>
{
fetchMocker
.
mockResponse
(
createFetchResponse
<
Proposal
>
(
{
id
:
12
,
title
:
"
My proposal
"
,
abstract
:
"
My concrete abstract
"
,
call_id
:
0
,
},
200
,
),
);
};
const
errorMock
=
()
=>
{
fetchMocker
.
mockResponse
(
createFetchResponse
<
unknown
>
({},
500
));
};
it
(
"
renders correctly
"
,
async
()
=>
{
const
component
=
render
(
<
Abstract
text
=
{
"
My concrete abstract
"
}
proposalId
=
{
12
}
/>,
);
expect
(
component
).
toBeTruthy
();
});
it
(
"
renders correctly with empty text
"
,
async
()
=>
{
const
component
=
render
(<
Abstract
text
=
{
""
}
proposalId
=
{
12
}
/>);
expect
(
component
).
toBeTruthy
();
});
it
(
"
displays supplied text in a text area
"
,
async
()
=>
{
const
text
=
"
My concrete abstract
"
;
const
component
=
render
(<
Abstract
text
=
{
text
}
proposalId
=
{
12
}
/>);
const
textArea
=
component
.
getByDisplayValue
(
text
);
expect
(
textArea
).
toBeTruthy
();
expect
(
textArea
.
tagName
).
toBe
(
"
TEXTAREA
"
);
});
it
(
"
displays the word count
"
,
async
()
=>
{
const
text
=
"
My concrete abstract
"
;
const
component
=
render
(<
Abstract
text
=
{
text
}
proposalId
=
{
12
}
/>);
const
wordCount
=
component
.
getByText
(
"
Save (3 words)
"
);
expect
(
wordCount
).
toBeTruthy
();
});
const
originalAbstract
=
"
My concrete abstract
"
;
const
newAbstract
=
"
New abstract
"
;
it
.
each
([
[
originalAbstract
,
newAbstract
,
originalAbstract
,
errorMock
],
[
originalAbstract
,
newAbstract
,
newAbstract
,
successMock
],
])(
"
sets the new abstract on success, sets the original abstract on error
"
,
async
(
originalValue
,
newValue
,
expectedValue
,
mock
)
=>
{
mock
();
const
component
=
render
(
<
Abstract
text
=
{
originalValue
}
proposalId
=
{
12
}
/>,
);
const
input
=
component
.
getByDisplayValue
(
originalValue
,
)
as
HTMLTextAreaElement
;
await
user
.
type
(
input
,
"
{backspace}
"
.
repeat
(
originalValue
.
length
));
await
user
.
type
(
input
,
newValue
);
const
saveButton
=
component
.
getByText
(
"
Save
"
,
{
exact
:
false
});
await
user
.
click
(
saveButton
);
await
waitFor
(()
=>
{
expect
(
input
.
value
).
toBe
(
expectedValue
);
});
},
);
});
Loading