2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe ThemeJavascriptCompiler do
|
2022-09-01 06:50:46 -04:00
|
|
|
let(:compiler) { ThemeJavascriptCompiler.new(1, 'marks') }
|
2019-01-17 06:46:11 -05:00
|
|
|
let(:theme_id) { 22 }
|
|
|
|
|
2020-03-06 11:35:52 -05:00
|
|
|
describe "#append_raw_template" do
|
2020-05-05 12:15:03 -04:00
|
|
|
it 'uses the correct template paths' do
|
2020-03-06 11:35:52 -05:00
|
|
|
template = "<h1>hello</h1>"
|
|
|
|
name = "/path/to/templates1"
|
|
|
|
compiler.append_raw_template("#{name}.raw", template)
|
2020-05-05 12:15:03 -04:00
|
|
|
expect(compiler.content.to_s).to include("addRawTemplate(\"#{name}\"")
|
2020-03-06 11:35:52 -05:00
|
|
|
|
|
|
|
name = "/path/to/templates2"
|
|
|
|
compiler.append_raw_template("#{name}.hbr", template)
|
2020-05-05 12:15:03 -04:00
|
|
|
expect(compiler.content.to_s).to include("addRawTemplate(\"#{name}\"")
|
2020-03-06 11:35:52 -05:00
|
|
|
|
|
|
|
name = "/path/to/templates3"
|
|
|
|
compiler.append_raw_template("#{name}.hbs", template)
|
2020-05-05 12:15:03 -04:00
|
|
|
expect(compiler.content.to_s).to include("addRawTemplate(\"#{name}.hbs\"")
|
2020-03-06 11:35:52 -05:00
|
|
|
end
|
|
|
|
end
|
2021-04-12 08:02:58 -04:00
|
|
|
|
|
|
|
describe "#append_ember_template" do
|
2022-09-01 06:50:46 -04:00
|
|
|
it 'maintains module names so that discourse-boot.js can correct them' do
|
2021-04-12 08:02:58 -04:00
|
|
|
compiler.append_ember_template("/connectors/blah-1", "{{var}}")
|
2022-09-01 06:50:46 -04:00
|
|
|
expect(compiler.content.to_s).to include("define(\"discourse/theme-1/connectors/blah-1\", [\"exports\", \"@ember/template-factory\"]")
|
2021-04-12 08:02:58 -04:00
|
|
|
|
|
|
|
compiler.append_ember_template("connectors/blah-2", "{{var}}")
|
2022-09-01 06:50:46 -04:00
|
|
|
expect(compiler.content.to_s).to include("define(\"discourse/theme-1/connectors/blah-2\", [\"exports\", \"@ember/template-factory\"]")
|
2021-04-12 08:02:58 -04:00
|
|
|
|
|
|
|
compiler.append_ember_template("javascripts/connectors/blah-3", "{{var}}")
|
2022-09-01 06:50:46 -04:00
|
|
|
expect(compiler.content.to_s).to include("define(\"discourse/theme-1/javascripts/connectors/blah-3\", [\"exports\", \"@ember/template-factory\"]")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "connector module name handling" do
|
|
|
|
it 'separates colocated connectors to avoid module name clash' do
|
|
|
|
# Colocated under `/connectors`
|
|
|
|
compiler = ThemeJavascriptCompiler.new(1, 'marks')
|
|
|
|
compiler.append_ember_template("connectors/outlet/blah-1", "{{var}}")
|
|
|
|
compiler.append_module("console.log('test')", "connectors/outlet/blah-1")
|
|
|
|
expect(compiler.content.to_s).to include("discourse/theme-1/connectors/outlet/blah-1")
|
|
|
|
expect(compiler.content.to_s).to include("discourse/theme-1/templates/connectors/outlet/blah-1")
|
|
|
|
|
|
|
|
# Colocated under `/templates/connectors`
|
|
|
|
compiler = ThemeJavascriptCompiler.new(1, 'marks')
|
|
|
|
compiler.append_ember_template("templates/connectors/outlet/blah-1", "{{var}}")
|
|
|
|
compiler.append_module("console.log('test')", "templates/connectors/outlet/blah-1")
|
|
|
|
expect(compiler.content.to_s).to include("discourse/theme-1/connectors/outlet/blah-1")
|
|
|
|
expect(compiler.content.to_s).to include("discourse/theme-1/templates/connectors/outlet/blah-1")
|
|
|
|
|
|
|
|
# Not colocated
|
|
|
|
compiler = ThemeJavascriptCompiler.new(1, 'marks')
|
|
|
|
compiler.append_ember_template("templates/connectors/outlet/blah-1", "{{var}}")
|
|
|
|
compiler.append_module("console.log('test')", "connectors/outlet/blah-1")
|
|
|
|
expect(compiler.content.to_s).to include("discourse/theme-1/connectors/outlet/blah-1")
|
|
|
|
expect(compiler.content.to_s).to include("discourse/theme-1/templates/connectors/outlet/blah-1")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "error handling" do
|
|
|
|
it "handles syntax errors in raw templates" do
|
|
|
|
expect do
|
|
|
|
compiler.append_raw_template("sometemplate.hbr", "{{invalidtemplate")
|
|
|
|
end.to raise_error(ThemeJavascriptCompiler::CompileError, /Parse error on line 1/)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "handles syntax errors in ember templates" do
|
|
|
|
expect do
|
|
|
|
compiler.append_ember_template("sometemplate", "{{invalidtemplate")
|
|
|
|
end.to raise_error(ThemeJavascriptCompiler::CompileError, /Parse error on line 1/)
|
2021-04-12 08:02:58 -04:00
|
|
|
end
|
|
|
|
end
|
2019-01-17 06:46:11 -05:00
|
|
|
end
|