-
-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests fir initial scroll position after init
- Loading branch information
Showing
9 changed files
with
201 additions
and
7 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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
declare module '@~local/playwright-tooling' { | ||
export function playwrightRollup(useEsbuild?: boolean): void; | ||
export interface PlaywrightRollupOptions { | ||
useEsbuild?: boolean; | ||
adaptUrl?: (originalUrl: string) => string; | ||
} | ||
export function playwrightRollup(options?: PlaywrightRollupOptions): void; | ||
export function expectSuccess(page: any): Promise<void>; | ||
} |
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
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
25 changes: 25 additions & 0 deletions
25
...s/overlayscrollbars/test/playwright/setups/structureSetup/initScroll/handleEnvironment.ts
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,25 @@ | ||
import { addClass } from '~/support'; | ||
|
||
{ | ||
const { body } = document; | ||
const url = new URL(window.location.toString()); | ||
const params = url.searchParams; | ||
|
||
/** | ||
* vpt: viewport is target | ||
* vps: viewport is element with valid scroll | ||
* vp: viewport is element without valid scroll | ||
*/ | ||
['vpt', 'vps', 'vp'].forEach((param) => { | ||
const paramValue = Boolean(params.get(param)); | ||
|
||
if (paramValue) { | ||
addClass(body, param); | ||
} else { | ||
document.getElementById(param)?.addEventListener('click', () => { | ||
params.set(param, 'true'); | ||
window.location.assign(url.toString()); | ||
}); | ||
} | ||
}); | ||
} |
65 changes: 65 additions & 0 deletions
65
packages/overlayscrollbars/test/playwright/setups/structureSetup/initScroll/index.browser.ts
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,65 @@ | ||
import '~/index.scss'; | ||
import './index.scss'; | ||
import './handleEnvironment'; | ||
import { OverlayScrollbars } from '~/overlayscrollbars'; | ||
import { setTestResult, timeout } from '@~local/browser-testing'; | ||
import should from 'should'; | ||
import { hasClass } from '~/support'; | ||
|
||
const targetElm: HTMLDivElement | null = document.querySelector('#target'); | ||
const viewportElm: HTMLDivElement | null = document.querySelector('#viewport'); | ||
const startBtn: HTMLButtonElement | null = document.querySelector('#start'); | ||
|
||
startBtn?.addEventListener('click', async () => { | ||
setTestResult(null); | ||
|
||
try { | ||
await timeout(1000); | ||
|
||
const viewportIsTarget = hasClass(document.body, 'vpt'); | ||
const scrollableViewort = hasClass(document.body, 'vps'); | ||
const notScrollableViewport = hasClass(document.body, 'vp'); | ||
const originaScrollElement = scrollableViewort ? viewportElm : targetElm; | ||
|
||
const originalScrollLeft = originaScrollElement!.scrollLeft; | ||
const originalScrollTop = originaScrollElement!.scrollTop; | ||
|
||
should.ok(originalScrollLeft > 0, 'Original ScrollLeft is expected to be > 0.'); | ||
should.ok(originalScrollTop > 0, 'Original ScrollTop is expected to be > 0.'); | ||
|
||
const osInstance = OverlayScrollbars( | ||
{ | ||
target: targetElm!, | ||
elements: { | ||
viewport: viewportIsTarget | ||
? targetElm! | ||
: (scrollableViewort || notScrollableViewport) && viewportElm, | ||
}, | ||
}, | ||
{} | ||
); | ||
|
||
const { scrollOffsetElement } = osInstance.elements(); | ||
const initScrollLeft = scrollOffsetElement.scrollLeft; | ||
const initScrollTop = scrollOffsetElement.scrollTop; | ||
|
||
should.ok(initScrollLeft > 0, 'Init ScrollLeft is expected to be > 0.'); | ||
should.ok(initScrollTop > 0, 'Init ScrollTop is expected to be > 0.'); | ||
|
||
const { scrollbarsSize } = OverlayScrollbars.env(); | ||
|
||
should.ok( | ||
Math.abs(originalScrollLeft - initScrollLeft - scrollbarsSize.x) <= 1, | ||
'Original and Init ScrollLeft should be about the same.' | ||
); | ||
should.ok( | ||
Math.abs(originalScrollTop - initScrollTop - scrollbarsSize.y) <= 1, | ||
'Original and Init ScrollTop should be about the same.' | ||
); | ||
|
||
setTestResult(true); | ||
} catch (exception) { | ||
setTestResult(false); | ||
throw exception; | ||
} | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/overlayscrollbars/test/playwright/setups/structureSetup/initScroll/index.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,18 @@ | ||
<div id="controls"> | ||
<button id="vpt">Viewport is target</button> | ||
<button id="vps">Viewport is scrollable</button> | ||
<button id="vp">Viewport is not scrollbar</button> | ||
<br /> | ||
<button id="start">start</button> | ||
</div> | ||
<div id="stage"> | ||
<div> | ||
<div id="target"> | ||
<div id="viewport"> | ||
<div id="element"> | ||
<p id="hi">hi</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
41 changes: 41 additions & 0 deletions
41
packages/overlayscrollbars/test/playwright/setups/structureSetup/initScroll/index.scss
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,41 @@ | ||
body { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
#controls { | ||
flex: none; | ||
} | ||
#stage { | ||
flex: auto; | ||
position: relative; | ||
|
||
& > div { | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
background: lightgoldenrodyellow; | ||
} | ||
} | ||
|
||
#target, | ||
body.vps #viewport { | ||
overflow: auto; | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
} | ||
|
||
#element { | ||
margin-top: 200vh; | ||
margin-left: 200vw; | ||
} | ||
|
||
#hi { | ||
display: inline-block; | ||
margin: 0; | ||
padding: 0; | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/overlayscrollbars/test/playwright/setups/structureSetup/initScroll/index.test.ts
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,31 @@ | ||
import { playwrightRollup, expectSuccess } from '@~local/playwright-tooling'; | ||
import { test } from '@playwright/test'; | ||
|
||
playwrightRollup({ | ||
adaptUrl: (originalUrl) => { | ||
const url = new URL(originalUrl); | ||
url.hash = '#hi'; | ||
return url.href; | ||
}, | ||
}); | ||
|
||
test.describe('StructureSetup.initScroll', () => { | ||
test('default', async ({ page }) => { | ||
await expectSuccess(page); | ||
}); | ||
|
||
test('viewport with scrollable overflow', async ({ page }) => { | ||
await page.click('#vps'); | ||
await expectSuccess(page); | ||
}); | ||
|
||
test('viewport without scrollable overflow', async ({ page }) => { | ||
await page.click('#vp'); | ||
await expectSuccess(page); | ||
}); | ||
|
||
test('viewport is target', async ({ page }) => { | ||
await page.click('#vpt'); | ||
await expectSuccess(page); | ||
}); | ||
}); |