Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add connect command #402

Merged
merged 8 commits into from
Oct 17, 2023
Merged

feat: Add connect command #402

merged 8 commits into from
Oct 17, 2023

Conversation

Lykhoyda
Copy link
Collaborator

@Lykhoyda Lykhoyda commented Oct 13, 2023

closes #371

Compatibility

  • Functionality of change validated with a connected account with multisig
  • Applicable elements hidden/disabled for watched multisigs / pure
  • Looks good for solo multisig
  • Looks good for multisig with proxy

@Lykhoyda Lykhoyda changed the title Add connect command feat: Add connect command Oct 13, 2023
@asnaith
Copy link
Member

asnaith commented Oct 13, 2023

Hey @Lykhoyda, I noticed some of the tests that I recently merged failed in this branch due to slower loading when executing in CI:

Watched Accounts -- can edit the name of a watched pure (failed)

I pushed a tiny commit to this branch to increase the timeout for the account header element. This is the element the test is looking for after navigating to the home page but we can see from the screenshot it's still loading so couldn't find it, and exceeded the default timeout we were relying on (4 seconds).


topMenuItems.headerNavbar().within(() => {
cy.get('[href="/create"]').click()
})
Copy link
Member

Choose a reason for hiding this comment

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

This could just be topMenuItems.newMultisigButton().click()

.should(
'have.text',
'No account found. Please connect at least one in a wallet extension. More info at wiki.polkadot.network'
)
Copy link
Member

Choose a reason for hiding this comment

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

Personally, I do like the thoroughness of the check of the string but in the past (before your time, maybe even on another FE project!) I recall there was a group consensus that we should just check for the presence of the error element itself but not the text so this is what I've been doing since.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed as long as this container is unique, and only this error would be displayed, in it. In this case, the container is called noAccount.. So we should be fine. Another idea could be that we keep the text check, but only check that it contains "no account found"? So that if we even change the rest, we won't have to change this test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@asnaith @Tbaut I have mixed feelings about the way of writing e2e tests. If we write the test from the expectation of the user what should happen on the screen, then we indeed carry about the text that will be displayed on the screen. And if we change the text on the UI side the tests would fail which is a valid scenario for me. The way we wrote the current test is we found the element by class and checked for visibility, it's an implementation details test as a user will not deal with the classes or any code at all, the user will see only text. BTW, it's also why I like testing library(https://testing-library.com/docs/) because it interacts only with displayed content by the core principles, and using the main API will not allow you to write such a test.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's just a matter of how safe we are with what's on the screen, and what maintenance burden this adds. At the end of the day, you and me are the one who will break the tests if we change the text, so we're the one who may be annoyed. The actual best way is to export those strings to shared files, but this is overkill IMHO. Let's keep this string check if you feel strongly about it, I doubt it will be such a maintenance annoyance. And if it it, we can reconsider this practice in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not only about checking the strings but keeping in mind the way to write the test, that it should be user-centric. The Cypress default library is super flexible, but from the beginning, it's better to have some guidance and principles for writing the test, and IMO the testing library forces good practices to avoid testing the implementation details. I want that we will all be on the same page. Let me know if you are against testing according to the following principles https://testing-library.com/docs/guiding-principles

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't have strong opinions. Also tbh I'm not sure to fully understand the content of the link you posted as it's written in a very abstract way 😄 . I just want our tests to be easy to read/understand, easy to maintain, while obviously being meaningful. I do think it's meaningful whether we check the string or check that this unique component with the error is visible (Cypress is clever enough that if it's present, but not visible, the test will fail). Both have pros/cons. So far in other projects, we didn't check the string because it was easier to maintain and we were 100% sure that if this component is visible, then this message is visible. Now I understand your PoV too, it's safer still to check the string. To go half way, that's why I proposed instead of checking the whole string, to just check the most important part, and the part that will likely not change "No account found". Because if e.g we change the link in the future, I feel it'd be better to not break the test for this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

At least to use "contain.text" is definitely better. The code is updated

Copy link
Member

Choose a reason for hiding this comment

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

@Lykhoyda I'm 100% aligned with you that the cypress tests should be user-centric. Meeting halfway with the "contains" and not an exact match is for sure better than not checking the text at all 👍

Comment on lines 50 to 48
const accountLabels = cy.get('[data-cy="label-account-name"]')
accountLabels.each((el, index) => {
const expectedName = Object.values(injectedAccounts)[index].name
cy.wrap(el).should('have.text', expectedName)
})
Copy link
Member

Choose a reason for hiding this comment

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

import { accountDisplay } from '../support/page-objects/components/accountDisplay'

and

Suggested change
const accountLabels = cy.get('[data-cy="label-account-name"]')
accountLabels.each((el, index) => {
const expectedName = Object.values(injectedAccounts)[index].name
cy.wrap(el).should('have.text', expectedName)
})
accountDisplay.nameLabel().each((el, index) => {
const expectedName = Object.values(injectedAccounts)[index].name
cy.wrap(el).should('have.text', expectedName)
})

Comment on lines 116 to 119
/**
* Connect an accounts to the extension
* @param accountAddress
*/
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/**
* Connect an accounts to the extension
* @param accountAddress
*/
/**
* Connect accounts to the dApp
* @param accountAddresses
*/

@github-actions github-actions bot requested a deployment to multix (Preview) October 16, 2023 10:19 Abandoned
Copy link
Collaborator

@Tbaut Tbaut left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Just a nit for this PR, please either remove the irrelevant checkboxs in the first post, or check them. Leaving them unchecked makes things unclear for anyone who's unaware.

@Lykhoyda Lykhoyda merged commit 1195cad into main Oct 17, 2023
7 checks passed
@Lykhoyda Lykhoyda deleted the lykhoyda/add_connect_command branch October 17, 2023 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Cypress] Add helper to connect with certain accounts
3 participants