diff --git a/cypress/integration/visits.spec.js b/cypress/integration/visits.spec.js new file mode 100644 --- /dev/null +++ b/cypress/integration/visits.spec.js @@ -0,0 +1,46 @@ +/** + * 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 {getTime} from '../utils'; + +let repo = 'https://github.com/wcoder/highlightjs-line-numbers.js'; + +function checkTimeLink(element) { + expect(element.text()).not.to.be.empty; + + let timeStringLink = element.attr('href').split('visit/')[1].split('/')[0]; + + // time in link should be equal to that in text + assert.deepEqual(getTime(timeStringLink), getTime(element.text())); +} + +describe('Visits tests', function() { + beforeEach(function() { + cy.visit(this.Urls.browse_origin_visits(repo)); + }); + + it('should display first full visit time', function() { + cy.get('#swh-first-full-visit > .swh-visit-full') + .then(($el) => { + checkTimeLink($el); + }); + }); + + it('should display last full visit time', function() { + cy.get('#swh-last-full-visit > .swh-visit-full') + .then(($el) => { + checkTimeLink($el); + }); + }); + + it('should display last visit time', function() { + cy.get('#swh-last-visit > .swh-visit-full') + .then(($el) => { + checkTimeLink($el); + }); + }); +}); diff --git a/cypress/utils/index.js b/cypress/utils/index.js --- a/cypress/utils/index.js +++ b/cypress/utils/index.js @@ -11,3 +11,21 @@ const response = await axios.get(url); return response.data; } + +/** + * converts string with Time ("Day Month(name) Year, hours:mins UTC") + * into object with Time information + */ +export function getTime(text) { + const date = new Date(text); + + let time = { + date: date.getUTCDate(), + month: date.getUTCMonth(), + year: date.getUTCFullYear(), + hours: date.getUTCHours(), + minutes: date.getUTCMinutes() + }; + + return time; +}