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
38e4d947
Commit
38e4d947
authored
Jan 26, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Jan 26, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate adder to TS
parent
d883b0b0
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
117 deletions
+95
-117
adder.tsx
src/annotator/adder.tsx
+85
-102
adder-test.js
src/annotator/test/adder-test.js
+10
-15
No files found.
src/annotator/adder.
js
→
src/annotator/adder.
tsx
View file @
38e4d947
This diff is collapsed.
Click to expand it.
src/annotator/test/adder-test.js
View file @
38e4d947
import
{
act
}
from
'preact/test-utils'
;
import
{
mount
}
from
'enzyme'
;
import
{
Adder
,
ARROW_POINTING_UP
,
ARROW_POINTING_DOWN
,
$imports
,
}
from
'../adder'
;
import
{
Adder
,
ArrowDirection
,
$imports
}
from
'../adder'
;
function
rect
(
left
,
top
,
width
,
height
)
{
return
{
left
,
top
,
width
,
height
};
...
...
@@ -199,25 +194,25 @@ describe('Adder', () => {
it
(
'positions the adder below the selection if the selection is forwards'
,
()
=>
{
const
target
=
adder
.
_calculateTarget
(
rect
(
100
,
200
,
100
,
20
),
false
);
assert
.
isAbove
(
target
.
top
,
220
);
assert
.
equal
(
target
.
arrowDirection
,
A
RROW_POINTING_
UP
);
assert
.
equal
(
target
.
arrowDirection
,
A
rrowDirection
.
UP
);
});
it
(
'positions the adder above the selection if the selection is backwards'
,
()
=>
{
const
target
=
adder
.
_calculateTarget
(
rect
(
100
,
200
,
100
,
20
),
true
);
assert
.
isBelow
(
target
.
top
,
200
);
assert
.
equal
(
target
.
arrowDirection
,
A
RROW_POINTING_
DOWN
);
assert
.
equal
(
target
.
arrowDirection
,
A
rrowDirection
.
DOWN
);
});
it
(
'does not position the adder above the top of the viewport'
,
()
=>
{
const
target
=
adder
.
_calculateTarget
(
rect
(
100
,
-
100
,
100
,
20
),
false
);
assert
.
isAtLeast
(
target
.
top
,
0
);
assert
.
equal
(
target
.
arrowDirection
,
A
RROW_POINTING_
UP
);
assert
.
equal
(
target
.
arrowDirection
,
A
rrowDirection
.
UP
);
});
it
(
'does not position the adder above the top of the viewport even when selection is backwards'
,
()
=>
{
const
target
=
adder
.
_calculateTarget
(
rect
(
100
,
-
100
,
100
,
20
),
true
);
assert
.
isAtLeast
(
target
.
top
,
0
);
assert
.
equal
(
target
.
arrowDirection
,
A
RROW_POINTING_
UP
);
assert
.
equal
(
target
.
arrowDirection
,
A
rrowDirection
.
UP
);
});
it
(
'does not position the adder below the bottom of the viewport'
,
()
=>
{
...
...
@@ -252,7 +247,7 @@ describe('Adder', () => {
});
const
target
=
adder
.
_calculateTarget
(
rect
(
100
,
200
,
100
,
20
),
true
);
assert
.
isAbove
(
target
.
top
,
220
);
assert
.
equal
(
target
.
arrowDirection
,
A
RROW_POINTING_
UP
);
assert
.
equal
(
target
.
arrowDirection
,
A
rrowDirection
.
UP
);
});
});
});
...
...
@@ -337,7 +332,7 @@ describe('Adder', () => {
describe
(
'#_showAt'
,
()
=>
{
context
(
'when the document and body elements have no offset'
,
()
=>
{
it
(
'shows adder at target position'
,
()
=>
{
adder
.
_showAt
(
100
,
100
,
A
RROW_POINTING_
UP
);
adder
.
_showAt
(
100
,
100
,
A
rrowDirection
.
UP
);
const
{
left
,
top
}
=
adderRect
();
assert
.
equal
(
left
,
100
);
...
...
@@ -355,7 +350,7 @@ describe('Adder', () => {
});
it
(
'shows adder at target position'
,
()
=>
{
adder
.
_showAt
(
100
,
100
,
A
RROW_POINTING_
UP
);
adder
.
_showAt
(
100
,
100
,
A
rrowDirection
.
UP
);
const
{
left
,
top
}
=
adderRect
();
assert
.
equal
(
left
,
100
);
...
...
@@ -373,7 +368,7 @@ describe('Adder', () => {
});
it
(
'shows adder at target position when document element is offset'
,
()
=>
{
adder
.
_showAt
(
100
,
100
,
A
RROW_POINTING_
UP
);
adder
.
_showAt
(
100
,
100
,
A
rrowDirection
.
UP
);
const
{
left
,
top
}
=
adderRect
();
assert
.
equal
(
left
,
100
);
...
...
@@ -399,7 +394,7 @@ describe('Adder', () => {
describe
(
'#hide'
,
()
=>
{
it
(
'shows the container in the correct location'
,
()
=>
{
adder
.
_showAt
(
100
,
100
,
A
RROW_POINTING_
UP
);
adder
.
_showAt
(
100
,
100
,
A
rrowDirection
.
UP
);
let
pos
=
adderRect
();
assert
.
equal
(
pos
.
left
,
100
);
...
...
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