Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/content-rendering.spec.js
- This file was added.
/** | |||||
* 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 | |||||
*/ | |||||
function checkLanguageHighlighting(language) { | |||||
kalpitk: Should we move this to cypress/support/index.js so that it can be accessed by D1756 also? | |||||
Done Inline ActionsI will rather move it in the cypress/integration/utils/index.js file. As this function is not needed in every tests, I think it is better to import it only when required. I will update that diff today with that change (and also rebase it on master). anlambert: I will rather move it in the `cypress/integration/utils/index.js` file. As this function is not… | |||||
cy.get('code') | |||||
.should('be.visible') | |||||
.and('have.class', 'hljs') | |||||
.and('have.class', language) | |||||
.and('not.be.empty') | |||||
.find('table.hljs-ln') | |||||
.should('be.visible') | |||||
.and('not.be.empty'); | |||||
} | |||||
describe('Code highlighting tests', function() { | |||||
const extensions = require('../fixtures/source-file-extensions.json'); | |||||
extensions.forEach(ext => { | |||||
it(`should highlight source files with extension ${ext}`, function() { | |||||
cy.request(`/tests/data/content/code/extension/${ext}`).then(response => { | |||||
let data = response.body; | |||||
cy.visit(`/browse/content/${data.sha1}/?path=file.${ext}`); | |||||
checkLanguageHighlighting(data.language); | |||||
}); | |||||
}); | |||||
}); | |||||
const filenames = require('../fixtures/source-file-names.json'); | |||||
filenames.forEach(filename => { | |||||
it(`should highlight source files with filenames ${filename}`, function() { | |||||
cy.request(`/tests/data/content/code/filename/${filename}`).then(response => { | |||||
let data = response.body; | |||||
cy.visit(`/browse/content/${data.sha1}/?path=${filename}`); | |||||
checkLanguageHighlighting(data.language); | |||||
}); | |||||
}); | |||||
}); | |||||
}); | |||||
describe('Image rendering tests', function() { | |||||
const imgExtensions = ['gif', 'jpeg', 'png', 'webp']; | |||||
imgExtensions.forEach(ext => { | |||||
it(`should render image with extension ${ext}`, function() { | |||||
cy.request(`/tests/data/content/other/extension/${ext}`).then(response => { | |||||
let data = response.body; | |||||
cy.visit(`/browse/content/${data.sha1}/?path=file.${ext}`); | |||||
cy.get('.swh-content img') | |||||
.then(img => { | |||||
assert.notEqual(img[0].width, 0); | |||||
assert.notEqual(img[0].height, 0); | |||||
}); | |||||
}); | |||||
}); | |||||
}); | |||||
}); | |||||
describe('PDF rendering test', function() { | |||||
function sum(previousValue, currentValue) { | |||||
return previousValue + currentValue; | |||||
} | |||||
it(`should render a PDF file`, function() { | |||||
cy.request(`/tests/data/content/other/extension/pdf`).then(response => { | |||||
let data = response.body; | |||||
cy.visit(`/browse/content/${data.sha1}/?path=file.pdf`); | |||||
cy.get('.swh-content canvas') | |||||
.wait(2000) | |||||
.then(canvas => { | |||||
let width = canvas[0].width; | |||||
let height = canvas[0].height; | |||||
let context = canvas[0].getContext('2d'); | |||||
let imgData = context.getImageData(0, 0, width, height); | |||||
assert.notEqual(imgData.data.reduce(sum), 0); | |||||
}); | |||||
}); | |||||
}); | |||||
}); |
Should we move this to cypress/support/index.js so that it can be accessed by D1756 also?