diff --git a/cypress/integration/layout.spec.js b/cypress/integration/layout.spec.js --- a/cypress/integration/layout.spec.js +++ b/cypress/integration/layout.spec.js @@ -8,8 +8,11 @@ const url = '/'; describe('Test top-bar', function() { - it('should should contain all navigation links', function() { + beforeEach(function() { + cy.clearLocalStorage(); cy.visit(url); + }); + it('should should contain all navigation links', function() { cy.get('.swh-top-bar a') .should('have.length.of.at.least', 4) .and('be.visible') @@ -17,17 +20,68 @@ }); it('should show donate button on lg screen', function() { - cy.visit(url); cy.get('.swh-donate-link') .should('be.visible'); }); it('should hide donate button on sm screen', function() { cy.viewport(600, 800); - cy.visit(url); cy.get('.swh-donate-link') .should('not.be.visible'); }); + it('should change container width when toggling Full width switch', function() { + cy.get('#swh-web-content') + .should('have.class', 'container') + .should('not.have.class', 'container-fluid'); + + cy.should(() => { + expect(JSON.parse(localStorage.getItem('swh-web-full-width'))).to.be.null; + }); + + cy.get('#swh-full-width-switch') + .click({force: true}); + + cy.get('#swh-web-content') + .should('not.have.class', 'container') + .should('have.class', 'container-fluid'); + + cy.should(() => { + expect(JSON.parse(localStorage.getItem('swh-web-full-width'))).to.be.true; + }); + + cy.get('#swh-full-width-switch') + .click({force: true}); + + cy.get('#swh-web-content') + .should('have.class', 'container') + .should('not.have.class', 'container-fluid'); + + cy.should(() => { + expect(JSON.parse(localStorage.getItem('swh-web-full-width'))).to.be.false; + }); + }); + it('should restore container width when loading page again', function() { + cy.visit(url) + .get('#swh-web-content') + .should('have.class', 'container') + .should('not.have.class', 'container-fluid'); + + cy.get('#swh-full-width-switch') + .click({force: true}); + + cy.visit(url) + .get('#swh-web-content') + .should('not.have.class', 'container') + .should('have.class', 'container-fluid'); + + cy.get('#swh-full-width-switch') + .click({force: true}); + + cy.visit(url) + .get('#swh-web-content') + .should('have.class', 'container') + .should('not.have.class', 'container-fluid'); + }); }); describe('Test footer', function() { 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 @@ -313,3 +313,26 @@ export function getSwhIdsContext() { return swhidsContext_; } + +function setFullWidth(fullWidth) { + if (fullWidth) { + $('#swh-web-content').removeClass('container'); + $('#swh-web-content').addClass('container-fluid'); + } else { + $('#swh-web-content').removeClass('container-fluid'); + $('#swh-web-content').addClass('container'); + } + localStorage.setItem('swh-web-full-width', JSON.stringify(fullWidth)); + $('#swh-full-width-switch').prop('checked', fullWidth); +} + +export function fullWidthToggled(event) { + setFullWidth($(event.target).prop('checked')); +} + +export function setContainerFullWidth() { + let previousFullWidthState = JSON.parse(localStorage.getItem('swh-web-full-width')); + if (previousFullWidthState !== null) { + setFullWidth(previousFullWidthState); + } +} diff --git a/swh/web/templates/layout.html b/swh/web/templates/layout.html --- a/swh/web/templates/layout.html +++ b/swh/web/templates/layout.html @@ -71,11 +71,12 @@
@@ -186,7 +188,7 @@
-
+
{% block content %}{% endblock %}
@@ -215,6 +217,9 @@
back to top
+