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
a6109dbd
Commit
a6109dbd
authored
Nov 11, 2024
by
Alejandro Celaya
Committed by
Alejandro Celaya
Nov 11, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure Selects are opening before querying options
parent
ffaf6ff6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
10 deletions
+56
-10
ExportAnnotations-test.js
...bar/components/ShareDialog/test/ExportAnnotations-test.js
+28
-5
ImportAnnotations-test.js
...bar/components/ShareDialog/test/ImportAnnotations-test.js
+28
-5
No files found.
src/sidebar/components/ShareDialog/test/ExportAnnotations-test.js
View file @
a6109dbd
...
@@ -19,6 +19,7 @@ describe('ExportAnnotations', () => {
...
@@ -19,6 +19,7 @@ describe('ExportAnnotations', () => {
let
fakeCopyPlainText
;
let
fakeCopyPlainText
;
let
fakeCopyHTML
;
let
fakeCopyHTML
;
let
wrappers
;
let
wrappers
;
let
containers
;
const
fakePrivateGroup
=
{
const
fakePrivateGroup
=
{
type
:
'private'
,
type
:
'private'
,
...
@@ -27,19 +28,26 @@ describe('ExportAnnotations', () => {
...
@@ -27,19 +28,26 @@ describe('ExportAnnotations', () => {
};
};
const
createComponent
=
props
=>
{
const
createComponent
=
props
=>
{
const
newContainer
=
document
.
createElement
(
'div'
);
containers
.
push
(
newContainer
);
document
.
body
.
appendChild
(
newContainer
);
const
wrapper
=
mount
(
const
wrapper
=
mount
(
<
ExportAnnotations
<
ExportAnnotations
annotationsExporter
=
{
fakeAnnotationsExporter
}
annotationsExporter
=
{
fakeAnnotationsExporter
}
toastMessenger
=
{
fakeToastMessenger
}
toastMessenger
=
{
fakeToastMessenger
}
{...
props
}
{...
props
}
/>
,
/>
,
{
attachTo
:
newContainer
},
);
);
wrappers
.
push
(
wrapper
);
wrappers
.
push
(
wrapper
);
containers
.
push
(
newContainer
);
return
wrapper
;
return
wrapper
;
};
};
beforeEach
(()
=>
{
beforeEach
(()
=>
{
wrappers
=
[];
wrappers
=
[];
containers
=
[];
fakeAnnotationsExporter
=
{
fakeAnnotationsExporter
=
{
buildJSONExportContent
:
sinon
.
stub
().
returns
({}),
buildJSONExportContent
:
sinon
.
stub
().
returns
({}),
buildTextExportContent
:
sinon
.
stub
().
returns
(
''
),
buildTextExportContent
:
sinon
.
stub
().
returns
(
''
),
...
@@ -96,12 +104,27 @@ describe('ExportAnnotations', () => {
...
@@ -96,12 +104,27 @@ describe('ExportAnnotations', () => {
afterEach
(()
=>
{
afterEach
(()
=>
{
wrappers
.
forEach
(
w
=>
w
.
unmount
());
wrappers
.
forEach
(
w
=>
w
.
unmount
());
containers
.
forEach
(
c
=>
c
.
remove
());
$imports
.
$restore
();
$imports
.
$restore
();
});
});
const
waitForSelect
=
(
wrapper
,
testId
)
=>
const
waitForSelect
=
(
wrapper
,
testId
)
=>
waitForElement
(
wrapper
,
`Select[data-testid="
${
testId
}
"]`
);
waitForElement
(
wrapper
,
`Select[data-testid="
${
testId
}
"]`
);
/**
* Wait for a `Select` to be found, then opens it and wait for the listbox to
* be found.
* @return Promise<{ select: EnzymeWrapper; listbox: EnzymeWrapper }> -
* The select and listbox wrappers
*/
async
function
waitForOpenSelect
(
wrapper
,
testId
)
{
const
select
=
await
waitForSelect
(
wrapper
,
testId
);
select
.
find
(
'button'
).
simulate
(
'click'
);
const
listbox
=
await
waitForElement
(
wrapper
,
'[role="listbox"]'
);
return
{
select
,
listbox
};
}
const
selectExportFormat
=
async
(
wrapper
,
format
)
=>
{
const
selectExportFormat
=
async
(
wrapper
,
format
)
=>
{
const
select
=
await
waitForSelect
(
wrapper
,
'export-format-select'
);
const
select
=
await
waitForSelect
(
wrapper
,
'export-format-select'
);
select
.
props
().
onChange
({
value
:
format
});
select
.
props
().
onChange
({
value
:
format
});
...
@@ -208,8 +231,8 @@ describe('ExportAnnotations', () => {
...
@@ -208,8 +231,8 @@ describe('ExportAnnotations', () => {
const
wrapper
=
createComponent
();
const
wrapper
=
createComponent
();
const
userList
=
await
waitFor
Select
(
wrapper
,
'user-select'
);
const
{
listbox
}
=
await
waitForOpen
Select
(
wrapper
,
'user-select'
);
const
users
=
userList
.
find
(
Select
.
Option
);
const
users
=
listbox
.
find
(
Select
.
Option
);
assert
.
equal
(
users
.
length
,
userEntries
.
length
);
assert
.
equal
(
users
.
length
,
userEntries
.
length
);
for
(
const
[
i
,
entry
]
of
userEntries
.
entries
())
{
for
(
const
[
i
,
entry
]
of
userEntries
.
entries
())
{
...
@@ -247,11 +270,11 @@ describe('ExportAnnotations', () => {
...
@@ -247,11 +270,11 @@ describe('ExportAnnotations', () => {
it
(
'lists supported export formats'
,
async
()
=>
{
it
(
'lists supported export formats'
,
async
()
=>
{
const
wrapper
=
createComponent
();
const
wrapper
=
createComponent
();
const
select
=
await
waitForElemen
t
(
const
{
listbox
}
=
await
waitForOpenSelec
t
(
wrapper
,
wrapper
,
'
[data-testid="export-format-select"]
'
,
'
export-format-select
'
,
);
);
const
options
=
select
.
find
(
Select
.
Option
);
const
options
=
listbox
.
find
(
Select
.
Option
);
const
optionText
=
(
index
,
type
)
=>
const
optionText
=
(
index
,
type
)
=>
options
.
at
(
index
).
find
(
`[data-testid="format-
${
type
}
"]`
).
text
();
options
.
at
(
index
).
find
(
`[data-testid="format-
${
type
}
"]`
).
text
();
...
...
src/sidebar/components/ShareDialog/test/ImportAnnotations-test.js
View file @
a6109dbd
...
@@ -13,9 +13,11 @@ describe('ImportAnnotations', () => {
...
@@ -13,9 +13,11 @@ describe('ImportAnnotations', () => {
let
fakeReadExportFile
;
let
fakeReadExportFile
;
let
fakeStore
;
let
fakeStore
;
let
wrappers
;
let
wrappers
;
let
containers
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
wrappers
=
[];
wrappers
=
[];
containers
=
[];
fakeReadExportFile
=
sinon
.
stub
().
rejects
(
new
Error
(
'Failed to read file'
));
fakeReadExportFile
=
sinon
.
stub
().
rejects
(
new
Error
(
'Failed to read file'
));
...
@@ -43,17 +45,24 @@ describe('ImportAnnotations', () => {
...
@@ -43,17 +45,24 @@ describe('ImportAnnotations', () => {
afterEach
(()
=>
{
afterEach
(()
=>
{
wrappers
.
forEach
(
w
=>
w
.
unmount
());
wrappers
.
forEach
(
w
=>
w
.
unmount
());
containers
.
forEach
(
c
=>
c
.
remove
());
$imports
.
$restore
();
$imports
.
$restore
();
});
});
function
createImportAnnotations
()
{
function
createImportAnnotations
()
{
const
newContainer
=
document
.
createElement
(
'div'
);
containers
.
push
(
newContainer
);
document
.
body
.
appendChild
(
newContainer
);
const
wrapper
=
mount
(
const
wrapper
=
mount
(
<
ImportAnnotations
<
ImportAnnotations
store
=
{
fakeStore
}
store
=
{
fakeStore
}
importAnnotationsService
=
{
fakeImportAnnotationsService
}
importAnnotationsService
=
{
fakeImportAnnotationsService
}
/>
,
/>
,
{
attachTo
:
newContainer
},
);
);
wrappers
.
push
(
wrapper
);
wrappers
.
push
(
wrapper
);
containers
.
push
(
newContainer
);
return
wrapper
;
return
wrapper
;
}
}
...
@@ -81,6 +90,20 @@ describe('ImportAnnotations', () => {
...
@@ -81,6 +90,20 @@ describe('ImportAnnotations', () => {
return
Boolean
(
getImportButton
(
wrapper
).
prop
(
'disabled'
));
return
Boolean
(
getImportButton
(
wrapper
).
prop
(
'disabled'
));
}
}
/**
* Wait for a `Select` to be found, then opens it and wait for the listbox to
* be found.
* @return Promise<{ select: EnzymeWrapper; listbox: EnzymeWrapper }> -
* The select and listbox wrappers
*/
async
function
waitForOpenSelect
(
wrapper
)
{
const
select
=
await
waitForElement
(
wrapper
,
Select
);
select
.
find
(
'button'
).
simulate
(
'click'
);
const
listbox
=
await
waitForElement
(
wrapper
,
'[role="listbox"]'
);
return
{
select
,
listbox
};
}
it
(
'shows a notice if the user is not logged in'
,
()
=>
{
it
(
'shows a notice if the user is not logged in'
,
()
=>
{
fakeStore
.
profile
.
returns
({
userid
:
null
});
fakeStore
.
profile
.
returns
({
userid
:
null
});
const
wrapper
=
createImportAnnotations
();
const
wrapper
=
createImportAnnotations
();
...
@@ -200,8 +223,8 @@ describe('ImportAnnotations', () => {
...
@@ -200,8 +223,8 @@ describe('ImportAnnotations', () => {
selectFile
(
wrapper
,
annotations
);
selectFile
(
wrapper
,
annotations
);
const
userList
=
await
waitForElement
(
wrapper
,
Select
);
const
{
listbox
}
=
await
waitForOpenSelect
(
wrapper
);
const
users
=
userList
.
find
(
Select
.
Option
);
const
users
=
listbox
.
find
(
Select
.
Option
);
assert
.
equal
(
users
.
length
,
userEntries
.
length
);
assert
.
equal
(
users
.
length
,
userEntries
.
length
);
...
@@ -297,15 +320,15 @@ describe('ImportAnnotations', () => {
...
@@ -297,15 +320,15 @@ describe('ImportAnnotations', () => {
selectFile
(
wrapper
,
annotations
);
selectFile
(
wrapper
,
annotations
);
const
userList
=
await
waitForElement
(
wrapper
,
Select
);
const
{
select
,
listbox
}
=
await
waitForOpenSelect
(
wrapper
);
const
option
=
userList
const
option
=
listbox
.
find
(
Select
.
Option
)
.
find
(
Select
.
Option
)
.
filterWhere
(
.
filterWhere
(
option
=>
option
.
prop
(
'value'
).
userid
===
'acct:brian@example.com'
,
option
=>
option
.
prop
(
'value'
).
userid
===
'acct:brian@example.com'
,
)
)
.
first
();
.
first
();
userLis
t
.
prop
(
'onChange'
)(
option
.
prop
(
'value'
));
selec
t
.
prop
(
'onChange'
)(
option
.
prop
(
'value'
));
wrapper
.
update
();
wrapper
.
update
();
const
importButton
=
getImportButton
(
wrapper
).
getDOMNode
();
const
importButton
=
getImportButton
(
wrapper
).
getDOMNode
();
...
...
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