2020-10-27 00:51:19 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-28 12:06:26 +08:00
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
2016-08-02 03:28:43 +08:00
|
|
|
describe MathMan do
|
|
|
|
let(:latex) do
|
|
|
|
'\sqrt{25}+12^{12}'
|
|
|
|
end
|
2017-07-20 04:55:32 +08:00
|
|
|
# we explicitly don't want a trailing slash here for the url tests
|
|
|
|
let(:service_url) { 'http://www.mml-service.com/beta' }
|
2016-08-02 03:28:43 +08:00
|
|
|
let(:use_for_mml) { false }
|
|
|
|
let(:use_for_svg) { false }
|
|
|
|
|
|
|
|
before do
|
2017-05-06 01:58:22 +08:00
|
|
|
@original_fallback = Canvas::DynamicSettings.fallback_data
|
|
|
|
Canvas::DynamicSettings.fallback_data = {
|
2017-09-19 23:33:08 +08:00
|
|
|
config: {
|
|
|
|
canvas: {
|
|
|
|
'math-man': {
|
|
|
|
base_url: service_url,
|
|
|
|
}
|
|
|
|
}
|
2016-08-02 03:28:43 +08:00
|
|
|
}
|
2017-05-06 01:58:22 +08:00
|
|
|
}
|
2017-08-17 06:01:05 +08:00
|
|
|
PluginSetting.create!(
|
|
|
|
name: 'mathman',
|
|
|
|
settings: {
|
|
|
|
use_for_mml: use_for_mml,
|
|
|
|
use_for_svg: use_for_svg
|
|
|
|
}.with_indifferent_access
|
|
|
|
)
|
2017-05-06 01:58:22 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Canvas::DynamicSettings.fallback_data = @original_fallback
|
2016-08-02 03:28:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '.url_for' do
|
2017-07-20 04:55:32 +08:00
|
|
|
it 'must retain the path from base_url setting' do
|
|
|
|
url = MathMan.url_for(latex: latex, target: :mml)
|
|
|
|
parsed = Addressable::URI.parse(url)
|
2021-09-27 23:58:39 +08:00
|
|
|
expect(parsed.path).to eq('/beta/mml')
|
2017-07-20 04:55:32 +08:00
|
|
|
end
|
|
|
|
|
2018-04-21 22:07:01 +08:00
|
|
|
it 'includes target string in generated url' do
|
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
|
2018-04-21 22:07:01 +08:00
|
|
|
|
|
|
|
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
|
2016-08-02 03:28:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '.use_for_mml?' do
|
2017-08-17 06:01:05 +08:00
|
|
|
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
|
2016-08-02 03:28:43 +08:00
|
|
|
expect(MathMan.use_for_mml?).to be_falsey
|
|
|
|
end
|
|
|
|
|
2018-04-21 22:07:01 +08:00
|
|
|
it 'does not error if DynamicSettings is not configured' do
|
|
|
|
Canvas::DynamicSettings.fallback_data = nil
|
|
|
|
expect(MathMan.use_for_mml?).to be_falsey
|
|
|
|
end
|
|
|
|
|
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
|
2017-08-17 06:01:05 +08:00
|
|
|
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
|
2016-08-02 03:28:43 +08:00
|
|
|
expect(MathMan.use_for_svg?).to be_falsey
|
|
|
|
end
|
|
|
|
|
2018-04-21 22:07:01 +08:00
|
|
|
it 'does not error if DynamicSettings is not configured' do
|
|
|
|
Canvas::DynamicSettings.fallback_data = nil
|
|
|
|
expect(MathMan.use_for_svg?).to be_falsey
|
|
|
|
end
|
|
|
|
|
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
|