Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

test: add footer and load safe #3802

Merged
merged 3 commits into from
May 3, 2022
Merged

test: add footer and load safe #3802

merged 3 commits into from
May 3, 2022

Conversation

francovenica
Copy link
Contributor

What it solves

Add e2e for cypress test to verify the footer and the load safe workflow

How to test it

Write the command yarn cypress:open dev
The cypress ui test selector opens
Select the files "load_safe" and "app_layout"

@github-actions
Copy link

CLA Assistant Lite All Contributors have signed the CLA.

@github-actions
Copy link

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 2 0
Warnings 0 0
Ignored 2 N/A
  • Result: ❌ failure

  • Annotations: 2 total


[failure] @typescript-eslint/no-unused-vars

Disallow unused variables


Report generated by eslint-plus-action

@coveralls
Copy link

Pull Request Test Coverage Report for Build 2197117793

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.007%) to 35.548%

Totals Coverage Status
Change from base Build 2195129238: -0.007%
Covered Lines: 3554
Relevant Lines: 9044

💛 - Coveralls

@github-actions
Copy link

Deployment links

🟠 Rinkeby Mainnet 🟣 Polygon 🟡 BSC Arbitrum 🟢 Gnosis Chain

Copy link
Member

@iamacook iamacook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work dude! More than happy to go through my suggestions with you

Comment on lines +8 to +17
cy.visit("/rin:0xFfDC1BcdeC18b1196e7FA04246295DE3A17972Ac/settings/details")
cy.get('footer').should('exist')

cy.visit("/rin:0xFfDC1BcdeC18b1196e7FA04246295DE3A17972Ac/transactions/history")
cy.get('footer').should('not.exist')

cy.visit("/rin:0xFfDC1BcdeC18b1196e7FA04246295DE3A17972Ac/balances")
cy.get('footer').should('not.exist')

cy.visit("/rin:0xFfDC1BcdeC18b1196e7FA04246295DE3A17972Ac/apps")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably best we use the generateSafeRoute function and our pre-defined route variables here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree. IMHO the dumber the better.

Comment on lines +5 to +17
cy.visit("/")
cy.get('footer').should('exist')

cy.visit("/rin:0xFfDC1BcdeC18b1196e7FA04246295DE3A17972Ac/settings/details")
cy.get('footer').should('exist')

cy.visit("/rin:0xFfDC1BcdeC18b1196e7FA04246295DE3A17972Ac/transactions/history")
cy.get('footer').should('not.exist')

cy.visit("/rin:0xFfDC1BcdeC18b1196e7FA04246295DE3A17972Ac/balances")
cy.get('footer').should('not.exist')

cy.visit("/rin:0xFfDC1BcdeC18b1196e7FA04246295DE3A17972Ac/apps")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should all begin with the PUBLIC_URL, '/app'.

cy.wait(1000) //Have to wait because clicking the switch network fails sometimes if not

//Step 1
cy.get('[data-testid="select-network-step"]').find('button').click()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use cy.findByTestId instead of cy.get('[data-testid=....

I won't mark the other instances of this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would even say to find by text whenever possible

@@ -0,0 +1,22 @@
/// <reference types="cypress" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this file? It doesn't seem to add anything and failing the linter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what I read is for the intellisense

* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
Copy link
Member

@katspaugh katspaugh Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace on with _, then it won't complain.

Edit: actually, just remove both on and config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove them to see if it still works

const { createArrayTypeNode } = require("typescript")

describe('App layout', () =>{
it('Check footer presence', () =>{
Copy link
Member

@katspaugh katspaugh Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, this functionality (which pages show the footer) is too trivial to cover.
Tests run slowly, so we need to prefer more complex scenarios to fit in a reasonable time budget.
The slowest part is loading new pages, and this test does a lot of it, just to check for the footer.

@katspaugh
Copy link
Member

There's a mix of single and double quotes, no new lines at the end of files but out linter didn't catch that.
I wonder if it ignores those files or we don't have prettier enabled on push?

const OWNER_ADDRESS = "0x6f965E48347AF3Df65c14CCc176A9CbeCEa0eDb5"

describe("Load Safe", () => {
it("Load safe", () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it('should load an existing Safe'

Comment on lines 14 to 64
it("Load safe", () => {
cy.visit("/")
cy.findByText('Accept selection').click()

cy.get('[data-track="load-safe: Open stepper"]').click()
cy.findByText('Add existing Safe').should('exist')
cy.wait(1000) //Have to wait because clicking the switch network fails sometimes if not

//Step 1
cy.get('[data-testid="select-network-step"]').find('button').click()
cy.get('[aria-labelledby="select-network"]').should('exist')
cy.findByText('Ethereum').click()
cy.get('nav').findByText('Ethereum').should('exist')
cy.get('[data-testid="select-network-step"]').findByText('Ethereum').should('exist')
cy.get('[data-testid="select-network-step"]').find('button').click()
cy.findByText('Rinkeby').click()
cy.get('[data-track="load-safe: Continue"]').click()

//Step2
cy.get('[data-testid="load-safe-name-field"]').should('have.attr', 'placeholder').should('contain','rinkeby-safe')
cy.get('[data-testid="load-safe-name-field"]').type('Test safe name').should('have.value', 'Test safe name')

cy.get('[data-testid="load-safe-address-field"]').type('RandomText')
cy.findByText(INVALID_INPUT_ERROR_MSG).should('exist')
cy.get('[data-testid="load-safe-address-field"]').clear().type(NON_CONTRACT_ADDRESS)
cy.findByText(INVALID_ADDRESS_ERROR_MSG).should('exist')
cy.get('[data-testid="load-safe-address-field"]').clear().type(SAFE_ENS_NAME).should('have.value', SAFE_ENS_NAME_TRANSLATED)
cy.get('[data-testid="qr-icon"]').click()
cy.get('[class="paper"]').find('button').contains('Upload an image').click()
cy.get('[type="file"]').attachFile('../utils/files/rinkeby_safe_QR.png')
cy.get('[data-testid="load-safe-address-field"]').should('have.value', SAFE_QR_CODE_ADDRESS)
cy.get('[data-testid="safeAddress-valid-address-adornment"]').should('exist')
cy.wait(3000) //have to wait or after clicking next what loads is the owners of the previous valids safe, not the one from the QR code
cy.get('[type="submit"]').click()

//Step3
cy.findByPlaceholderText(OWNER_ENS_DEFAULT_NAME).parents('div[data-testid="owner-row"]').findByText(OWNER_ADDRESS)
cy.findByPlaceholderText(OWNER_ENS_DEFAULT_NAME).type('Test Owner Name').should('have.value', 'Test Owner Name')
cy.get('[data-track="load-safe: Continue"]').click()

//Review Step
cy.findByText('Test safe name').should('exist')
cy.findByText('Test Owner Name').should('exist')
cy.get('[data-track="load-safe: Add"]').click()

//Safe Loaded
cy.get('[data-testid="sidebar"]').findByText('Test safe name')
cy.get('[data-testid="sidebar"]').find('nav').findByText('Settings').click()
cy.get('[data-testid="sidebar"]').find('nav').findByText('Owners').click()
cy.findByText('Test Owner Name')
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this scenario tests only the happy path.
It would be nice to also check possible input errors, Safes that don't exist (or on a diff network), adding and discarding owners, going back etc.
Doesn't need to be in the PR, just an idea for future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I check for the safe address that wrong values and address that are not safes (like mm accounts).

@DiogoSoaress
Copy link
Member

DiogoSoaress commented Apr 21, 2022

I wonder if it ignores those files or we don't have prettier enabled on push?

I think it was because we used the --no-verify flag. @francovenica you need to find a smoother way to work with your Windows machine and git/GitHub and add the prettier setup.

@iamacook
Copy link
Member

I think it was because we used the --no-verify flag.

Prettier currently only formats /src, /public and /scripts.

@@ -0,0 +1,65 @@
import 'cypress-file-upload';
const path = require("path");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import not used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is used to upload the QR file

Comment on lines 4 to 11
const SAFE_ENS_NAME = "safe.test"
const SAFE_ENS_NAME_TRANSLATED = "0x83eC7B0506556a7749306D69681aDbDbd08f0769"
const SAFE_QR_CODE_ADDRESS = "0x9913B9180C20C6b0F21B6480c84422F6ebc4B808"
const NON_CONTRACT_ADDRESS = "0x61a0c717d18232711bC788F19C9Cd56a43cc8872"
const INVALID_INPUT_ERROR_MSG = "Must be a valid address, ENS or Unstoppable domain"
const INVALID_ADDRESS_ERROR_MSG = "Address given is not a valid Safe address"
const OWNER_ENS_DEFAULT_NAME = "francoledger.eth"
const OWNER_ADDRESS = "0x6f965E48347AF3Df65c14CCc176A9CbeCEa0eDb5"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest moving to a constants.ts file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to create a bunch of test that work individually first. At some point as the test grow I'll create files to share constant, selectors and such.


cy.get('[data-track="load-safe: Open stepper"]').click()
cy.findByText('Add existing Safe').should('exist')
cy.wait(1000) //Have to wait because clicking the switch network fails sometimes if not
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we wait for data-testid="select-network-step" to exist? as opposite to timeouts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is the application, if you click too fast it fails to load. Is not that the button is missing or anything, is that you can click it before it loads properly

cy.wait(1000) //Have to wait because clicking the switch network fails sometimes if not

//Step 1
cy.get('[data-testid="select-network-step"]').find('button').click()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would even say to find by text whenever possible

Comment on lines 25 to 28
cy.findByText('Ethereum').click()
cy.get('nav').findByText('Ethereum').should('exist')
cy.get('[data-testid="select-network-step"]').findByText('Ethereum').should('exist')
cy.get('[data-testid="select-network-step"]').find('button').click()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we changing network unnecessarily? I would keep the test as straightforward as possible and do not bloat to much the tested scenario

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just making sure the network works back and forth. I'll do the same whenever we can make a safe creation test

cy.findByText(INVALID_ADDRESS_ERROR_MSG).should('exist')
cy.get('[data-testid="load-safe-address-field"]').clear().type(SAFE_ENS_NAME).should('have.value', SAFE_ENS_NAME_TRANSLATED)
cy.get('[data-testid="qr-icon"]').click()
cy.get('[class="paper"]').find('button').contains('Upload an image').click()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does findByText work here?

cy.get('[type="file"]').attachFile('../utils/files/rinkeby_safe_QR.png')
cy.get('[data-testid="load-safe-address-field"]').should('have.value', SAFE_QR_CODE_ADDRESS)
cy.get('[data-testid="safeAddress-valid-address-adornment"]').should('exist')
cy.wait(3000) //have to wait or after clicking next what loads is the owners of the previous valids safe, not the one from the QR code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we wait for the submit button not to be disabled instead of a timeout?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that if you clcik the button too fast when it reaches the owner steps it shows the owners for the safe that was loaded previously and not the safe loaded by the QR code. Is a case of the app not ready to have a user clicking the "next" button so fast

//Review Step
cy.findByText('Test safe name').should('exist')
cy.findByText('Test Owner Name').should('exist')
cy.get('[data-track="load-safe: Add"]').click()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findByText

//Step3
cy.findByPlaceholderText(OWNER_ENS_DEFAULT_NAME).parents('div[data-testid="owner-row"]').findByText(OWNER_ADDRESS)
cy.findByPlaceholderText(OWNER_ENS_DEFAULT_NAME).type('Test Owner Name').should('have.value', 'Test Owner Name')
cy.get('[data-track="load-safe: Continue"]').click()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findByText

@francovenica
Copy link
Contributor Author

On a personal note, I'd not like to use the "findByText" as the first option, since that searches for the first occurrence of a text, so if it is not unique you are in trouble. I'd prefer to use any other selector as first option (a test-id, a class, an alt or title...)
A better way to use it is if the scope is reduced, like searching for a specific text on the sidebar only:
cy.FindByTestId('sidebar').findByText('Some text here')

@github-actions
Copy link

github-actions bot commented May 2, 2022

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 2 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@francovenica francovenica merged commit ca53029 into dev May 3, 2022
@francovenica francovenica deleted the test-footer-and-load-safe branch May 3, 2022 13:47
@github-actions github-actions bot locked and limited conversation to collaborators May 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants