Skip to content
This repository was archived by the owner on Jan 15, 2021. It is now read-only.

Commit a472504

Browse files
committed
Merge branch 'develop' of github.com:gnosis/dex-react into develop
2 parents a571df4 + cb86349 commit a472504

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+64637
-283
lines changed

build/__snowpack__/env.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {"MODE":"production","NODE_ENV":"production","SSR":false};

cypress.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"baseUrl": "http://localhost:8080",
3-
"projectId": "digs58"
3+
"projectId": "digs58",
4+
"defaultCommandTimeout": 10000
45
}

cypress/integration/about.test.ts

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
describe('About', () => {
2-
beforeEach(() => {
3-
cy.visit('/about')
2+
it('Navigates from link in the footer', () => {
3+
// GIVEN: At home page, scrolled to the bottom
4+
cy.visitApp('/')
5+
cy.scrollTo('bottom')
6+
7+
// WHEN: Click on the "About" link in the footer
8+
cy.get('footer').contains('About').click()
9+
10+
// THEN: We navigate to the about page
11+
cy.url().should('contain', '/about')
412
})
5-
it('Does not do much!', () => {
6-
expect(true).to.equal(true)
13+
14+
it('Navigates using URL', () => {
15+
// GIVEN: about page
16+
cy.visitApp('/about')
17+
18+
// WHEN: -
19+
// THEN: There's the heading we expect
20+
cy.get('main h1:first').contains('About Gnosis Protocol Web')
721
})
822
})

cypress/support/commands.js

+16-25
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
1-
// ***********************************************
2-
// This example commands.js shows you how to
3-
// create various custom commands and overwrite
4-
// existing commands.
5-
//
6-
// For more comprehensive examples of custom
7-
// commands please read more here:
8-
// https://on.cypress.io/custom-commands
9-
// ***********************************************
10-
//
11-
//
12-
// -- This is a parent command --
13-
// Cypress.Commands.add("login", (email, password) => { ... })
14-
//
15-
//
16-
// -- This is a child command --
17-
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
18-
//
19-
//
20-
// -- This is a dual command --
21-
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
22-
//
23-
//
24-
// -- This will overwrite an existing command --
25-
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
1+
/**
2+
* Substitute for "visit" command. The original visit command should not be used, when the tests depend on the
3+
* scroll, because cypress has an issue with "scroll-behaviour: smooth"
4+
*
5+
* See https://github.com/cypress-io/cypress/issues/3200#issuecomment-672788861
6+
*
7+
* @example cy.visitApp('/about')
8+
*/
9+
Cypress.Commands.add('visitApp', (url) => {
10+
cy.visit(url)
11+
cy.document().then((document) => {
12+
const node = document.createElement('style')
13+
node.innerHTML = 'html { scroll-behavior: inherit !important; }'
14+
document.body.appendChild(node)
15+
})
16+
})

cypress/support/index.d.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference types="cypress" />
2+
3+
declare namespace Cypress {
4+
interface Chainable {
5+
/**
6+
* Substitute for "visit" command. The original visit command should not be used, when the tests depend on the
7+
* scroll, because cypress has an issue with "scroll-behaviour: smooth
8+
*
9+
* See https://github.com/cypress-io/cypress/issues/3200#issuecomment-672788861
10+
*
11+
* @example cy.visitApp('/about')
12+
*/
13+
visitApp(url: string): Chainable<Element>
14+
}
15+
}

empty.webpack.config

Whitespace-only changes.

output.js

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
const { chromium } = require('playwright')
2+
// const Web3 = require('web3')
3+
const webpack = require('webpack')
4+
const path = require('path')
5+
const compiler = webpack({
6+
entry: './playwright/inject_provider.js',
7+
output: {
8+
path: path.resolve(__dirname, './playwright/build/'),
9+
filename: 'inject_provider.js',
10+
},
11+
cache: true,
12+
})
13+
14+
;(async () => {
15+
await new Promise((resolve, reject) => {
16+
compiler.run((error, stats) => {
17+
if (error) {
18+
return reject(error)
19+
}
20+
21+
resolve(stats)
22+
})
23+
})
24+
const browser = await chromium.launch({
25+
headless: false,
26+
})
27+
const context = await browser.newContext()
28+
29+
// Open new page
30+
const page = await context.newPage()
31+
32+
// window.ethereum = {
33+
// request(request) {
34+
// if (request.method === 'eth_accounts') return [account]
35+
36+
// if (request.method === 'eth_chainId') return '0x4'
37+
// },
38+
// enable() {
39+
// return [account]
40+
// },
41+
// }
42+
43+
await page.addInitScript({
44+
path: './playwright/init/inject_provider.js',
45+
})
46+
47+
await page.addInitScript((pk) => {
48+
// async function injectProvider() {
49+
// await import('https://unpkg.com/[email protected]/dist/web3.min.js')
50+
// /** @type typeof import('web3').default */
51+
// const Web3 = window.Web3
52+
// const web3 = new Web3('https://rinkeby.infura.io/v3/3c9b697bcf414df8b2e59f7f5523a93a')
53+
// web3.eth.accounts.wallet.add(pk)
54+
55+
// window.web3 = web3
56+
// window.ethereum = web3.currentProvider
57+
// // window.ethereum = new HDWalletProvider({
58+
// // privateKeys: [pk],
59+
// // providerOrUrl: 'https://rinkeby.infura.io/v3/4bf032f2d38a4ed6bb975b80d6340847',
60+
// // })
61+
// }
62+
// injectProvider()
63+
64+
window.injectProvider({
65+
pk,
66+
url: 'https://rinkeby.infura.io/v3/3c9b697bcf414df8b2e59f7f5523a93a',
67+
})
68+
}, '0xad20c82497421e9784f18460ad2fe84f73569068e98e270b3e63743268af5763')
69+
70+
// Go to http://localhost:8081/
71+
await page.goto('http://localhost:8081/')
72+
73+
// Go to http://localhost:8081/trade/USDC-DAI?sell=0&price=0
74+
await page.goto('http://localhost:8081/trade/USDC-DAI?sell=0&price=0')
75+
76+
// Go to http://localhost:8081/trade/USDC-DAI?sell=0&price=0&from=&expires=
77+
await page.goto('http://localhost:8081/trade/USDC-DAI?sell=0&price=0&from=&expires=')
78+
79+
// Click text=/.*Connect Wallet.*/
80+
await page.click('text=/.*Connect Wallet.*/')
81+
82+
await page.click('text=/.*Web3.*/')
83+
// Close page
84+
// await page.close()
85+
86+
// // ---------------------
87+
// await context.close()
88+
// await browser.close()
89+
})()

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"docs": "start-storybook --docs",
2929
"build-docs": "build-storybook --docs",
3030
"check-types": "tsc --noEmit --incremental",
31-
"cypress": "cypress open",
31+
"cypress": "CYPRESS_BASE_URL=http://localhost:8081 cypress open",
32+
"cypress:dev": "cypress open",
3233
"cypress:run": "cypress run"
3334
},
3435
"husky": {

playwright/init/inject_provider.js

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

playwright/inject_provider.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import HDWalletProvider from '@truffle/hdwallet-provider'
2+
3+
const pk = '0xad20c82497421e9784f18460ad2fe84f73569068e98e270b3e63743268af5763'
4+
5+
// window.ethereum = new HDWalletProvider({
6+
// privateKeys: [pk],
7+
// providerOrUrl: 'https://rinkeby.infura.io/v3/3c9b697bcf414df8b2e59f7f5523a93a',
8+
// })
9+
10+
window.injectProvider = ({ pk, url }) => {
11+
const provider = new HDWalletProvider({
12+
privateKeys: [pk],
13+
providerOrUrl: url,
14+
})
15+
16+
provider.enable = () => {}
17+
18+
window.ethereum = provider
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { chromium, ChromiumBrowser, Page } from 'playwright'
2+
let browser: ChromiumBrowser
3+
let page: Page
4+
5+
const baseURL = process.env.BASE_URL || 'http://localhost:8080 '
6+
const isDebug = !!process.env.PWDEBUG
7+
let slowMo: number | undefined = undefined
8+
9+
if (isDebug) {
10+
// timeout to have time to look around in the browser
11+
jest.setTimeout(15000)
12+
// slow down playright actions
13+
slowMo = 2000
14+
} else {
15+
// close after only when not debugging
16+
afterAll(() => browser.close())
17+
afterEach(() => page.close())
18+
}
19+
20+
beforeAll(async () => {
21+
// launch chrome,headless by default
22+
browser = await chromium.launch({ slowMo })
23+
})
24+
beforeEach(async () => {
25+
// new page per test
26+
page = await browser.newPage()
27+
})
28+
29+
describe('About', () => {
30+
it('Page has expected title', async () => {
31+
// GIVEN: At home page
32+
await page.goto(baseURL)
33+
34+
// THEN: page has title
35+
expect(await page.title()).toBe('Gnosis Protocol Web')
36+
})
37+
})

0 commit comments

Comments
 (0)