Skip to content

Commit

Permalink
Improve command operator regex (#74)
Browse files Browse the repository at this point in the history
* Improve command operator regex

* Add tests for operator buttons both command and latex string

* Added new assertion to check if the operator was properly rendered
  • Loading branch information
ahmed2m authored May 7, 2021
1 parent 16df556 commit 16117a8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
6 changes: 2 additions & 4 deletions mathquill4quill.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ window.mathquill4quill = function(dependencies) {
}

function isOperatorCommand(operator) {
if (/\[|\{|\(/.test(operator)) {
return false;
}
return true;
return /^\\[A-Za-z]+$/.test(operator);
}

function enableMathQuillFormulaAuthoring(quill, options) {
Expand Down Expand Up @@ -225,6 +222,7 @@ window.mathquill4quill = function(dependencies) {

const button = document.createElement("button");
button.setAttribute("type", "button");
button.setAttribute("data-value", operator);

katex.render(displayOperator, button, {
throwOnError: false
Expand Down
26 changes: 26 additions & 0 deletions tests/commandOperatorButton.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-env node */

module.exports = {
"Is the formula editor visible": function(browser) {
browser
.useXpath()
.url("http://localhost:8000/?&operators=true")
.waitForElementVisible('//*[@id="editor"]')
.click('//button[@class="ql-formula"]')
.waitForElementVisible('//div[@data-mode="formula"]');
},
"Is command operator button working": function(browser) {
browser
.useXpath()
.click('//button[@data-value="\\sqrt"]')
.waitForElementVisible('//span[@class="mq-scaled mq-sqrt-prefix"]')
.click('//a[@class="ql-action"]')
.waitForElementVisible('//span[@class="ql-formula"]')
.assert.attributeContains(
'//span[@class="ql-formula"]',
"data-value",
"\\sqrt"
)
.end();
}
};
26 changes: 26 additions & 0 deletions tests/latexOperatorButton.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-env node */

module.exports = {
"Is the formula editor visible": function(browser) {
browser
.useXpath()
.url("http://localhost:8000/?&operators=true")
.waitForElementVisible('//*[@id="editor"]')
.click('//button[@class="ql-formula"]')
.waitForElementVisible('//div[@data-mode="formula"]');
},
"Is latex string button working": function(browser) {
browser
.useXpath()
.click('//button[@data-value="\\sqrt[3]{}"]')
.waitForElementVisible('//sup[@class="mq-nthroot mq-non-leaf"]')
.click('//a[@class="ql-action"]')
.waitForElementVisible('//span[@class="ql-formula"]')
.assert.attributeContains(
'//span[@class="ql-formula"]',
"data-value",
"\\sqrt[3]{}"
)
.end();
}
};

0 comments on commit 16117a8

Please sign in to comment.