2021-04-12 08:02:58 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
describe QunitController do
|
2021-04-28 16:12:08 -04:00
|
|
|
describe "#theme" do
|
|
|
|
let(:theme) { Fabricate(:theme, name: 'main-theme') }
|
|
|
|
let(:component) { Fabricate(:theme, component: true, name: 'enabled-component') }
|
|
|
|
let(:disabled_component) { Fabricate(:theme, component: true, enabled: false, name: 'disabled-component') }
|
|
|
|
let(:theme_without_tests) { Fabricate(:theme, name: 'no-tests-guy') }
|
2021-04-12 08:02:58 -04:00
|
|
|
|
2021-04-28 16:12:08 -04:00
|
|
|
before do
|
|
|
|
Theme.destroy_all
|
|
|
|
theme.set_default!
|
|
|
|
component.add_relative_theme!(:parent, theme)
|
|
|
|
disabled_component.add_relative_theme!(:parent, theme)
|
|
|
|
[theme, component, disabled_component].each do |t|
|
|
|
|
t.set_field(
|
|
|
|
target: :extra_js,
|
|
|
|
type: :js,
|
|
|
|
name: "discourse/initializers/my-#{t.id}-initializer.js",
|
|
|
|
value: "console.log(#{t.id});"
|
|
|
|
)
|
|
|
|
t.set_field(
|
|
|
|
target: :tests_js,
|
|
|
|
type: :js,
|
|
|
|
name: "acceptance/some-test-#{t.id}.js",
|
|
|
|
value: "assert.ok(#{t.id});"
|
|
|
|
)
|
|
|
|
t.save!
|
|
|
|
end
|
2021-04-12 08:02:58 -04:00
|
|
|
end
|
|
|
|
|
2021-04-28 16:12:08 -04:00
|
|
|
context "non-admin users on production" do
|
|
|
|
before do
|
2021-05-27 13:30:59 -04:00
|
|
|
# We need to call sign_in before stubbing the method because SessionController#become
|
|
|
|
# checks for the current env when the file is loaded.
|
|
|
|
# We need to make sure become is called once before stubbing, or the method
|
|
|
|
# wont'be available for future tests if this one runs first.
|
|
|
|
sign_in(Fabricate(:user))
|
2021-04-28 16:12:08 -04:00
|
|
|
Rails.env.stubs(:production?).returns(true)
|
2021-04-12 08:02:58 -04:00
|
|
|
end
|
2021-04-28 16:12:08 -04:00
|
|
|
|
2021-05-27 13:30:59 -04:00
|
|
|
it "regular users cannot see the page" do
|
2021-04-28 16:12:08 -04:00
|
|
|
get '/theme-qunit'
|
|
|
|
expect(response.status).to eq(404)
|
2021-04-12 08:02:58 -04:00
|
|
|
end
|
|
|
|
|
2021-05-27 13:30:59 -04:00
|
|
|
it "anons cannot see the page" do
|
|
|
|
sign_out
|
2021-04-28 16:12:08 -04:00
|
|
|
get '/theme-qunit'
|
|
|
|
expect(response.status).to eq(404)
|
2021-04-12 08:02:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-28 16:12:08 -04:00
|
|
|
context "admin users" do
|
|
|
|
before do
|
|
|
|
sign_in(Fabricate(:admin))
|
|
|
|
end
|
2021-04-26 05:56:45 -04:00
|
|
|
|
2021-04-28 16:12:08 -04:00
|
|
|
context "when no theme is specified" do
|
|
|
|
it "renders a list of themes and components that have tests" do
|
|
|
|
get '/theme-qunit'
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
[theme, component, disabled_component].each do |t|
|
|
|
|
expect(response.body).to include(t.name)
|
|
|
|
expect(response.body).to include("/theme-qunit?id=#{t.id}")
|
|
|
|
end
|
|
|
|
expect(response.body).not_to include(theme_without_tests.name)
|
|
|
|
expect(response.body).not_to include("/theme-qunit?id=#{theme_without_tests.id}")
|
2021-04-26 16:05:58 -04:00
|
|
|
end
|
2021-04-26 05:56:45 -04:00
|
|
|
end
|
2021-04-28 16:12:08 -04:00
|
|
|
|
|
|
|
it "can specify theme by id" do
|
|
|
|
get "/theme-qunit?id=#{theme.id}"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.body).to include("/theme-javascripts/tests/#{theme.id}-")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can specify theme by name" do
|
|
|
|
get "/theme-qunit?name=#{theme.name}"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.body).to include("/theme-javascripts/tests/#{theme.id}-")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can specify theme by url" do
|
|
|
|
theme.build_remote_theme(remote_url: "git@github.com:discourse/discourse.git").save!
|
|
|
|
theme.save!
|
|
|
|
get "/theme-qunit?url=#{theme.remote_theme.remote_url}"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.body).to include("/theme-javascripts/tests/#{theme.id}-")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "themes qunit page includes all the JS/CSS it needs" do
|
|
|
|
get "/theme-qunit?id=#{theme.id}"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.body).to include("/stylesheets/color_definitions_base_")
|
|
|
|
expect(response.body).to include("/stylesheets/desktop_")
|
|
|
|
expect(response.body).to include("/stylesheets/test_helper_")
|
2021-04-30 06:28:33 -04:00
|
|
|
expect(response.body).to include("/assets/locales/en.js")
|
2022-01-13 15:16:34 -05:00
|
|
|
expect(response.body).to include("/test-support")
|
|
|
|
expect(response.body).to include("/test-helpers")
|
2021-04-30 06:28:33 -04:00
|
|
|
expect(response.body).to include("/assets/markdown-it-bundle.js")
|
DEV: Allow Ember CLI assets to be used by development Rails app (#16511)
Previously, accessing the Rails app directly in development mode would give you assets from our 'legacy' Ember asset pipeline. The only way to run with Ember CLI assets was to run ember-cli as a proxy. This was quite limiting when working on things which are bypassed when using the ember-cli proxy (e.g. changes to `application.html.erb`). Also, since `ember-auto-import` introduced chunking, visiting `/theme-qunit` under Ember CLI was failing to include all necessary chunks.
This commit teaches Sprockets about our Ember CLI assets so that they can be used in development mode, and are automatically collected up under `/public/assets` during `assets:precompile`. As a bonus, this allows us to remove all the custom manifest modification from `assets:precompile`.
The key changes are:
- Introduce a shared `EmberCli.enabled?` helper
- When ember-cli is enabled, add ember-cli `/dist/assets` as the top-priority Rails asset directory
- Have ember-cli output a `chunks.json` manifest, and teach `preload_script` to read it and append the correct chunks to their associated `afterFile`
- Remove most custom ember-cli logic from the `assets:precompile` step. Instead, rely on Rails to take care of pulling the 'precompiled' assets into the `public/assets` directory. Move the 'renaming' logic to runtime, so it can be used in development mode as well.
- Remove fingerprinting from `ember-cli-build`, and allow Rails to take care of things
Long-term, we may want to replace Sprockets with the lighter-weight Propshaft. The changes made in this commit have been made with that long-term goal in mind.
tldr: when you visit the rails app directly, you'll now be served the current ember-cli assets. To keep these up-to-date make sure either `ember serve`, or `ember build --watch` is running. If you really want to load the old non-ember-cli assets, then you should start the server with `EMBER_CLI_PROD_ASSETS=0`. (the legacy asset pipeline will be removed very soon)
2022-04-21 11:26:34 -04:00
|
|
|
expect(response.body).to include("/assets/#{EmberCli.transform_name("application")}.js")
|
2021-04-30 06:28:33 -04:00
|
|
|
expect(response.body).to include("/assets/admin.js")
|
2021-04-28 16:12:08 -04:00
|
|
|
expect(response.body).to match(/\/theme-javascripts\/\h{40}\.js/)
|
|
|
|
expect(response.body).to include("/theme-javascripts/tests/#{theme.id}-")
|
|
|
|
end
|
2021-04-12 08:02:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|