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 | |||||
*/ | |||||
import {checkLanguageHighlighting} from '../utils'; | |||||
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… | |||||
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(this.Urls.tests_content_code_extension(ext)).then(response => { | |||||
let data = response.body; | |||||
cy.visit(`${this.Urls.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(this.Urls.tests_content_code_filename(filename)).then(response => { | |||||
let data = response.body; | |||||
cy.visit(`${this.Urls.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(this.Urls.tests_content_other_extension(ext)).then(response => { | |||||
let data = response.body; | |||||
cy.visit(`${this.Urls.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(this.Urls.tests_content_other_extension('pdf')).then(response => { | |||||
let data = response.body; | |||||
cy.visit(`${this.Urls.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); | |||||
}); | |||||
}); | |||||
}); | |||||
}); | |||||
describe('Jupyter notebook rendering test', function() { | |||||
it(`should render a notebook file to HTML`, function() { | |||||
cy.request(this.Urls.tests_content_other_extension('ipynb')).then(response => { | |||||
let data = response.body; | |||||
cy.visit(`${this.Urls.browse_content(data.sha1)}?path=file.ipynb`); | |||||
cy.get('.nb-notebook') | |||||
.should('be.visible') | |||||
.and('not.be.empty'); | |||||
cy.get('.nb-cell.nb-markdown-cell') | |||||
.should('be.visible') | |||||
.and('not.be.empty'); | |||||
cy.get('.nb-cell.nb-code-cell') | |||||
.should('be.visible') | |||||
.and('not.be.empty'); | |||||
cy.get('.MathJax') | |||||
.should('be.visible') | |||||
.and('not.be.empty'); | |||||
}); | |||||
}); | |||||
}); |
Should we move this to cypress/support/index.js so that it can be accessed by D1756 also?