diff --git a/cypress/integration/webapp.spec.js b/cypress/integration/webapp.spec.js new file mode 100644 --- /dev/null +++ b/cypress/integration/webapp.spec.js @@ -0,0 +1,59 @@ +/** + * Copyright (C) 2019 The Software Heritage developers + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU Affero General Public License version 3, or any later version + * See top-level LICENSE file for more information + */ + +const url = '/' + +describe('Back-to-top button tests', function() { + beforeEach(function () { + cy.visit(url); + }) + + it('should be hidden when on top', function() { + cy.get('#back-to-top').should('not.be.visible'); + }) + + it('should be visible when scrolled down', function() { + cy.scrollTo('bottom') + .get('#back-to-top') + .should('be.visible'); + }) + + it('should scroll to top when clicked', function() { + cy.scrollTo('bottom') + .get('#back-to-top') + .click() + .window() + .then((window) => { + assert.equal(window.scrollY, 0); + }) + }) +}) + +describe('Sidebar tests', function() { + beforeEach(function () { + cy.visit(url); + }) + + it('should toggle sidebar when swh-push-menu is clicked', function() { + cy.get('.swh-push-menu') + .click() + .then(() => { + cy.get('body') + .should('have.class', 'sidebar-collapse') + .get('.nav-link > p') + .should('have.css', 'opacity', '0'); + }) + .get('.swh-push-menu') + .click() + .then(() => { + cy.get('body') + .should('have.class', 'sidebar-open') + .get('.nav-link > p') + .should('not.have.css', 'opacity', '0'); + }) + }) +}) diff --git a/swh/web/assets/src/bundles/webapp/webapp-utils.js b/swh/web/assets/src/bundles/webapp/webapp-utils.js --- a/swh/web/assets/src/bundles/webapp/webapp-utils.js +++ b/swh/web/assets/src/bundles/webapp/webapp-utils.js @@ -3,6 +3,13 @@ import {selectText} from 'utils/functions'; let collapseSidebar = false; +let width = 0; +width = $(window).width(); +console.log(width); +if (width < 992) { + collapseSidebar = true; + console.log(collapseSidebar); +} let previousSidebarState = localStorage.getItem('swh-sidebar-collapsed'); if (previousSidebarState !== undefined) { collapseSidebar = JSON.parse(previousSidebarState); @@ -25,6 +32,7 @@ $(document).on('DOMContentLoaded', () => { // restore previous sidebar state (collapsed/expanded) if (collapseSidebar) { + console.log(collapseSidebar); // hack to avoid animated transition for collapsing sidebar // when loading a page let sidebarTransition = $('.main-sidebar, .main-sidebar:before').css('transition'); @@ -37,6 +45,7 @@ setTimeout(() => { $('.main-sidebar, .main-sidebar:before').css('transition', sidebarTransition); $('.sidebar .nav-link p, .main-sidebar .brand-text, .sidebar .user-panel .info').css('transition', sidebarEltsTransition); + $('body').addClass('sidebar-collapse'); }); } });