Skip to content

Commit ec1ac8c

Browse files
committed
fix: 2020 let heading menu overflow workspace
* roll back parts of #1903 that broke it again. * Calculate top of menububble based on scrollHeight of content-wrapper. * Always display menububble below selected line. This will make it less likely to conflict with the menubar or mobile copy and paste toolbars. * Add cypress tests for the workspace.
1 parent 7d4d16d commit ec1ac8c

22 files changed

+181
-39
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/**
2+
* @copyright Copyright (c) 2021 Azul <azul@riseup.net>
3+
*
4+
* @author Azul <azul@riseup.net>
5+
*
6+
* @license GNU AGPL version 3 or any later version
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
24+
import { randHash } from '../utils/'
25+
const randUser = randHash()
26+
27+
describe('Workspace', function() {
28+
29+
before(function() {
30+
cy.nextcloudCreateUser(randUser, 'password')
31+
})
32+
33+
beforeEach(function() {
34+
cy.login(randUser, 'password')
35+
cy.visit('/apps/files')
36+
// isolate tests - each happens in it's own folder
37+
cy.createFolder(Cypress.currentTest.title)
38+
cy.openFile(Cypress.currentTest.title)
39+
})
40+
41+
it('adds a Readme.md', function() {
42+
cy.get('#fileList').should('not.contain', 'Readme.md')
43+
openWorkspace()
44+
.type('Hello')
45+
.should('contain', 'Hello')
46+
cy.get('#fileList').should('contain', 'Readme.md')
47+
})
48+
49+
it('formats text', function() {
50+
openWorkspace()
51+
.type('Format me')
52+
.type('{selectall}')
53+
;[['bold', 'strong'], ['italic', 'em'], ['strike', 's']]
54+
.forEach(([button, tag]) => {
55+
menuButton(button)
56+
.click()
57+
.should('have.class', 'is-active')
58+
cy.get(`.ProseMirror ${tag}`).should('contain', 'Format me')
59+
menuButton(button)
60+
.click()
61+
.should('not.have.class', 'is-active')
62+
})
63+
})
64+
65+
it('links via menububble', function() {
66+
openWorkspace()
67+
.type('Nextcloud')
68+
.type('{selectall}')
69+
menuBubbleButton('link').click()
70+
cy.get('.menububble input').type('https://nextcloud.com{enter}')
71+
cy.get('.ProseMirror a')
72+
.should('contain', 'Nextcloud')
73+
.should('be.visible')
74+
cy.get('.ProseMirror a').invoke('attr', 'href')
75+
.should('include', 'https://nextcloud.com')
76+
cy.window().then((win) => {
77+
cy.stub(win, 'open').as('windowOpen')
78+
})
79+
cy.get('.ProseMirror a').click()
80+
cy.get('@windowOpen').should('be.calledWith', 'https://nextcloud.com/')
81+
cy.get('.ProseMirror').type('{selectall}')
82+
menuBubbleButton('link').click()
83+
cy.get('.menububble input').type('/team{enter}')
84+
cy.get('.ProseMirror a').click()
85+
cy.get('@windowOpen').should('be.calledWith', 'https://nextcloud.com/team')
86+
})
87+
88+
it('creates headings via submenu', function() {
89+
openWorkspace()
90+
.type('Heading')
91+
.type('{selectall}')
92+
;['h1', 'h2', 'h3', 'h4', 'h5', 'h6'].forEach((heading) => {
93+
menuButton('h1').click()
94+
submenuButton(heading).click()
95+
menuButton(heading).should('have.class', 'is-active')
96+
cy.get(`.ProseMirror ${heading}`)
97+
.should('contain', 'Heading')
98+
menuButton(heading).click()
99+
submenuButton(heading).click()
100+
menuButton('h1').should('not.have.class', 'is-active')
101+
})
102+
})
103+
104+
})
105+
106+
const menuButton = (name) => {
107+
return cy.get(`#editor button.icon-${name}`)
108+
}
109+
110+
const submenuButton = (name) => {
111+
return cy.get(`#editor button .icon-${name}`)
112+
}
113+
114+
const menuBubbleButton = submenuButton
115+
116+
const openWorkspace = () => {
117+
cy.get('#rich-workspace').click()
118+
cy.get('#editor .content-wrapper').click()
119+
return cy.get('#rich-workspace .ProseMirror')
120+
}

β€Žcypress/runLocal.shβ€Ž

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,21 @@ then
1616
fi
1717

1818
# start server if it's not running yet
19-
if $(npm bin)/wait-on -i 500 -t 1000 $CYPRESS_baseUrl
19+
if $(npm bin)/wait-on -i 500 -t 1000 $CYPRESS_baseUrl 2> /dev/null
2020
then
2121
echo Server is up at $CYPRESS_baseUrl
2222
else
23+
echo No server reached at $CYPRESS_baseUrl - starting containers.
2324
docker-compose up -d
24-
$(npm bin)/wait-on -i 500 -t 240000 $CYPRESS_baseUrl || ( docker-compose logs ; exit 1 )
25-
docker-compose exec -T nextcloud bash /var/www/html/apps/text/cypress/server.sh
25+
if $(npm bin)/wait-on -i 500 -t 240000 $CYPRESS_baseUrl 2> /dev/null
26+
then
27+
docker-compose exec -T nextcloud bash /var/www/html/apps/text/cypress/server.sh
28+
else
29+
echo Waiting for $CYPRESS_baseUrl timed out.
30+
echo Container logs:
31+
docker-compose logs
32+
exit 1
33+
fi
2634
fi
2735

2836
(cd .. && $(npm bin)/cypress $@)

β€Žcypress/support/commands.jsβ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ Cypress.Commands.add('login', (user, password, route = '/apps/files') => {
3333
cy.get('#submit-wrapper input[type=submit]').click()
3434
cy.url().should('include', route)
3535
})
36-
// in case the session already existed but we are on a different route...
37-
cy.visit(route)
3836
})
3937

4038
Cypress.Commands.add('logout', (route = '/') => {

β€Žjs/editor-rich.jsβ€Ž

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žjs/editor-rich.js.mapβ€Ž

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žjs/editor.jsβ€Ž

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žjs/editor.js.mapβ€Ž

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žjs/files-modal.jsβ€Ž

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žjs/files-modal.js.mapβ€Ž

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žjs/text-files.jsβ€Ž

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)