Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
ac230b38
Commit
ac230b38
authored
Aug 16, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Aug 22, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate min and max length on export annotations filename
parent
f23ae27d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
13 deletions
+20
-13
ExportAnnotations.tsx
src/sidebar/components/ShareDialog/ExportAnnotations.tsx
+14
-7
ExportAnnotations-test.js
...bar/components/ShareDialog/test/ExportAnnotations-test.js
+6
-6
No files found.
src/sidebar/components/ShareDialog/ExportAnnotations.tsx
View file @
ac230b38
...
...
@@ -15,7 +15,6 @@ export type ExportAnnotationsProps = {
toastMessenger
:
ToastMessengerService
;
};
// TODO: Validate user-entered filename
// TODO: does the Input need a label?
/**
...
...
@@ -39,7 +38,9 @@ function ExportAnnotations({
return
<
LoadingSpinner
/>;
}
const
exportAnnotations
=
()
=>
{
const
exportAnnotations
=
(
e
:
Event
)
=>
{
e
.
preventDefault
();
try
{
const
filename
=
`
${
inputRef
.
current
!
.
value
}
.json`
;
const
exportData
=
annotationsExporter
.
buildExportContent
(
...
...
@@ -57,21 +58,27 @@ function ExportAnnotations({
};
return
(
<>
<
form
className=
"space-y-3"
onSubmit=
{
exportAnnotations
}
data
-
testid=
"export-form"
>
{
exportCount
>
0
?
(
<>
<
p
data
-
testid=
"export-count
"
>
<
label
data
-
testid=
"export-count"
htmlFor=
"export-filename
"
>
Export
{
' '
}
<
strong
>
{
exportCount
}
{
pluralize
(
'annotation'
,
exportCount
)
}
</
strong
>
{
' '
}
in a file named:
</
p
>
</
label
>
<
Input
data
-
testid=
"export-filename"
id=
"export-filename"
defaultValue=
{
suggestedFilename
({
groupName
:
group
?.
name
})
}
elementRef=
{
inputRef
}
required
maxLength=
{
250
}
/>
</>
)
:
(
...
...
@@ -90,12 +97,12 @@ function ExportAnnotations({
data
-
testid=
"export-button"
variant=
"primary"
disabled=
{
!
exportCount
}
onClick=
{
exportAnnotations
}
type=
"submit"
>
Export
</
Button
>
</
CardActions
>
</>
</
form
>
);
}
...
...
src/sidebar/components/ShareDialog/test/ExportAnnotations-test.js
View file @
ac230b38
...
...
@@ -111,9 +111,9 @@ describe('ExportAnnotations', () => {
assert
.
equal
(
input
.
prop
(
'defaultValue'
),
'suggested-filename'
);
});
describe
(
'export
button click
ed'
,
()
=>
{
const
clickExportButton
=
wrapper
=>
wrapper
.
find
(
'
button[data-testid="export-button"]'
).
simulate
(
'click
'
);
describe
(
'export
form submitt
ed'
,
()
=>
{
const
submitExportForm
=
wrapper
=>
wrapper
.
find
(
'
[data-testid="export-form"]'
).
simulate
(
'submit
'
);
it
(
'builds an export file from the non-draft annotations'
,
()
=>
{
const
wrapper
=
createComponent
();
...
...
@@ -123,7 +123,7 @@ describe('ExportAnnotations', () => {
];
fakeStore
.
savedAnnotations
.
returns
(
annotationsToExport
);
clickExportButton
(
wrapper
);
submitExportForm
(
wrapper
);
assert
.
calledOnce
(
fakeAnnotationsExporter
.
buildExportContent
);
assert
.
calledWith
(
...
...
@@ -139,7 +139,7 @@ describe('ExportAnnotations', () => {
wrapper
.
find
(
'input[data-testid="export-filename"]'
).
getDOMNode
().
value
=
'my-filename'
;
clickExportButton
(
wrapper
);
submitExportForm
(
wrapper
);
assert
.
calledOnce
(
fakeDownloadJSONFile
);
assert
.
calledWith
(
...
...
@@ -157,7 +157,7 @@ describe('ExportAnnotations', () => {
const
wrapper
=
createComponent
();
clickExportButton
(
wrapper
);
submitExportForm
(
wrapper
);
assert
.
notCalled
(
fakeDownloadJSONFile
);
assert
.
calledOnce
(
fakeAnnotationsExporter
.
buildExportContent
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment