diff --git a/cypress/integration/content-view.spec.js b/cypress/integration/content-view.spec.js new file mode 100644 --- /dev/null +++ b/cypress/integration/content-view.spec.js @@ -0,0 +1,65 @@ +/** + * 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 = 'browse/origin/https://github.com/memononen/libtess2/content/Source/tess.h'; + +let fileName, filePath, sha1git, rawFilePath, numberLines; + +describe('Test File Rendering', function() { + before(function() { + cy.visit(url); + cy.window().then(async win => { + const metadata = win.swh.webapp.getBrowsedSwhObjectMetadata(); + + fileName = metadata.filename; + filePath = metadata.path; + sha1git = metadata.sha1_git; + rawFilePath = '/browse/content/sha1_git:' + sha1git + + '/raw/?filename=' + encodeURIComponent(fileName); + + cy.request(rawFilePath) + .then((response) => { + numberLines = response.body.split('\n').length; + }); + }); + }); + + beforeEach(function() { + cy.visit(url); + }); + + it('should display correct file name', function() { + cy.get('.card-header') + .should('be.visible') + .and('contain', fileName) + .and('have.css', 'background-color', 'rgb(242, 244, 245)'); + }); + + it('should display all lines', function() { + cy.get('.hljs-ln-code') + .should('have.length', numberLines) + .and('be.visible') + .and('have.css', 'background-color', 'rgba(0, 0, 0, 0)'); + }); + + it('should show correct path', function() { + // Array containing names of all the parent directories of the file + const filePathArr = filePath.slice(1, -1).slice('/'); + + filePathArr.split('/').forEach(dirName => { + cy.get('.swh-browse-bread-crumbs') + .should('contain', dirName); + }); + }); + + it('should have correct url to raw file', function() { + cy.get('.swh-actions-dropdown > a') + .should('be.visible') + .and('contain', 'Raw File') + .and('have.attr', 'href', rawFilePath); + }); +});