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

fix(tests): Move leftover acceptance tests for users from drone to Cypress #41021

Merged
merged 1 commit into from
Oct 25, 2023

Conversation

susnux
Copy link
Contributor

@susnux susnux commented Oct 20, 2023

Summary

Move the tiny rest of acceptance tests for user setting to Cypress and add missing test cases:

  • Change quota
  • Set subadmin
  • Add manager

Checklist

@susnux susnux requested review from artonge, skjnldsv and Pytal October 20, 2023 18:12
@susnux susnux requested a review from nickvergessen as a code owner October 20, 2023 18:12
@susnux susnux force-pushed the fix/move-tests-from-drone-to-cypress branch 2 times, most recently from b59766a to 2e1b182 Compare October 20, 2023 18:16
@susnux
Copy link
Contributor Author

susnux commented Oct 20, 2023

BTW using random users should make it also less flaky, as now every test has a defined state.

@susnux susnux force-pushed the fix/move-tests-from-drone-to-cypress branch 2 times, most recently from 1be69fa to 64839ed Compare October 21, 2023 01:44
@skjnldsv
Copy link
Member

BTW using random users should make it also less flaky, as now every test has a defined state.

If random users makes it flaky, the tests or our codeis probably the issue then.
I would prefer not hardcoding users, they do create a new universal "fresh Nextcloud" base and we should rely on it :)

@susnux
Copy link
Contributor Author

susnux commented Oct 21, 2023

I would prefer not hardcoding users

Exactly, previously hardcoded "jane doe" was used, but that might lead to inconsistent state.
Now random users are created, so at least the user does not exists and we start with a fresh profile.

It would need some more work (I do not have the time currently) to rewrite the tests, as the best way (and the best practice from Cypress) would be to ensure we have a clean state before the tests and not clean up after the tests.

So e.g. removing the datadir and resetting the database before each test.

Thinking about this hardcoding users might also be good if we always use the same and have something like:

before each: delete user "test" if exists. Recreate a fresh user "test".

But especially as our Cypress tests are also changing admin settings (we have a reset but only for theming), the golden standard would be to reset all settings by running every testsuite with the initial database.
So not sure if possible but creating a snapshot of the datadir right before cypress starts (as that includes the sqlite database) and then having a command that resets the datadir to the snapshot in the before hook.
So something like this (did not test probably does not work):

// in e2e support file
before(() => {
	cy.exec('docker exec --user www-data nextcloud-cypress-tests-server rm -rf apps-cypress')
	cy.exec('docker exec --user www-data nextcloud-cypress-tests-server mkdir apps-cypress')

	cy.exec('docker exec --user www-data nextcloud-cypress-tests-server bash -c \'echo -e "<?php\\n\\$CONFIG = [\\n\\t\\"apps_paths\\" => [\\n\\t\\t[\\"path\\" => \\"/var/www/html/apps\\", \\"url\\" => \\"/apps\\", \\"writeable\\"=>false],\\n\\t\\t[\\"path\\" => \\"/var/www/html/apps-cypress\\", \\"url\\" => \\"/apps2\\", \\"writeable\\" => true]\\n\\t],\\n];" > config/cypress.config.php\'')

	cy.exec('docker exec --user www-data nextcloud-cypress-tests-server tar -cf clean-state.tar apps-cypress config data')
})

beforeEach(() => {
	cy.exec('docker exec --user www-data nextcloud-cypress-tests-server rm -rf apps-cypress config data')
	cy.exec('docker exec --user www-data nextcloud-cypress-tests-server tar -xpf clean-state.tar')
})

Edit: Pushed another commit making all user modify tests less flaky as the users and groups are reset before each run. As suggested by the Cypress best practice guides.

<template v-if="editing && user.backendCapabilities.setDisplayName">
<NcTextField ref="displayNameField"
class="user-row-text-field"
data-test-id="input-displayName"
Copy link
Member

@skjnldsv skjnldsv Oct 22, 2023

Choose a reason for hiding this comment

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

Ah, we talked abut this before with various other devs. I advocated for the usage of data-cy-xxxx and seemed that other devs agreed too after a some discussion. This allow to scope the elements.

I know what the best-practices says, but I think they do not have our overall ecosystem, so things differs a bit :)

The data attribute value should be used when it have a real changing value. Like data-cy-userslist-user="admin". Otherwise it makes really weird to target a specific element.
I also prefer to have more unique data attributes. The fact that you can grep all [data-cy="files-list-row"] makes no sense imho.
But [data-cy-files-list-row] and [data-cy-files-list-row-fileid="12345"] does :)

Any thoughts or counter arguments?
cc @artonge @max-nextcloud @Pytal as I recall you were in that discussion before 😉

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 me it makes no difference if I use data-testid or data-cy both a pretty common and standard, so I am fine with both.

The fact that you can grep all [data-cy="files-list-row"] makes no sense imho.
But [data-cy-files-list-row] and [data-cy-files-list-row-fileid="12345"] does :)

Well for me not that much 😅
data-cy="files-list-row" for me this is like the id (without its singleton limitation), so it says "Select all elements that are file list rows". While data-cy-files-list-row-fileid="12345" says "get the file list row that for file ID 12345".

So my problem with data-cy-files-list-row vs data-cy="files-list-row" is that there is no consistent naming for identifying elements, you always need to use a specific attribute rather that a specific attribute ID.
This feels wrong in a HTML context.

But this is not about feels, so I have no problem to stick with one notation for all of our code and if it was decided to go with data-cy-some-identifier as boolean attribute then I am fine with it. As there is no technical downside 😃

Need some time to adjust this PR then for data-cy and we should probably add this to our development guides :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TL;DR: Will take some time this week to adjust the test selectors 😉

Copy link
Member

Choose a reason for hiding this comment

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

data-cy="files-list-row" for me this is like the id (without its singleton limitation), so it says "Select all elements that are file list rows". While data-cy-files-list-row-fileid="12345" says "get the file list row that for file ID 12345".

If you want all the lines, then you can also do [data-cy-files-list-row-fileid], without the id.
That's the benefit of scoped selectors. And with [data-cy="files-list-row"], you cannot select by Ids with that syntax.
Or with something like [data-cy="files-list-row-123456"], but I find it incredibly messy 🤷

@skjnldsv
Copy link
Member

Exactly, previously hardcoded "jane doe" was used, but that might lead to inconsistent state.
Now random users are created, so at least the user does not exists and we start with a fresh profile.

Ah, I read it as the opposite 🙈
I thought you meant we should go for hardcoded users with Cypress 😉

@susnux susnux force-pushed the fix/move-tests-from-drone-to-cypress branch 2 times, most recently from 1826e93 to 9a0b9b8 Compare October 24, 2023 12:16
@susnux susnux requested review from ShGKme and max-nextcloud and removed request for artonge October 24, 2023 12:17
@susnux susnux force-pushed the fix/move-tests-from-drone-to-cypress branch from 9a0b9b8 to 6a8756c Compare October 25, 2023 08:24
@netlify
Copy link

netlify bot commented Oct 25, 2023

Deploy Preview for nextcloud-server ready!

Name Link
🔨 Latest commit 6a8756c
🔍 Latest deploy log https://app.netlify.com/sites/nextcloud-server/deploys/6538d0c3abb96d000895ffdd
😎 Deploy Preview https://deploy-preview-41021--nextcloud-server.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

* Use common `data-testid` to identify elements rather than to depend on internal classes or properties
* Force clean the state for the user tests
* Move leftover acceptance tests for users from drone to cypress

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
@susnux susnux force-pushed the fix/move-tests-from-drone-to-cypress branch from 6a8756c to 5b0c27b Compare October 25, 2023 09:36
@susnux
Copy link
Contributor Author

susnux commented Oct 25, 2023

Cypress error caused by theming, so will do a follow up fixing theming tests.

@susnux susnux merged commit 421f601 into master Oct 25, 2023
38 of 41 checks passed
@susnux susnux deleted the fix/move-tests-from-drone-to-cypress branch October 25, 2023 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants