diff --git a/mathquill4quill.js b/mathquill4quill.js index ffeb08d..eaeebfd 100644 --- a/mathquill4quill.js +++ b/mathquill4quill.js @@ -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) { @@ -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 diff --git a/tests/commandOperatorButton.test.js b/tests/commandOperatorButton.test.js new file mode 100644 index 0000000..6630236 --- /dev/null +++ b/tests/commandOperatorButton.test.js @@ -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(); + } +}; diff --git a/tests/latexOperatorButton.test.js b/tests/latexOperatorButton.test.js new file mode 100644 index 0000000..236676b --- /dev/null +++ b/tests/latexOperatorButton.test.js @@ -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(); + } +};