Skip to content

Commit

Permalink
Only render presentation MathML
Browse files Browse the repository at this point in the history
* Add tests
  • Loading branch information
physikerwelt committed Feb 19, 2018
1 parent c1a1e6c commit 9dabb55
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion api/v1/controller/AbstractSyntaxTreeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = {
.then((ast) => {
Promise.all([
new ASTRenderer.Graph(ast).renderSingleTree(source),
MathJaxRenderer.renderMML(req.body.mathml)
MathJaxRenderer.renderMML(ast.presentation)
])
.then(([cytoscapedAST, mathjaxSVG]) => {
res.json({
Expand Down
1 change: 0 additions & 1 deletion public/html/ast-renderer.pug
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ html
option(value = mml[2]) Wide AST
option(value = mml[5]) Einstein
option(value = mml[9]) Goat
option(value = mml[10]) [PMML, CMML]
fieldset.form-group.option-type
legend Advanced Options
.form-check
Expand Down
23 changes: 16 additions & 7 deletions test/api/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,48 @@ describe('api test', () => {
const singleEndpoints = ['parseAST', 'renderPMML', 'parseCytoscapedAST', 'renderAST'];
const mergedEndpoints = ['renderMergedAST', 'parseCytoscapedMergedAst'];
const endpoints = singleEndpoints.concat(mergedEndpoints);
const parsingEndpoints = ['parseAST', 'parseCytoscapedAST'];
endpoints.forEach((t) => {
it('handle empty requests ' + t, function testSlash (done) {
it('handle empty requests ' + t, function testSlash(done) {
request(server)
.post(`/api/v1/math/${t}`)
.expect(400, done);
});
});
singleEndpoints.forEach((t) => {
it('handle invalid mathml requests ' + t, function testSlash (done) {
it('handle invalid mathml requests ' + t, function testSlash(done) {
request(server)
.post(`/api/v1/math/${t}`)
.field('mathml', '<math>this is not valid</math>')
.expect(422, done);
});
});
singleEndpoints.forEach((t) => {
it('handle mathml requests ' + t, function testSlash (done) {
it('handle mathml requests ' + t, function testSlash(done) {
request(server)
.post(`/api/v1/math/${t}`)
.field('mathml', app.locals.mml[0])
.expect(200, done);
});
});
singleEndpoints.forEach((t) => {
it('handle single mathml requests ' + t, function testSlash (done) {
it('handle single mathml requests ' + t, function testSlash(done) {
request(server)
.post(`/api/v1/math/${t}`)
.field('mathml', app.locals.mml[6])
.expect(200, done);
});
});
singleEndpoints.forEach((t) => {
it('handle presentation annotation requests ' + t, function testSlash (done) {
it('handle presentation annotation requests ' + t, function testSlash(done) {
request(server)
.post(`/api/v1/math/${t}`)
.field('mathml', app.locals.mml[7])
.expect(200, done);
});
});
mergedEndpoints.forEach((t) => {
it('handle mathml requests ' + t, function testSlash (done) {
it('handle mathml requests ' + t, function testSlash(done) {
request(server)
.post(`/api/v1/math/${t}`)
.field('reference_mathml', app.locals.mml[3])
Expand All @@ -62,7 +63,7 @@ describe('api test', () => {
});
});
mergedEndpoints.forEach((t) => {
it('handle invaldid mathml requests ' + t, function testSlash (done) {
it('handle invaldid mathml requests ' + t, function testSlash(done) {
request(server)
.post(`/api/v1/math/${t}`)
.field('reference_mathml', '<math>this is not valid</math>')
Expand All @@ -71,4 +72,12 @@ describe('api test', () => {
.expect(422, done);
});
});
parsingEndpoints.forEach((t) => {
it('parse swapped presentation and content structure ' + t, function testSlash(done) {
request(server)
.post(`/api/v1/math/${t}`)
.field('mathml', app.locals.mml[10])
.expect(200, done);
});
});
});

0 comments on commit 9dabb55

Please sign in to comment.