-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix race conditions and add tests (#85)
* Fix race conditions and add tests * Move to main branch * Publish to "main" dist tag * Add entry
- Loading branch information
Showing
103 changed files
with
70,441 additions
and
7,120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* | ||
!/__tests__ | ||
!/Dockerfile | ||
!/packages/component/dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
/.env | ||
/chromedriver* | ||
/coverage | ||
/lerna-debug.log | ||
/lib | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM node:alpine | ||
|
||
EXPOSE 80 | ||
RUN npm install serve -g | ||
WORKDIR /var/web/ | ||
ENTRYPOINT ["npx", "--no-install", "serve", "-c", "serve.json", "-p", "80", "/var/web/"] | ||
|
||
RUN echo {}>/var/web/package.json | ||
|
||
ADD __tests__/*.html /var/web/ | ||
ADD __tests__/assets/ /var/web/assets/ | ||
ADD __tests__/favicon.ico /var/web/ | ||
ADD __tests__/serve.json /var/web/ | ||
ADD packages/component/dist/ /var/web/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
body, | ||
html { | ||
height: 100%; | ||
} | ||
|
||
body { | ||
align-items: center; | ||
background: #f7f7f7; | ||
display: flex; | ||
justify-content: center; | ||
margin: 0; | ||
} | ||
|
||
.react-scroll-to-bottom { | ||
background: White; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); | ||
height: 640px; | ||
width: 360px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class PageObjects { | ||
async mouseWheel(deltaY) { | ||
const scrollable = document.getElementsByClassName('scrollable')[0]; | ||
const { height, left, top, width } = scrollable.getBoundingClientRect(); | ||
|
||
await webDriver.sendDevToolsCommand('Input.dispatchMouseEvent', { | ||
deltaX: 0, | ||
deltaY, | ||
type: 'mouseWheel', | ||
x: left + width / 2, | ||
y: top + height / 2 | ||
}); | ||
} | ||
|
||
paragraphs = [ | ||
'Tempor id consectetur ex non irure aliquip ea irure sint voluptate et. Magna aute reprehenderit amet dolor laboris. Adipisicing aliqua officia tempor magna aliqua commodo proident.', | ||
'Ad aute esse dolor in veniam reprehenderit labore et. Et dolor sint proident dolor. Aliquip amet duis laboris laboris dolor proident sit adipisicing enim dolore elit dolore.', | ||
'Consectetur irure qui excepteur voluptate et exercitation. Nostrud sint officia ipsum qui duis do. Amet veniam ipsum tempor anim ad voluptate commodo quis exercitation. Consectetur et laborum Lorem cillum aliquip quis duis est officia culpa consequat nostrud ex. Officia dolore mollit irure aliquip aliquip minim dolor eiusmod et magna.', | ||
'Proident aliquip culpa aliquip esse cupidatat incididunt voluptate pariatur ullamco ea aute cupidatat. Ex fugiat mollit sunt duis elit aliqua cupidatat officia. Laborum magna dolor non ea aliquip tempor. Sunt voluptate sint minim elit eu eiusmod. Dolor nisi qui enim excepteur ut non elit enim deserunt consectetur in quis. Aute et incididunt sunt est do.', | ||
'Cillum qui adipisicing culpa laborum eu. Amet qui duis sunt qui magna fugiat culpa. Sit ea amet do sint.', | ||
'Laboris nulla esse duis fugiat mollit duis consequat incididunt anim eiusmod. Esse labore eiusmod sint culpa Lorem in cupidatat duis. Do et proident irure commodo ut ut reprehenderit ut esse deserunt minim occaecat sunt. Consequat in elit amet labore quis deserunt.', | ||
'Tempor esse enim cupidatat tempor amet. Sint esse ad consectetur quis minim aliquip. Eiusmod consectetur tempor occaecat deserunt officia enim tempor anim incididunt. Irure duis ad laboris anim. Ullamco reprehenderit voluptate adipisicing excepteur duis id magna quis ex aliqua minim magna minim occaecat.', | ||
'In consequat ea irure officia enim adipisicing. Laboris excepteur incididunt ad in. Dolor mollit occaecat sunt elit minim commodo est incididunt sit reprehenderit commodo. Sit magna duis minim elit irure velit culpa dolor. Minim culpa nisi et fugiat. In est dolore anim sunt est minim qui sunt mollit commodo id qui non duis. Commodo occaecat occaecat eu cupidatat nostrud nulla ad mollit reprehenderit.', | ||
'Adipisicing ex sint adipisicing irure ut consectetur nisi consectetur enim qui cillum nostrud. Ullamco adipisicing excepteur proident qui amet eiusmod aute Lorem voluptate eiusmod ullamco. Ex non laborum incididunt nulla ad.' | ||
]; | ||
|
||
async scrollStabilized() { | ||
await stabilized('scroll', () => document.getElementsByClassName('scrollable')[0].scrollTop, 5, 5000); | ||
} | ||
|
||
async scrollStabilizedAt(message, offset) { | ||
await stabilized( | ||
message, | ||
() => { | ||
const scrollable = document.getElementsByClassName('scrollable')[0]; | ||
|
||
return Math.abs(scrollable.scrollTop - offset) <= 1 ? scrollable.scrollTop : {}; | ||
}, | ||
5, | ||
5000 | ||
); | ||
} | ||
|
||
async scrollStabilizedAtBottom() { | ||
const scrollable = document.getElementsByClassName('scrollable')[0]; | ||
|
||
await this.scrollStabilizedAt('scroll is at bottom', scrollable.scrollHeight - scrollable.clientHeight); | ||
} | ||
|
||
async scrollStabilizedAtTop() { | ||
await this.scrollStabilizedAt('scroll is at top', 0); | ||
} | ||
} | ||
|
||
window.pageObjects || (window.pageObjects = new PageObjects()); |
47 changes: 47 additions & 0 deletions
47
__tests__/click-follow-button-should-scroll-to-bottom.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title></title> | ||
<link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script> | ||
<script src="/react-scroll-to-bottom.development.js"></script> | ||
<script src="/test-harness.js"></script> | ||
<script src="/assets/page-object-model.js"></script> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
</body> | ||
<script type="text/babel" data-presets="react"> | ||
'use strict'; | ||
|
||
run(async function () { | ||
await new Promise(resolve => | ||
ReactDOM.render( | ||
<ReactScrollToBottom.default | ||
className="react-scroll-to-bottom" | ||
followButtonClassName="follow" | ||
scrollViewClassName="scrollable" | ||
> | ||
{pageObjects.paragraphs.map(paragraph => ( | ||
<p key={paragraph}>{paragraph}</p> | ||
))} | ||
</ReactScrollToBottom.default>, | ||
document.getElementById('app'), | ||
resolve | ||
) | ||
); | ||
|
||
await pageObjects.scrollStabilizedAtBottom(); | ||
|
||
expect(document.getElementsByClassName('follow')[0]).toBeFalsy(); | ||
|
||
await pageObjects.mouseWheel(-100); | ||
|
||
await pageObjects.scrollStabilized(); | ||
|
||
await webDriver.click(document.getElementsByClassName('follow')[0]); | ||
|
||
await pageObjects.scrollStabilized(); | ||
}); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/** @jest-environment ./packages/test-harness/JestEnvironment */ | ||
|
||
test('click follow button should scroll to bottom', () => runHTML('click-follow-button-should-scroll-to-bottom.html')); |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title></title> | ||
<link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script> | ||
<script src="/react-scroll-to-bottom.development.js"></script> | ||
<script src="/test-harness.js"></script> | ||
<script src="/assets/page-object-model.js"></script> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
</body> | ||
<script type="text/babel" data-presets="react"> | ||
'use strict'; | ||
|
||
run(async function () { | ||
await new Promise(resolve => | ||
ReactDOM.render( | ||
<ReactScrollToBottom.default | ||
className="react-scroll-to-bottom" | ||
followButtonClassName="follow" | ||
scrollViewClassName="scrollable" | ||
> | ||
{pageObjects.paragraphs.map(paragraph => ( | ||
<p key={paragraph}>{paragraph}</p> | ||
))} | ||
</ReactScrollToBottom.default>, | ||
document.getElementById('app'), | ||
resolve | ||
) | ||
); | ||
|
||
await pageObjects.scrollStabilizedAtBottom(); | ||
|
||
expect(document.getElementsByClassName('follow')[0]).toBeFalsy(); | ||
|
||
await pageObjects.mouseWheel(-100); | ||
|
||
await pageObjects.scrollStabilized(); | ||
|
||
expect(document.getElementsByClassName('follow')[0]).toBeTruthy(); | ||
}); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/** @jest-environment ./packages/test-harness/JestEnvironment */ | ||
|
||
test('scroll up should show follow button', () => runHTML('scroll-up-should-show-follow-button.html')); |
Oops, something went wrong.