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

[stable27] fix(css): Fix print view in viewer and single-file share #5066

Merged
merged 12 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ jobs:
if: failure()
with:
name: Upload screenshots
path: apps/${{ env.APP_NAME }}/cypress/screenshots/
path: |
apps/${{ env.APP_NAME }}/cypress/screenshots/
apps/${{ env.APP_NAME }}/cypress/snapshots/
retention-days: 5

- name: Upload nextcloud logs
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ node_modules/
vendor/
img/twemoji/
cypress/screenshots/
cypress/snapshots/actual
cypress/snapshots/diff
cypress/videos/
cypress/downloads/
.php-cs-fixer.cache
Expand Down
93 changes: 62 additions & 31 deletions css/print.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@
overflow: visible!important;
}

#header {
display: none!important;
}

#content {
display: block!important;
position: relative!important;
border-radius: 0;
margin: 0;
width: 100%;
height: fit-content;
}

footer {
display: none!important;
}

#viewer[data-handler='text'] {
// Hide top border
border: none;
Expand All @@ -29,6 +46,8 @@
}

.text-editor {
height: fit-content!important;

.text-menubar {
// Hide menu bar
display: none!important;
Expand All @@ -44,40 +63,47 @@
.text-editor__wrapper {
height: fit-content;
position: unset;
}

div.ProseMirror {
h1, h2, h3, h4, h5 {
// orphaned headlines are ugly
break-after: avoid;
}
.image, img, table {
// try no page breaks within tables or images
break-inside: avoid-page;
// Some more indention
max-width: 90%!important;
margin: 5vw auto 5vw 5%!important;
}
div.ProseMirror {
margin-top: 0;
margin-bottom: 0;
padding-top: 0;
padding-bottom: 0;

// Add some borders below header and between columns
th {
color: black!important;
font-weight: bold!important;
border-width: 0 1px 2px 0!important;
border-color: gray!important;
border-style: none solid solid none!important;
}
th:last-of-type {
border-width: 0 0 2px 0!important;
}
h1, h2, h3, h4, h5 {
// orphaned headlines are ugly
break-after: avoid;
page-break-after: avoid;
}
.image, img, table {
// try no page breaks within tables or images
break-inside: avoid-page;
page-break-inside: avoid;
// Some more indention
max-width: 90%!important;
margin: 5vw auto 5vw 5%!important;
}

td {
border-style: none solid none none!important;
border-width: 1px!important;
border-color: gray!important;
}
td:last-of-type {
border: none!important;
// Add some borders below header and between columns
th {
color: black!important;
font-weight: bold!important;
border-width: 0 1px 2px 0!important;
border-color: gray!important;
border-style: none solid solid none!important;
}
th:last-of-type {
border-width: 0 0 2px 0!important;
}

td {
border-style: none solid none none!important;
border-width: 1px!important;
border-color: gray!important;
}
td:last-of-type {
border: none!important;
}
}
}
}
Expand All @@ -101,4 +127,9 @@
display: none;
}
}

.collaboration-cursor__caret,
.collaboration-cursor__label {
display: none;
}
}
13 changes: 12 additions & 1 deletion cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
const { defineConfig } = require('cypress')
const getCompareSnapshotsPlugin = require('cypress-visual-regression/dist/plugin.js')

module.exports = defineConfig({
projectId: 'hx9gqy',
viewportWidth: 1280,
viewportHeight: 900,
screenshotsFolder: './cypress/snapshots/actual',
trashAssetsBeforeRuns: true,
env: {
failSilently: false,
type: 'actual',
SNAPSHOT_BASE_DIRECTORY: './cypress/snapshots/base',
SNAPSHOT_DIFF_DIRECTORY: './cypress/snapshots/diff',
},
e2e: {
setupNodeEvents(on, config) {
getCompareSnapshotsPlugin(on, config)

const browserify = require('@cypress/browserify-preprocessor')
const webpack = require('@cypress/webpack-preprocessor')
const webpackOptions = require('@nextcloud/webpack-vue-config')
Expand All @@ -25,5 +36,5 @@ module.exports = defineConfig({
// do not retry in `cypress open`
openMode: 0,
},
"numTestsKeptInMemory": 5,
'numTestsKeptInMemory': 5,
})
70 changes: 70 additions & 0 deletions cypress/e2e/print.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
*
* @copyright Copyright (c) 2023 Jonas <[email protected]>
*
* @author Jonas <[email protected]>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { initUserAndFiles, randUser } from '../utils/index.js'
const user = randUser()

describe('Open print.md and compare print view', function() {
before(function() {
initUserAndFiles(user, 'print.md')
})
beforeEach(function() {
cy.login(user)
cy.visit('/apps/files')
})

it('Renders print view in viewer', function() {
cy.openFile('print.md')
cy.setCssMedia('print')

cy.getEditor().should('be.visible')
cy.getContent()
// Ensure cursor is not displayed to prevent flaky tests (flashing input cursor)
.invoke('css', 'caret-color', 'transparent')
.get('h1:not(.hidden-visually)').should('contain', 'Print test')
.should('be.visible')

cy.compareSnapshot('print view in viewer', { capture: 'fullPage' })
cy.setCssMedia('screen')
})

it('Renders print view in single-file share', function() {
cy.shareFile('/print.md', { edit: true })
.then((token) => {
cy.logout()
cy.visit(`/s/${token}`)
cy.setCssMedia('print')
})
.then(() => {
cy.getEditor().should('be.visible')
cy.getContent()
// Ensure cursor is not displayed to prevent flaky tests (flashing input cursor)
.invoke('css', 'caret-color', 'transparent')
.get('h1:not(.hidden-visually)').should('contain', 'Print test')
.should('be.visible')

cy.compareSnapshot('print view in single-file share', { capture: 'fullPage' })
cy.setCssMedia('screen')
})
})
})
86 changes: 86 additions & 0 deletions cypress/fixtures/print.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Print test

---

> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent augue turpis, viverra molestie pellentesque a, hendrerit nec turpis. Fusce fermentum felis sit amet consectetur posuere. Nullam eleifend nibh ut auctor varius. Vivamus pharetra efficitur libero, nec cursus dui faucibus non. Ut nec dapibus ligula. Duis tincidunt ex sem, nec convallis nisi ultrices suscipit. Sed sed sollicitudin lorem. Mauris congue tincidunt elementum. In sit amet sapien dictum, congue sapien sed, iaculis diam. Ut at pulvinar urna, a interdum velit. Aenean blandit magna vitae felis elementum dictum eget in neque. Suspendisse vulputate urna eu enim rhoncus sollicitudin. Nullam nec bibendum tortor.

- first
- second
- third
- fourth
- firth
- fifth
- fifth
- nineth

Suspendisse a ullamcorper ex. Nullam id odio in ligula bibendum vehicula. Mauris in porttitor risus, ac consequat purus. Morbi consequat odio at lobortis venenatis. Aenean blandit justo et purus dignissim euismod. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec volutpat fringilla justo nec fringilla. Nulla a leo vel arcu fringilla auctor. Quisque aliquam leo velit, sit amet faucibus nisl tincidunt a. Ut eget porttitor metus. Sed erat tortor, mollis at arcu at, posuere interdum massa. Suspendisse vestibulum massa et diam ultrices pulvinar. Donec sagittis dui sed vehicula pellentesque. Etiam eu interdum mauris.

- first
- second
- third
- fourth
- firth
- fifth
- fifth
- nineth

Praesent sed tincidunt nunc, vitae volutpat enim. Cras felis justo, porta pretium semper ut, bibendum non odio. Quisque nunc risus, faucibus at ipsum quis, finibus tempus nunc. Maecenas faucibus vehicula est non vehicula. Aenean eu tincidunt sapien, sed posuere enim. Donec id urna mi. Quisque eget massa posuere sem lacinia ultricies.

- first
- second
- third
- fourth
- firth
- fifth
- fifth
- nineth

Praesent eget nisi porta, efficitur nisl at, iaculis tortor. Curabitur risus neque, auctor vitae est eu, sagittis aliquam magna. Fusce eu finibus sapien, vitae pellentesque justo. Nam vitae lectus interdum, venenatis magna sed, hendrerit dolor. Mauris dapibus, arcu fermentum tempor ultricies, sapien nisl tempor ligula, a mollis est lectus vitae augue. Phasellus nec libero ac ante viverra dignissim quis sed velit. Curabitur nec odio iaculis, hendrerit purus quis, gravida nibh. Fusce risus dui, rutrum quis blandit at, laoreet ut est. Maecenas iaculis, purus a pulvinar lobortis, quam mauris pulvinar lectus, porttitor sagittis nisi lorem at dolor. Duis eleifend elit felis, ut blandit purus gravida quis. Maecenas ac mattis sem, ut egestas turpis.

- first
- second
- third
- fourth
- firth
- fifth
- fifth
- nineth

Pellentesque diam ante, placerat non ligula in, commodo viverra metus. Suspendisse ornare libero ac nunc fringilla, vel finibus ante tempor. Nunc et nunc efficitur, imperdiet orci sed, suscipit dolor. Donec eleifend, metus quis fermentum imperdiet, urna mi porta mi, sed lacinia purus sapien et purus. Sed id imperdiet sapien. Suspendisse ante enim, venenatis ut ultrices at, tristique nec felis. Etiam consectetur arcu nec malesuada hendrerit.

- first
- second
- third
- fourth
- firth
- fifth
- fifth
- nineth

Morbi dignissim enim fringilla, lacinia odio venenatis, luctus diam. Nulla porttitor lacus velit, sit amet ultrices arcu dictum a. Integer ultricies turpis sed ornare pharetra. Etiam consectetur est ac ornare accumsan. Nulla facilisi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Vivamus interdum dolor neque, id iaculis nisi efficitur a. Curabitur eu erat enim.

Mauris mattis lacinia sollicitudin. Aenean in justo id orci viverra dapibus in a nisi. Nulla porttitor lorem at augue commodo, eget feugiat justo bibendum. Cras elit neque, accumsan vitae ullamcorper at, aliquam non enim. Aliquam sagittis nunc sem, quis dictum nulla laoreet euismod. Quisque suscipit lorem non aliquam volutpat. Nam vel odio felis. Vivamus vestibulum quam vitae nisi sodales, eu fermentum arcu tristique. Proin pulvinar quam quis laoreet viverra. Sed vitae sagittis mauris. Cras finibus est at dui pharetra, vel ultrices tortor imperdiet.

- first
- second
- third
- fourth
- firth
- fifth
- fifth
- nineth

Morbi fringilla tellus nec mi congue ornare. Mauris maximus et ipsum vel scelerisque. Sed vel placerat massa. Quisque sagittis turpis ultrices eros cursus pellentesque. Cras et dolor sit amet lectus ullamcorper ullamcorper ac et dolor. Aenean in convallis justo. Maecenas velit felis, maximus vel posuere nec, molestie eget metus. Etiam interdum tellus erat, sit amet ultrices lacus hendrerit pellentesque. Suspendisse potenti. Integer ornare dignissim nulla eget viverra.

Duis ac lectus ultricies, feugiat ante nec, posuere justo. Vivamus mauris elit, fringilla id lectus a, venenatis dictum nisi. Maecenas tristique, metus elementum pulvinar tempus, purus nibh laoreet nunc, ultrices finibus est urna vitae elit. Cras in dui molestie, accumsan magna sed, maximus lacus. Suspendisse id libero at tortor congue vehicula nec eu dui. Nam purus nunc, tempus at hendrerit vulputate, rhoncus vitae lacus. Pellentesque mattis, augue et vehicula interdum, mi elit pharetra sapien, at consequat arcu tortor in dolor. Fusce neque nisl, pharetra et sapien a, ultrices mollis felis. Suspendisse accumsan lacus mauris, nec suscipit nisl tincidunt at. Phasellus in viverra libero, condimentum vulputate lacus.

- first
- second
- third
- fourth
- firth
- fifth
- fifth
- nineth

Suspendisse lacinia nulla scelerisque nisl egestas, ac eleifend ipsum lobortis. Vivamus ornare ultricies vestibulum. Interdum et malesuada fames ac ante ipsum primis in faucibus. Suspendisse rhoncus rhoncus risus quis iaculis. Aliquam condimentum enim non pellentesque auctor. Fusce blandit vulputate tincidunt. In vehicula tortor eget metus congue feugiat. Suspendisse nulla nisi, feugiat in nibh eu, placerat semper odio. Maecenas in tincidunt velit, eget egestas ex. Sed ac imperdiet ante, eget placerat enim. Sed eu dapibus mauris. Morbi eros nisi, porta at ornare in, congue at tortor. Morbi porttitor dapibus velit sed ultricies. Etiam vestibulum dolor nulla, id vehicula massa sodales eget. Maecenas eu vulputate nulla, eu aliquet nunc.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@

import axios from '@nextcloud/axios'
import { addCommands } from '@nextcloud/cypress'
import compareSnapshotCommand from 'cypress-visual-regression/dist/command.js'

// eslint-disable-next-line no-unused-vars,n/no-extraneous-import
import regeneratorRuntime from 'regenerator-runtime'

compareSnapshotCommand()

const url = Cypress.config('baseUrl').replace(/\/index.php\/?$/g, '')
Cypress.env('baseUrl', url)

Expand Down Expand Up @@ -418,6 +421,16 @@ Cypress.Commands.add('createDescription', () => {
cy.wait('@addDescription')
})

Cypress.Commands.add('setCssMedia', (media) => {
cy.log(`Setting CSS media to ${media}`)
Cypress.automation('remote:debugger:protocol', {
command: 'Emulation.setEmulatedMedia',
params: {
media,
},
})
})

Cypress.on(
'uncaught:exception',
err => !err.message.includes('ResizeObserver loop limit exceeded'),
Expand Down
Loading
Loading