diff --git a/cypress/integration/directory.spec.js b/cypress/integration/directory.spec.js new file mode 100644 --- /dev/null +++ b/cypress/integration/directory.spec.js @@ -0,0 +1,79 @@ +/** + * 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 + */ + +import {httpGetJson} from './utils'; + +const url = 'browse/origin/https://github.com/memononen/libtess2/directory/'; +const $ = Cypress.$; + +let dirs, files; + +describe('Directory Tests', function() { + + before(function() { + cy.visit(url); + cy.window().then(async win => { + const metadata = win.swh.webapp.getBrowsedSwhObjectMetadata(); + const apiUrl = Cypress.config().baseUrl + '/api/1/directory/' + metadata.directory; + let dirContent = await httpGetJson(apiUrl); + files = []; + dirs = []; + for (let entry of dirContent) { + if (entry.type === 'file') { + files.push(entry); + } else { + dirs.push(entry); + } + } + }); + }); + + beforeEach(function() { + cy.visit(url); + }); + + it('should display all files and directories', function() { + cy.get('.swh-directory') + .should('have.length', dirs.length) + .and('be.visible'); + cy.get('.swh-content') + .should('have.length', files.length) + .and('be.visible'); + }); + + it('should display sizes for files', function() { + cy.get('.swh-content') + .parent('tr') + .then((rows) => { + for (let row of rows) { + let text = $(row).children('td').eq(2).text(); + expect(text.trim()).to.not.be.empty; + } + }); + }); + + it('should display readme when it is present', function() { + cy.get('#readme-panel > .card-body') + .should('be.visible') + .and('have.class', 'swh-showdown') + .and('not.be.empty') + .and('not.contain', 'Readme bytes are not available'); + }); + + it('should open subdirectory when clicked', function() { + cy.get('.swh-directory') + .first() + .children('a') + .click(); + + cy.url() + .should('include', url + dirs[0]['name']); + + cy.get('.swh-directory-table') + .should('be.visible'); + }); +}); diff --git a/cypress/integration/utils.js b/cypress/integration/utils.js new file mode 100644 --- /dev/null +++ b/cypress/integration/utils.js @@ -0,0 +1,6 @@ +import axios from 'axios'; + +export async function httpGetJson(url) { + const response = await axios.get(url); + return response.data; +} diff --git a/package.json b/package.json --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "@babel/plugin-transform-runtime": "^7.4.4", "@babel/preset-env": "^7.4.5", "autoprefixer": "^9.6.0", + "axios": "^0.19.0", "babel-eslint": "^10.0.2", "babel-loader": "^8.0.6", "bootstrap-loader": "^3.0.4", @@ -63,6 +64,7 @@ "ejs": "^2.6.2", "eslint": "^5.15.3", "eslint-loader": "^2.1.2", + "eslint-plugin-chai-friendly": "^0.4.1", "eslint-plugin-import": "^2.17.3", "eslint-plugin-node": "^9.1.0", "eslint-plugin-promise": "^4.1.1", diff --git a/swh/web/assets/config/.eslintrc b/swh/web/assets/config/.eslintrc --- a/swh/web/assets/config/.eslintrc +++ b/swh/web/assets/config/.eslintrc @@ -22,7 +22,8 @@ "node", "promise", "standard", - "cypress" + "cypress", + "chai-friendly" ], "globals": { @@ -209,11 +210,7 @@ "no-unreachable": "error", "no-unsafe-finally": "error", "no-unsafe-negation": "error", - "no-unused-expressions": ["error", { - "allowShortCircuit": true, - "allowTernary": true, - "allowTaggedTemplates": true - }], + "no-unused-expressions": 0, "no-unused-vars": ["error", { "vars": "all", "args": "none", @@ -305,6 +302,7 @@ "standard/array-bracket-even-spacing": ["error", "either"], "standard/computed-property-even-spacing": ["error", "even"], "standard/no-callback-literal": "error", - "standard/object-curly-even-spacing": ["error", "either"] + "standard/object-curly-even-spacing": ["error", "either"], + "chai-friendly/no-unused-expressions": 2 } } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock --- a/yarn.lock +++ b/yarn.lock @@ -1299,6 +1299,14 @@ resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f" integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ== +axios@^0.19.0: + version "0.19.0" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.0.tgz#8e09bff3d9122e133f7b8101c8fbdd00ed3d2ab8" + integrity sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ== + dependencies: + follow-redirects "1.5.10" + is-buffer "^2.0.2" + babel-eslint@^10.0.2: version "10.0.2" resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-10.0.2.tgz#182d5ac204579ff0881684b040560fdcc1558456" @@ -2949,6 +2957,13 @@ dependencies: ms "^2.1.1" +debug@=3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" + integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g== + dependencies: + ms "2.0.0" + debug@^4.0.1, debug@^4.1.0, debug@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791" @@ -3412,6 +3427,11 @@ debug "^2.6.8" pkg-dir "^2.0.0" +eslint-plugin-chai-friendly@^0.4.1: + version "0.4.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-chai-friendly/-/eslint-plugin-chai-friendly-0.4.1.tgz#9eeb17f92277ba80bb64f0e946c6936a3ae707b4" + integrity sha512-hkpLN7VVoGGsofZjUhcQ+sufC3FgqMJwD0DvAcRfxY1tVRyQyVsqpaKnToPHJQOrRo0FQ0fSEDwW2gr4rsNdGA== + eslint-plugin-cypress@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/eslint-plugin-cypress/-/eslint-plugin-cypress-2.2.1.tgz#17295d8ef76984fe05886c7c5830ba216c1f9717" @@ -4005,6 +4025,13 @@ inherits "^2.0.3" readable-stream "^2.3.6" +follow-redirects@1.5.10: + version "1.5.10" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a" + integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ== + dependencies: + debug "=3.1.0" + follow-redirects@^1.0.0: version "1.7.0" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.7.0.tgz#489ebc198dc0e7f64167bd23b03c4c19b5784c76" @@ -4940,7 +4967,7 @@ resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w== -is-buffer@^2.0.0: +is-buffer@^2.0.0, is-buffer@^2.0.2: version "2.0.3" resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.3.tgz#4ecf3fcf749cbd1e472689e109ac66261a25e725" integrity sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw==