Skip to content

Commit aab9041

Browse files
authored
Merge pull request #2046 from nextcloud/backport/2039/stable23
2 parents d23e5b9 + 17ddab7 commit aab9041

File tree

5 files changed

+35
-60
lines changed

5 files changed

+35
-60
lines changed

cypress.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"baseUrl": "https://localhost:8081/index.php/",
33
"projectId": "hx9gqy",
44
"viewportWidth": 1280,
5-
"viewportHeight": 720
5+
"viewportHeight": 720,
6+
"experimentalSessionSupport": true
67
}

cypress/integration/files.spec.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121
*/
2222

2323
describe('Files default view', function() {
24-
before(function() {
24+
beforeEach(function() {
2525
cy.login('admin', 'admin')
2626
})
27-
after(function() {
28-
cy.logout()
29-
})
3027

3128
it('See the default files list', function() {
3229
cy.get('#fileList tr').should('contain', 'welcome.txt')

cypress/integration/share.spec.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@ describe('Open test.md in viewer', function() {
5151
cy.get('#fileList tr[data-file="test.md"]', {timeout: 10000})
5252
.should('contain', 'test.md')
5353
})
54-
after(function () {
55-
cy.on('uncaught:exception', (err, runnable) => {
56-
return false
57-
})
58-
cy.visit('/apps/files')
59-
cy.logout()
54+
beforeEach(function() {
55+
cy.login(randUser, 'password')
6056
})
6157

6258
it('Shares the file as a public read only link', function () {

cypress/integration/viewer.spec.js

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,10 @@ describe('Open test.md in viewer', function() {
3232

3333
// Upload test files
3434
cy.uploadFile('test.md', 'text/markdown')
35-
cy.visit('/apps/files')
36-
37-
// wait a bit for things to be settled
38-
cy.wait(1000)
3935
})
40-
after(function() {
41-
cy.logout()
36+
37+
beforeEach(function() {
38+
cy.login(randUser, 'password')
4239
})
4340

4441
it('See test.md in the list', function() {
@@ -47,41 +44,33 @@ describe('Open test.md in viewer', function() {
4744
})
4845

4946
it('Open the viewer on file click', function() {
50-
cy.visit('/apps/files')
5147
cy.openFile('test.md')
52-
cy.get('#viewer').should('be.visible')
53-
cy.get('#viewer .modal-title').should('contain', 'test.md')
54-
cy.get('#viewer .modal-header button.action-item__menutoggle').should('be.visible')
55-
cy.get('#viewer .modal-header button.header-close').should('be.visible')
5648

57-
cy.wait(2000)
58-
cy.get('#viewer', { timeout: 4000 })
59-
.should('be.visible')
49+
cy.log('Inspect viewer')
50+
const viewer = cy.get('#viewer')
51+
viewer.should('be.visible')
6052
.and('have.class', 'modal-mask')
6153
.and('not.have.class', 'icon-loading')
62-
})
54+
viewer.get('.modal-title').should('contain', 'test.md')
55+
viewer.get('.modal-header button.action-item__menutoggle')
56+
.should('be.visible')
6357

64-
it('Has opened the file', function() {
65-
cy.get('#viewer #editor .ProseMirror').should('contain', 'Hello world')
66-
cy.get('#viewer #editor .ProseMirror h2').should('contain', 'Hello world')
67-
})
58+
cy.log('Inspect editor')
59+
const editor = viewer.get('#editor .ProseMirror')
60+
editor.should('contain', 'Hello world')
61+
editor.get('h2').should('contain', 'Hello world')
6862

69-
it('Shows the menu bar icons', function() {
70-
// FIXME those checks are failing since the parent container is currently at 0x0 size
71-
// due to the way we make the text app be a full screen viewer
72-
// cy.get('#viewer-content #editor .menubar .menubar-icons .icon-undo').should('be.visible')
73-
// cy.get('#viewer-content #editor .menubar .menubar-icons .icon-redo').should('be.visible')
74-
// cy.get('#viewer-content #editor .menubar .menubar-icons .icon-bold').should('be.visible')
63+
cy.log('Inspect menubar')
64+
const menubar = editor.get('.menubar .menubar-icons')
65+
menubar.get('.icon-undo').should('be.visible')
66+
menubar.get('.icon-bold').should('be.visible')
67+
68+
cy.screenshot()
7569
})
7670

7771
it('Closes the editor', function() {
78-
cy.get('.modal-header button.header-close').click()
72+
cy.openFile('test.md')
73+
cy.get('#viewer .modal-header button.header-close').click()
7974
cy.get('#viewer').should('not.exist')
8075
})
81-
82-
it('Take screenshot', function() {
83-
// gif is impossible to match with existing screenshot
84-
// just taking a screenshot to manually compare if needed
85-
cy.screenshot()
86-
})
8776
})

cypress/support/commands.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,19 @@ const url = Cypress.config('baseUrl').replace(/\/index.php\/?$/g, '')
2626
Cypress.env('baseUrl', url)
2727

2828
Cypress.Commands.add('login', (user, password, route = '/apps/files') => {
29-
cy.clearCookies()
30-
Cypress.Cookies.defaults({
31-
preserve: /^(oc|nc)/
29+
cy.session(user, function () {
30+
cy.visit(route)
31+
cy.get('input[name=user]').type(user)
32+
cy.get('input[name=password]').type(password)
33+
cy.get('#submit-wrapper input[type=submit]').click()
34+
cy.url().should('include', route)
3235
})
36+
// in case the session already existed but we are on a different route...
3337
cy.visit(route)
34-
cy.get('input[name=user]').type(user)
35-
cy.get('input[name=password]').type(password)
36-
cy.get('#submit-wrapper input[type=submit]').click()
37-
cy.url().should('include', route)
3838
})
3939

40-
Cypress.Commands.add('logout', () => {
41-
Cypress.Cookies.defaults({
42-
preserve: []
43-
})
44-
45-
cy.clearLocalStorage()
46-
cy.clearCookies()
47-
48-
Cypress.Cookies.defaults({
49-
preserve: /^(oc|nc)/
40+
Cypress.Commands.add('logout', (route = '/') => {
41+
cy.session('_guest', function () {
5042
})
5143
})
5244

0 commit comments

Comments
 (0)