-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from arifulbgt4/wip/test-puppeteer
Wip/test puppeteer
- Loading branch information
Showing
7 changed files
with
685 additions
and
25 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,6 @@ | ||
module.exports = { | ||
launch: { | ||
headless: false, | ||
slowMo: 300, | ||
}, | ||
}; |
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,11 @@ | ||
module.exports = { | ||
preset: 'jest-puppeteer', | ||
globals: { | ||
URL: 'http://localhost:3000', | ||
}, | ||
testMatch: ['**/specs/*.js'], | ||
transform: { | ||
'\\.js$': 'react-scripts/config/jest/babelTransform', | ||
}, | ||
verbose: true, | ||
}; |
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 @@ | ||
const mouse = page.mouse; | ||
|
||
export const clientXY = async (selector) => | ||
await page.$eval(selector, (e) => [e.offsetLeft, e.offsetTop]); | ||
|
||
export const moveDown = async (x, y) => { | ||
await mouse.move(x, y); | ||
await mouse.down(); | ||
}; | ||
|
||
export const moveUp = async (x, y) => { | ||
await mouse.move(x, y); | ||
await mouse.up(); | ||
}; |
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,67 @@ | ||
import { clientXY, moveDown, moveUp } from '../pageObjects'; | ||
|
||
const NODE_SELECT_ONE = 'div.sidebar div:nth-child(1)'; | ||
const NODE_SELECT_TWO = 'div.sidebar div:nth-child(2)'; | ||
|
||
const NODE_DELETE_BUTTON = 'div.toolbar'; | ||
|
||
describe('Wireflow', () => { | ||
beforeAll(async () => { | ||
await page.goto(URL); | ||
await page.setViewport({ width: 1280, height: 800 }); | ||
}); | ||
|
||
const navigationPromise = page.waitForNavigation(); | ||
|
||
it('should be add node (1) on canvas', async (done) => { | ||
const [, clientY] = await clientXY(NODE_SELECT_ONE); | ||
|
||
await moveDown(70, clientY + 30); | ||
await moveUp(200, 200); | ||
|
||
await navigationPromise; | ||
|
||
done(); | ||
}); | ||
|
||
it('should be add node (2) on canvas', async (done) => { | ||
const [, clientY] = await clientXY(NODE_SELECT_TWO); | ||
|
||
await moveDown(70, clientY + 30); | ||
await moveUp(400, 400); | ||
|
||
await navigationPromise; | ||
|
||
done(); | ||
}); | ||
|
||
it('should be add edge between two nodes', async (done) => { | ||
await moveDown(210, 210); | ||
await page.mouse.up(); | ||
|
||
await navigationPromise; | ||
|
||
await moveDown(200, 250); | ||
await page.mouse.move(300, 200); | ||
await moveUp(400, 450); | ||
|
||
await navigationPromise; | ||
|
||
done(); | ||
}); | ||
|
||
it('should be delete node (1) from canvas', async () => { | ||
const [x, y] = await clientXY(NODE_DELETE_BUTTON); | ||
|
||
await moveDown(210, 210); | ||
await page.mouse.up(); | ||
|
||
await navigationPromise; | ||
|
||
await page.mouse.click(x + 10, y + 15); | ||
|
||
await page.waitFor(2000); | ||
|
||
await navigationPromise; | ||
}); | ||
}); |
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,6 @@ | ||
// jest-dom adds custom jest matchers for asserting on DOM nodes. | ||
// allows you to do things like: | ||
// expect(element).toHaveTextContent(/react/i) | ||
// learn more: https://github.com/testing-library/jest-dom | ||
|
||
import '@testing-library/jest-dom/extend-expect'; |
Oops, something went wrong.