-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to import additional admin JS modules
In order to be able to import additional JS modules into the Alchemy admin UI you can use this. Be sure to also pin the modules with `Alchemy.importmap`. \## Example Alchemy.importmap.pin "flatpickr/de", to: "https://ga.jspm.io/npm:flatpickr@4.6.13/dist/l10n/de.js" Alchemy.admin_js_imports << "flatpickr/de"
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe "layouts/alchemy/admin.html.erb" do | ||
before do | ||
view.extend Alchemy::Admin::BaseHelper | ||
allow(view).to receive(:alchemy_modules).and_return([]) | ||
allow(view).to receive(:current_alchemy_user).and_return(DummyUser.new) | ||
allow(view).to receive(:configuration).and_return({}) | ||
end | ||
|
||
subject do | ||
render template: "layouts/alchemy/admin" | ||
rendered | ||
end | ||
|
||
context "with Alchemy.admin_js_imports" do | ||
around do |example| | ||
current = Alchemy.admin_js_imports | ||
Alchemy.admin_js_imports << "foo" | ||
example.run | ||
Alchemy.admin_js_imports = current | ||
end | ||
|
||
it "renders the given javascripts module imports" do | ||
expect(subject).to have_selector("script[type=\"module\"]:last-of-type", text: /import "foo"/) | ||
end | ||
end | ||
|
||
context "without Alchemy.admin_js_imports" do | ||
it "does not render the given javascripts module imports" do | ||
expect(subject).to_not have_selector("script[type=\"module\"]:last-of-type", text: /import "foo"/) | ||
end | ||
end | ||
end |