Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2021-12-30 16:13:50 +0300
committerAzul <azul@riseup.net>2021-12-30 18:12:24 +0300
commit1e5259bdf77f55ce9ed4e26c9a75ed82447fa791 (patch)
tree51ec0b6ecbe5b1e3f51512b7c6860b3ee8251d9c /cypress
parent75876791e29ec9089339f11657c49f8591e49226 (diff)
fix: cypress login with new session feature
Use the new session feature to create and reuse sessions: https://docs.cypress.io/api/commands/session The first time `login` with a given name is called the steps described in the login function are performed and cookies and localstorage are cached. The next time `login` is called with the same name cookies and localStorage are restored and used again. This allows us to keep fast test runs while still separating the tests more cleanly. The old logout command was broken because of the way we used `Cypress.Cookies.defaults({ preserve })` before: Cypress runs all the `cy.*` commands during initialization and builds a list of commands that are then executed during the tests. However `Cypress.Cookies.defaults` is evaluated when preparing the list not while performing the actual steps. Signed-off-by: Azul <azul@riseup.net>
Diffstat (limited to 'cypress')
-rw-r--r--cypress/integration/files.spec.js5
-rw-r--r--cypress/integration/share.spec.js8
-rw-r--r--cypress/integration/viewer.spec.js10
-rw-r--r--cypress/support/commands.js26
4 files changed, 15 insertions, 34 deletions
diff --git a/cypress/integration/files.spec.js b/cypress/integration/files.spec.js
index 6f77be7db..3b5b8d470 100644
--- a/cypress/integration/files.spec.js
+++ b/cypress/integration/files.spec.js
@@ -21,12 +21,9 @@
*/
describe('Files default view', function() {
- before(function() {
+ beforeEach(function() {
cy.login('admin', 'admin')
})
- after(function() {
- cy.logout()
- })
it('See the default files list', function() {
cy.get('#fileList tr').should('contain', 'welcome.txt')
diff --git a/cypress/integration/share.spec.js b/cypress/integration/share.spec.js
index 7ec10d518..0b48896e2 100644
--- a/cypress/integration/share.spec.js
+++ b/cypress/integration/share.spec.js
@@ -51,12 +51,8 @@ describe('Open test.md in viewer', function() {
cy.get('#fileList tr[data-file="test.md"]', {timeout: 10000})
.should('contain', 'test.md')
})
- after(function () {
- cy.on('uncaught:exception', (err, runnable) => {
- return false
- })
- cy.visit('/apps/files')
- cy.logout()
+ beforeEach(function() {
+ cy.login(randUser, 'password')
})
it('Shares the file as a public read only link', function () {
diff --git a/cypress/integration/viewer.spec.js b/cypress/integration/viewer.spec.js
index dfa447105..47bfad682 100644
--- a/cypress/integration/viewer.spec.js
+++ b/cypress/integration/viewer.spec.js
@@ -32,13 +32,10 @@ describe('Open test.md in viewer', function() {
// Upload test files
cy.uploadFile('test.md', 'text/markdown')
- cy.visit('/apps/files')
-
- // wait a bit for things to be settled
- cy.wait(1000)
})
- after(function() {
- cy.logout()
+
+ beforeEach(function() {
+ cy.login(randUser, 'password')
})
it('See test.md in the list', function() {
@@ -47,7 +44,6 @@ describe('Open test.md in viewer', function() {
})
it('Open the viewer on file click', function() {
- cy.visit('/apps/files')
cy.openFile('test.md')
cy.get('#viewer').should('be.visible')
cy.get('#viewer .modal-title').should('contain', 'test.md')
diff --git a/cypress/support/commands.js b/cypress/support/commands.js
index 3283a8ab5..dbe72c3d0 100644
--- a/cypress/support/commands.js
+++ b/cypress/support/commands.js
@@ -26,27 +26,19 @@ const url = Cypress.config('baseUrl').replace(/\/index.php\/?$/g, '')
Cypress.env('baseUrl', url)
Cypress.Commands.add('login', (user, password, route = '/apps/files') => {
- cy.clearCookies()
- Cypress.Cookies.defaults({
- preserve: /^(oc|nc)/
+ cy.session(user, function () {
+ cy.visit(route)
+ cy.get('input[name=user]').type(user)
+ cy.get('input[name=password]').type(password)
+ cy.get('#submit-wrapper input[type=submit]').click()
+ cy.url().should('include', route)
})
+ // in case the session already existed but we are on a different route...
cy.visit(route)
- cy.get('input[name=user]').type(user)
- cy.get('input[name=password]').type(password)
- cy.get('#submit-wrapper input[type=submit]').click()
- cy.url().should('include', route)
})
-Cypress.Commands.add('logout', () => {
- Cypress.Cookies.defaults({
- preserve: []
- })
-
- cy.clearLocalStorage()
- cy.clearCookies()
-
- Cypress.Cookies.defaults({
- preserve: /^(oc|nc)/
+Cypress.Commands.add('logout', (route = '/') => {
+ cy.session('_guest', function () {
})
})