Skip to content

Commit

Permalink
Merge pull request #1177 from nextcloud/feat/enabled-previews
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv committed Mar 3, 2022
2 parents 86b0921 + 166426b commit 011519f
Show file tree
Hide file tree
Showing 9 changed files with 14,797 additions and 11,652 deletions.
45 changes: 10 additions & 35 deletions cypress/integration/sidebar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ describe('Open the sidebar from the viewer and open viewer with sidebar already
cy.get('body > .viewer .modal-header button.header-close').should('be.visible')
})

it('Does not have any visual regression 1', function() {
// cy.matchImageSnapshot()
})

it('Open the sidebar', function() {
// open the menu
cy.get('body > .viewer .modal-header button.action-item__menutoggle').click()
Expand All @@ -87,20 +83,19 @@ describe('Open the sidebar from the viewer and open viewer with sidebar already
cy.get('.action-button__icon.icon-menu-sidebar').should('not.exist')
// check the sidebar is opened for the correct file
cy.get('aside.app-sidebar .app-sidebar-header .app-sidebar-header__maintitle').should('contain', 'image1.jpg')
// check we indeed have a preview
// check we do not have a preview
cy.get('aside.app-sidebar .app-sidebar-header').should('have.class', 'app-sidebar-header--with-figure')
cy.getFileId('image1.jpg').then(fileID1 => {
cy.get('aside.app-sidebar .app-sidebar-header .app-sidebar-header__figure').should('have.attr', 'style').should('contain', fileID1)
})

cy.get('aside.app-sidebar .app-sidebar-header').should('have.class', 'app-sidebar-header--compact')
cy.get('aside.app-sidebar .app-sidebar-header .app-sidebar-header__figure').should('have.attr', 'style').should('contain', 'core/filetypes')
})

it('Does not have any visual regression 2', function() {
// Comments have the user's username which is randomly generated for tests causing a difference in the snapshot.
// Switch to sharing section to avoid the issue.
cy.get('aside.app-sidebar a#sharing').click()

// cy.matchImageSnapshot()
it('Sidebar is in compact mode', function() {
// check the sidebar is opened for the correct file
cy.get('aside.app-sidebar .app-sidebar-header .app-sidebar-header__maintitle').should('contain', 'image1.jpg')
// check we do not have a preview
cy.get('aside.app-sidebar .app-sidebar-header').should('have.class', 'app-sidebar-header--with-figure')
cy.get('aside.app-sidebar .app-sidebar-header').should('have.class', 'app-sidebar-header--compact')
cy.get('aside.app-sidebar .app-sidebar-header .app-sidebar-header__figure').should('have.attr', 'style').should('contain', 'core/filetypes')
})

it('Change to next image with sidebar open', function() {
Expand All @@ -114,14 +109,6 @@ describe('Open the sidebar from the viewer and open viewer with sidebar already
cy.get('aside.app-sidebar .app-sidebar-header .app-sidebar-header__maintitle').should('contain', 'image2.jpg')
})

it('Does not have any visual regression 3', function() {
// Comments have the user's username which is randomly generated for tests causing a difference in the snapshot.
// Switch to sharing section to avoid the issue.
cy.get('aside.app-sidebar a#sharing').click()

// cy.matchImageSnapshot()
})

it('Change to previous image with sidebar open', function() {
cy.get('aside.app-sidebar').should('be.visible')

Expand All @@ -133,14 +120,6 @@ describe('Open the sidebar from the viewer and open viewer with sidebar already
cy.get('aside.app-sidebar .app-sidebar-header .app-sidebar-header__maintitle').should('contain', 'image1.jpg')
})

it('Does not have any visual regression 4', function() {
// Comments have the user's username which is randomly generated for tests causing a difference in the snapshot.
// Switch to sharing section to avoid the issue.
cy.get('aside.app-sidebar a#sharing').click()

// cy.matchImageSnapshot()
})

it('Close the sidebar', function() {
cy.get('aside.app-sidebar .app-sidebar-header .app-sidebar__close').click()
cy.get('aside.app-sidebar').should('not.exist')
Expand Down Expand Up @@ -169,8 +148,4 @@ describe('Open the sidebar from the viewer and open viewer with sidebar already
cy.get('aside.app-sidebar').should('not.exist')
cy.get('body > .viewer .modal-header button.action-item__menutoggle').should('be.visible')
})

it('Does not have any visual regression 5', function() {
// cy.matchImageSnapshot()
})
})
4 changes: 2 additions & 2 deletions js/viewer-main.js

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions js/viewer-main.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,10 @@ object-assign
*/

/**
* @copyright Copyright (c) 2020 Azul <azul@riseup.net>
* @copyright Copyright (c) 2019 Marco Ambrosini <marcoambrosini@pm.me>
*
* @author Azul <azul@riseup.net>
* @author Marco Ambrosini <marcoambrosini@pm.me>
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -203,9 +204,9 @@ object-assign
*/

/**
* @copyright Copyright (c) 2021 John Molakvoæ <skjnldsv@protonmail.com>
* @copyright Copyright (c) 2020 Azul <azul@riseup.net>
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
* @author Azul <azul@riseup.net>
*
* @license GNU AGPL version 3 or any later version
*
Expand Down
2 changes: 1 addition & 1 deletion js/viewer-main.js.map

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion lib/Listener/LoadViewerScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,35 @@

namespace OCA\Viewer\Listener;

use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Viewer\AppInfo\Application;
use OCA\Viewer\Event\LoadViewer;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCP\AppFramework\Services\IInitialState;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IPreview;
use OCP\Util;

class LoadViewerScript implements IEventListener {

/** @var IInitialState */
private $initialStateService;

/** @var IPreview */
private $previewManager;

public function __construct(IInitialState $initialStateService,
IPreview $previewManager) {
$this->initialStateService = $initialStateService;
$this->previewManager = $previewManager;
}

public function handle(Event $event): void {
if (!($event instanceof LoadViewer || $event instanceof LoadAdditionalScriptsEvent)) {
return;
}

Util::addScript(Application::APP_ID, 'viewer-main', 'files');
$this->initialStateService->provideInitialState('enabled_preview_providers', array_keys($this->previewManager->getProviders()));
}
}
Loading

0 comments on commit 011519f

Please sign in to comment.