Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
test: refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpa9708 committed Jan 12, 2019
1 parent ef1d5b5 commit 1dcc05a
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 24 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ webpack.config.js
.prettierignore
.prettierrc
tslint.json
cypress
13 changes: 13 additions & 0 deletions cypress/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as ScrollUtility from "../"

function takeScreenShot(delay: number = 0) {
cy.wait(delay).then(() => cy.screenshot("basic", { capture: "viewport" }))
}

function withWindow<T = void>(f: (window: Window & { ScrollUtility: typeof ScrollUtility }) => T) {
cy.window().then(wind => {
f(wind as Window & { ScrollUtility: typeof ScrollUtility })
})
}

export { withWindow, takeScreenShot }
Binary file removed cypress/screenshots/custom.ts/basic.png
Binary file not shown.
22 changes: 22 additions & 0 deletions cypress/tests/basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { withWindow } from "../common"

context("Basic", () => {
beforeEach(() => {
cy.visit("http://localhost:8080")
})
it("should have ScrollUtility defined", () => {
cy.window().should("have.property", "ScrollUtility")
})
it("should scroll", () => {
withWindow(window => {
const scrollManager = new window.ScrollUtility.Scroll()
const element = window.document.querySelector("#scrollable")
scrollManager.scrollBy(scrollManager.misc.getDistToElement(element!), 1000)
scrollManager.scrollBy(scrollManager.misc.getDistToElement(element!), 1000, true)
window.setTimeout(() => {
scrollManager.scrollBy(scrollManager.misc.getDistToElement(element!), 0)
scrollManager.scrollBy(scrollManager.misc.getDistToElement(element!, 0, true), 0, true)
}, 1000)
})
})
})
24 changes: 0 additions & 24 deletions cypress/tests/custom.ts

This file was deleted.

14 changes: 14 additions & 0 deletions cypress/tests/misc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { withWindow } from "../common"

context("Misc", () => {
before(() => {
cy.visit("http://localhost:8080")
})
beforeEach(() => {
withWindow(window => {
const windowScrollManager = window.ScrollUtility.default
windowScrollManager.misc.scrollTo(0, 0, false)
windowScrollManager.misc.scrollTo(0, 0, true)
})
})
})

0 comments on commit 1dcc05a

Please sign in to comment.