Skip to content

Commit 71e1576

Browse files
authored
Merge pull request #372 from onflow/setup_cypress_tests_for_flow_playground
implement cypress tests for flow-playground frontend
2 parents b02d74d + fb3ad2b commit 71e1576

24 files changed

+2287
-301
lines changed

.env.local

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ GA_TRACKING_CODE=""
44
MIXPANEL_TOKEN=""
55
DEFAULT_SEO_IMAGE=""
66
SENTRY_DSN=""
7+
CYPRESS_RECORD_KEY=""

.github/workflows/ci.yml

+48-11
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
name: Continuous Integration
22

33
on:
4+
pull_request:
5+
branches:
6+
- master
7+
- staging
48
push:
5-
6-
env:
7-
PLAYGROUND_API: ''
8-
AVATAAR_URL: ''
9-
GA_TRACKING_CODE: ''
10-
MIXPANEL_TOKEN: ''
11-
DEFAULT_SEO_IMAGE: ''
12-
SENTRY_DSN: ''
9+
branches:
10+
- master
11+
- staging
1312

1413
jobs:
15-
test:
16-
name: 'Tests'
14+
tests:
15+
name: 'Linter and Unit Tests'
1716
runs-on: ubuntu-latest
1817
strategy:
1918
matrix:
20-
node-version: [15.x]
19+
node-version: [16.x]
2120

2221
steps:
2322
- uses: actions/checkout@v2
@@ -26,3 +25,41 @@ jobs:
2625
with:
2726
node-version: ${{ matrix.node-version }}
2827
- run: make ci
28+
29+
cypress-e2e:
30+
name: Cypress Emulator Tests for Flow-Playground
31+
timeout-minutes: 10
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v2
36+
37+
- name: Use Node.js ${{ matrix.node-version }}
38+
uses: actions/setup-node@v3
39+
with:
40+
node-version: ${{ matrix.node-version }}
41+
42+
- name: Install dependencies
43+
run: npm install
44+
45+
- name: Spin up docker backend
46+
run: npm run start-docker
47+
48+
- name: Cypress run emulator
49+
uses: cypress-io/github-action@v4
50+
with:
51+
start: npm run start
52+
wait-on: http://localhost:3000
53+
spec: cypress/e2e/playground.cy.ts
54+
record: true
55+
browser: chrome
56+
env:
57+
PLAYGROUND_API: 'http://localhost:8080'
58+
CYPRESS_RECORD_KEY: '${{ secrets.CYPRESS_RECORD_KEY }}'
59+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
60+
61+
- uses: actions/upload-artifact@v3
62+
if: always()
63+
with:
64+
name: cypress-videos
65+
path: cypress/videos

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ yarn-error.log*
2323

2424

2525
.idea
26+
27+
# tests
28+
cypress/videos
29+
cypress/screenshots

cypress.config.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { defineConfig } from "cypress";
2+
3+
export default defineConfig({
4+
projectId: "h1jieb",
5+
defaultCommandTimeout: 10000,
6+
viewportWidth: 1536,
7+
viewportHeight: 960,
8+
chromeWebSecurity: false,
9+
e2e: {
10+
setupNodeEvents() {},
11+
baseUrl: 'http://localhost:3000/',
12+
specPattern: 'cypress/e2e/**/*.cy.{js,ts,jsx,tsx}',
13+
excludeSpecPattern: ['**/__snapshots__/*', '**/__image_snapshots__/*'],
14+
},
15+
});

cypress/e2e/playground.cy.ts

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
describe('Flow-Playground frontend tests', () => {
2+
const DEPLOY_BUTTON = '[data-test="deploy-button"]';
3+
const EXECUTE = '[data-test="execute-button"]';
4+
const SEND_BUTTON = '[data-test="send-button"]';
5+
const ACCOUNTS_LIST = '[data-test="account-list"]';
6+
const MONACO_EDITOR = '.monaco-editor textarea:first';
7+
const STATUS_MESSAGE = '[data-test="control-panel-status-message"]';
8+
const selectAllKeys = Cypress.platform == 'darwin' ? '{cmd}a' : '{ctrl}a';
9+
10+
beforeEach(() => {
11+
cy.visit('/');
12+
});
13+
14+
it('deploys a contract', () => {
15+
cy.get(ACCOUNTS_LIST).children().should('have.length', 5).first().click();
16+
cy.get(DEPLOY_BUTTON).should('have.text', 'Deploy').click();
17+
cy.get(STATUS_MESSAGE).should('have.text', 'Please wait...');
18+
cy.get(DEPLOY_BUTTON).should('have.text', 'Redeploy');
19+
cy.get('[data-test="CONTRACT-response"]').should(
20+
'include.text',
21+
'Deployed Contract To: 0x01',
22+
);
23+
});
24+
25+
it('sends a transaction', () => {
26+
cy.get('[data-test="sidebar-Transaction"]').click();
27+
cy.get('[data-test="editor-heading"]').should(
28+
'include.text',
29+
'Transaction Template',
30+
);
31+
// Ensure action button is disabled when contract not deployed yet
32+
cy.get(SEND_BUTTON).should('be.disabled');
33+
34+
// deploy contract
35+
cy.get(ACCOUNTS_LIST).children().first().click();
36+
cy.get(DEPLOY_BUTTON).should('have.text', 'Deploy').click();
37+
cy.get(DEPLOY_BUTTON).should('have.text', 'Redeploy');
38+
39+
// open transaction template and successfully send transaction
40+
cy.get('[data-test="sidebar-Transaction"]').click();
41+
cy.get(SEND_BUTTON)
42+
.should('have.text', 'Send')
43+
.should('be.enabled')
44+
.click();
45+
cy.get('[data-test="TRANSACTION-response"]').should(
46+
'include.text',
47+
'Hello, World!',
48+
);
49+
});
50+
51+
it('executes a script', () => {
52+
cy.get('[data-test="sidebar-Script"]').click();
53+
cy.get('[data-test="editor-heading"]').should(
54+
'include.text',
55+
'Script Template',
56+
);
57+
cy.get(EXECUTE).should('have.text', 'Execute').click();
58+
cy.get('[data-test="SCRIPT-response"]').should(
59+
'include.text',
60+
'{"type":"Int","value":"1"}',
61+
);
62+
});
63+
64+
it('reflects changes to imported contract after contract has been redeployed', () => {
65+
// deploy contract
66+
cy.get(ACCOUNTS_LIST).children().first().click();
67+
cy.get(DEPLOY_BUTTON).should('have.text', 'Deploy').click();
68+
cy.get(STATUS_MESSAGE).should('have.text', 'Please wait...');
69+
cy.get(DEPLOY_BUTTON).should('have.text', 'Redeploy');
70+
cy.get('[data-test="CONTRACT-response"]').should(
71+
'include.text',
72+
'Deployed Contract To: 0x01',
73+
);
74+
75+
// open transaction template and successfully send transaction
76+
cy.get('[data-test="sidebar-Transaction"]').click();
77+
cy.get(SEND_BUTTON)
78+
.should('have.text', 'Send')
79+
.should('be.enabled')
80+
.click();
81+
cy.get('[data-test="TRANSACTION-response"]').should(
82+
'include.text',
83+
'Hello, World!',
84+
);
85+
86+
// edit contract
87+
cy.get(ACCOUNTS_LIST).children().first().click();
88+
cy.get(MONACO_EDITOR).click().focused().type(selectAllKeys).clear();
89+
cy.get(MONACO_EDITOR).should('be.empty');
90+
cy.get(DEPLOY_BUTTON).should('be.disabled');
91+
cy.get(MONACO_EDITOR)
92+
.click()
93+
.focused()
94+
.type(
95+
'access(all) contract HelloWorld { access(all) let greeting: String init() { self.greeting = "Hello, Other World!" } access(all) fun other_hello(): String {return self.greeting}}',
96+
{ parseSpecialCharSequences: false },
97+
);
98+
cy.get(DEPLOY_BUTTON).should('be.enabled');
99+
cy.get(DEPLOY_BUTTON).should('have.text', 'Redeploy').click();
100+
cy.get('[data-test="redeploy-confirm-button"]').should('exist').click();
101+
cy.get(STATUS_MESSAGE).should('have.text', 'Please wait...');
102+
cy.get(DEPLOY_BUTTON).should('have.text', 'Redeploy');
103+
cy.get(DEPLOY_BUTTON).should('be.enabled');
104+
105+
// select and edit transaction
106+
cy.get('[data-test="sidebar-Transaction"]').click();
107+
cy.get(SEND_BUTTON).should('have.text', 'Send').should('be.disabled');
108+
cy.get(MONACO_EDITOR)
109+
.click()
110+
.focused()
111+
.type(selectAllKeys)
112+
.type(
113+
'import HelloWorld from 0x01 transaction { prepare(acct: AuthAccount) {} execute { log(HelloWorld.other_hello())}}',
114+
{ parseSpecialCharSequences: false },
115+
);
116+
117+
// successfully send transaction
118+
cy.get(SEND_BUTTON)
119+
.should('have.text', 'Send')
120+
.should('be.enabled')
121+
.click();
122+
cy.get('[data-test="transaction-result"]').should(
123+
'include.text',
124+
'Hello, Other World!',
125+
);
126+
});
127+
});

cypress/fixtures/example.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "[email protected]",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}

cypress/support/commands.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************
3+
// This example commands.ts shows you how to
4+
// create various custom commands and overwrite
5+
// existing commands.
6+
//
7+
// For more comprehensive examples of custom
8+
// commands please read more here:
9+
// https://on.cypress.io/custom-commands
10+
// ***********************************************
11+
//
12+
//
13+
// -- This is a parent command --
14+
// Cypress.Commands.add('login', (email, password) => { ... })
15+
//
16+
//
17+
// -- This is a child command --
18+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
19+
//
20+
//
21+
// -- This is a dual command --
22+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
23+
//
24+
//
25+
// -- This will overwrite an existing command --
26+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
27+
//
28+
// declare global {
29+
// namespace Cypress {
30+
// interface Chainable {
31+
// login(email: string, password: string): Chainable<void>
32+
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
33+
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
34+
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
35+
// }
36+
// }
37+
// }

cypress/support/e2e.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/e2e.ts is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands';
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

0 commit comments

Comments
 (0)