canvas-lms/spec/lib/math_man_spec.rb

119 lines
3.4 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
#
# Copyright (C) 2016 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
enable use of MathMan for latex => mathml conversion fixes CNVS-59514 Also adds a MathMan module that wraps some convenience methods for 1- figuring out if it's ok to use mathman; 2- constructing urls for hitting mathman's endpoints. test plan: *With Ritex* - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. *With Mathman* - Navigate to an account's plugin page, and select the MathMan plugin. - On the edit screen, enable the plugin, and provide a working mathman base url and check the 'Use for mml' checkbox. Save the changes. - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. Change-Id: I194d155b339123f7ed1948cf29070c1d17fc7f17 Reviewed-on: https://gerrit.instructure.com/84031 Tested-by: Jenkins Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Benjamin Christian Nelson <bcnelson@instructure.com> Product-Review: John Corrigan <jcorrigan@instructure.com>
2016-08-02 03:28:43 +08:00
describe MathMan do
let(:latex) do
'\sqrt{25}+12^{12}'
end
# we explicitly don't want a trailing slash here for the url tests
let(:service_url) { 'http://www.mml-service.com/beta' }
enable use of MathMan for latex => mathml conversion fixes CNVS-59514 Also adds a MathMan module that wraps some convenience methods for 1- figuring out if it's ok to use mathman; 2- constructing urls for hitting mathman's endpoints. test plan: *With Ritex* - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. *With Mathman* - Navigate to an account's plugin page, and select the MathMan plugin. - On the edit screen, enable the plugin, and provide a working mathman base url and check the 'Use for mml' checkbox. Save the changes. - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. Change-Id: I194d155b339123f7ed1948cf29070c1d17fc7f17 Reviewed-on: https://gerrit.instructure.com/84031 Tested-by: Jenkins Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Benjamin Christian Nelson <bcnelson@instructure.com> Product-Review: John Corrigan <jcorrigan@instructure.com>
2016-08-02 03:28:43 +08:00
let(:use_for_mml) { false }
let(:use_for_svg) { false }
before do
@original_fallback = Canvas::DynamicSettings.fallback_data
Canvas::DynamicSettings.fallback_data = {
config: {
canvas: {
'math-man': {
base_url: service_url,
}
}
enable use of MathMan for latex => mathml conversion fixes CNVS-59514 Also adds a MathMan module that wraps some convenience methods for 1- figuring out if it's ok to use mathman; 2- constructing urls for hitting mathman's endpoints. test plan: *With Ritex* - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. *With Mathman* - Navigate to an account's plugin page, and select the MathMan plugin. - On the edit screen, enable the plugin, and provide a working mathman base url and check the 'Use for mml' checkbox. Save the changes. - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. Change-Id: I194d155b339123f7ed1948cf29070c1d17fc7f17 Reviewed-on: https://gerrit.instructure.com/84031 Tested-by: Jenkins Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Benjamin Christian Nelson <bcnelson@instructure.com> Product-Review: John Corrigan <jcorrigan@instructure.com>
2016-08-02 03:28:43 +08:00
}
}
PluginSetting.create!(
name: 'mathman',
settings: {
use_for_mml: use_for_mml,
use_for_svg: use_for_svg
}.with_indifferent_access
)
end
after do
Canvas::DynamicSettings.fallback_data = @original_fallback
enable use of MathMan for latex => mathml conversion fixes CNVS-59514 Also adds a MathMan module that wraps some convenience methods for 1- figuring out if it's ok to use mathman; 2- constructing urls for hitting mathman's endpoints. test plan: *With Ritex* - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. *With Mathman* - Navigate to an account's plugin page, and select the MathMan plugin. - On the edit screen, enable the plugin, and provide a working mathman base url and check the 'Use for mml' checkbox. Save the changes. - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. Change-Id: I194d155b339123f7ed1948cf29070c1d17fc7f17 Reviewed-on: https://gerrit.instructure.com/84031 Tested-by: Jenkins Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Benjamin Christian Nelson <bcnelson@instructure.com> Product-Review: John Corrigan <jcorrigan@instructure.com>
2016-08-02 03:28:43 +08:00
end
describe '.url_for' do
it 'must retain the path from base_url setting' do
url = MathMan.url_for(latex: latex, target: :mml)
parsed = Addressable::URI.parse(url)
expect(parsed.path).to eq('/beta/mml')
end
it 'includes target string in generated url' do
enable use of MathMan for latex => mathml conversion fixes CNVS-59514 Also adds a MathMan module that wraps some convenience methods for 1- figuring out if it's ok to use mathman; 2- constructing urls for hitting mathman's endpoints. test plan: *With Ritex* - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. *With Mathman* - Navigate to an account's plugin page, and select the MathMan plugin. - On the edit screen, enable the plugin, and provide a working mathman base url and check the 'Use for mml' checkbox. Save the changes. - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. Change-Id: I194d155b339123f7ed1948cf29070c1d17fc7f17 Reviewed-on: https://gerrit.instructure.com/84031 Tested-by: Jenkins Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Benjamin Christian Nelson <bcnelson@instructure.com> Product-Review: John Corrigan <jcorrigan@instructure.com>
2016-08-02 03:28:43 +08:00
expect(MathMan.url_for(latex: latex, target: :mml)).to match(/mml/)
expect(MathMan.url_for(latex: latex, target: :svg)).to match(/svg/)
end
it 'errors if DynamicSettings is not configured' do
Canvas::DynamicSettings.fallback_data = nil
expect { MathMan.url_for(latex: latex, target: :mml) }.to raise_error MathMan::InvalidConfigurationError
end
enable use of MathMan for latex => mathml conversion fixes CNVS-59514 Also adds a MathMan module that wraps some convenience methods for 1- figuring out if it's ok to use mathman; 2- constructing urls for hitting mathman's endpoints. test plan: *With Ritex* - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. *With Mathman* - Navigate to an account's plugin page, and select the MathMan plugin. - On the edit screen, enable the plugin, and provide a working mathman base url and check the 'Use for mml' checkbox. Save the changes. - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. Change-Id: I194d155b339123f7ed1948cf29070c1d17fc7f17 Reviewed-on: https://gerrit.instructure.com/84031 Tested-by: Jenkins Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Benjamin Christian Nelson <bcnelson@instructure.com> Product-Review: John Corrigan <jcorrigan@instructure.com>
2016-08-02 03:28:43 +08:00
end
describe '.use_for_mml?' do
it 'returns false when set to false' do
expect(MathMan.use_for_mml?).to be_falsey
end
it 'returns false when PluginSetting is missing' do
PluginSetting.where(name: 'mathman').first.destroy
enable use of MathMan for latex => mathml conversion fixes CNVS-59514 Also adds a MathMan module that wraps some convenience methods for 1- figuring out if it's ok to use mathman; 2- constructing urls for hitting mathman's endpoints. test plan: *With Ritex* - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. *With Mathman* - Navigate to an account's plugin page, and select the MathMan plugin. - On the edit screen, enable the plugin, and provide a working mathman base url and check the 'Use for mml' checkbox. Save the changes. - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. Change-Id: I194d155b339123f7ed1948cf29070c1d17fc7f17 Reviewed-on: https://gerrit.instructure.com/84031 Tested-by: Jenkins Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Benjamin Christian Nelson <bcnelson@instructure.com> Product-Review: John Corrigan <jcorrigan@instructure.com>
2016-08-02 03:28:43 +08:00
expect(MathMan.use_for_mml?).to be_falsey
end
it 'does not error if DynamicSettings is not configured' do
Canvas::DynamicSettings.fallback_data = nil
expect(MathMan.use_for_mml?).to be_falsey
end
enable use of MathMan for latex => mathml conversion fixes CNVS-59514 Also adds a MathMan module that wraps some convenience methods for 1- figuring out if it's ok to use mathman; 2- constructing urls for hitting mathman's endpoints. test plan: *With Ritex* - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. *With Mathman* - Navigate to an account's plugin page, and select the MathMan plugin. - On the edit screen, enable the plugin, and provide a working mathman base url and check the 'Use for mml' checkbox. Save the changes. - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. Change-Id: I194d155b339123f7ed1948cf29070c1d17fc7f17 Reviewed-on: https://gerrit.instructure.com/84031 Tested-by: Jenkins Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Benjamin Christian Nelson <bcnelson@instructure.com> Product-Review: John Corrigan <jcorrigan@instructure.com>
2016-08-02 03:28:43 +08:00
context 'when appropriately configured' do
let(:use_for_mml) { true }
it 'returns true' do
expect(MathMan.use_for_mml?).to be_truthy
end
end
end
describe '.use_for_svg?' do
it 'returns false when set to false' do
expect(MathMan.use_for_svg?).to be_falsey
end
it 'returns false when PluginSetting is missing' do
PluginSetting.where(name: 'mathman').first.destroy
enable use of MathMan for latex => mathml conversion fixes CNVS-59514 Also adds a MathMan module that wraps some convenience methods for 1- figuring out if it's ok to use mathman; 2- constructing urls for hitting mathman's endpoints. test plan: *With Ritex* - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. *With Mathman* - Navigate to an account's plugin page, and select the MathMan plugin. - On the edit screen, enable the plugin, and provide a working mathman base url and check the 'Use for mml' checkbox. Save the changes. - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. Change-Id: I194d155b339123f7ed1948cf29070c1d17fc7f17 Reviewed-on: https://gerrit.instructure.com/84031 Tested-by: Jenkins Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Benjamin Christian Nelson <bcnelson@instructure.com> Product-Review: John Corrigan <jcorrigan@instructure.com>
2016-08-02 03:28:43 +08:00
expect(MathMan.use_for_svg?).to be_falsey
end
it 'does not error if DynamicSettings is not configured' do
Canvas::DynamicSettings.fallback_data = nil
expect(MathMan.use_for_svg?).to be_falsey
end
enable use of MathMan for latex => mathml conversion fixes CNVS-59514 Also adds a MathMan module that wraps some convenience methods for 1- figuring out if it's ok to use mathman; 2- constructing urls for hitting mathman's endpoints. test plan: *With Ritex* - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. *With Mathman* - Navigate to an account's plugin page, and select the MathMan plugin. - On the edit screen, enable the plugin, and provide a working mathman base url and check the 'Use for mml' checkbox. Save the changes. - Add an assignment (or some type of content with a description editable via tinymce / rcs). - Update the description to include a latex equation using the equation editor. - Upon saving the assignment, observe that an image of the equation is visible. - Using the browser's elemnt / DOM inspector, select the equation image, and observe that there is a hidden span that contain a math ml representation. Change-Id: I194d155b339123f7ed1948cf29070c1d17fc7f17 Reviewed-on: https://gerrit.instructure.com/84031 Tested-by: Jenkins Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Benjamin Christian Nelson <bcnelson@instructure.com> Product-Review: John Corrigan <jcorrigan@instructure.com>
2016-08-02 03:28:43 +08:00
context 'when appropriately configured' do
let(:use_for_svg) { true }
it 'returns true' do
expect(MathMan.use_for_svg?).to be_truthy
end
end
end
end