Skip to content

Commit

Permalink
Merge pull request #3073 from projectblacklight/fix-exhibit-user-role…
Browse files Browse the repository at this point in the history
…s-js

Fix exhibit user roles management
  • Loading branch information
taylor-steve authored Jul 31, 2024
2 parents 9cc0f8a + 9ab6ff8 commit ac477bc
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 20 deletions.
12 changes: 6 additions & 6 deletions app/assets/javascripts/spotlight/spotlight.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/assets/javascripts/spotlight/spotlight.esm.js.map

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions app/assets/javascripts/spotlight/spotlight.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/assets/javascripts/spotlight/spotlight.js.map

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions app/javascript/spotlight/admin/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export default class {
function edit_user(event) {
event.preventDefault();
$(this).closest('tr').hide();
id = $(this).attr('data-target')
edit_view = $("[data-edit-for='"+id+"']", container).show();
const id = $(this).attr('data-target')
const edit_view = $("[data-edit-for='"+id+"']", container).show();
$.each(edit_view.find('input[type="text"], select'), function() {
// Cache original values incase editing is canceled
$(this).data('orig', $(this).val());
Expand All @@ -14,8 +14,8 @@ export default class {

function cancel_edit(event) {
event.preventDefault();
id = $(this).closest('tr').attr('data-edit-for');
edit_view = $("[data-edit-for='"+id+"']", container).hide();
const id = $(this).closest('tr').attr('data-edit-for');
const edit_view = $("[data-edit-for='"+id+"']", container).hide();
clear_errors(edit_view);
rollback_changes(edit_view);
$("[data-show-for='"+id+"']", container).show();
Expand All @@ -35,13 +35,13 @@ export default class {
}

function destroy_user(event) {
id = $(this).attr('data-target')
const id = $(this).attr('data-target')
$("[data-destroy-for='"+id+"']", container).val('1');
}

function new_user(event) {
event.preventDefault();
edit_view = $("[data-edit-for='new']", container).show();
const edit_view = $("[data-edit-for='new']", container).show();
$.each(edit_view.find('input[type="text"], select'), function() {
// Cache original values incase editing is canceled
$(this).data('orig', $(this).val());
Expand Down
31 changes: 31 additions & 0 deletions spec/features/exhibits/user_roles_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

RSpec.describe 'Manage exhibit users and roles', js: true do
let(:exhibit) { FactoryBot.create(:exhibit) }
let(:admin) { FactoryBot.create(:exhibit_admin, exhibit: exhibit) }

before do
login_as(admin)
visit spotlight.exhibit_roles_path(exhibit)
end

it 'admins can add a new user' do
click_on 'Add a new user'
expect(page).to have_selector('[data-edit-for="new"]')
fill_in 'User key', with: '[email protected]'
click_button 'Save changes'
expect(page).to have_content 'User has been updated.'
end

it 'admins can edit existing roles' do
find("[data-behavior='edit-user'][data-target='#{admin.id}']").click
expect(page).to have_selector("[data-edit-for='#{admin.id}']")
end

it 'admins can cancel adding a new user' do
click_on 'Add a new user'
expect(page).to have_selector('[data-edit-for="new"]')
click_on 'Cancel'
expect(page).to have_no_selector('[data-edit-for="new"]')
end
end

0 comments on commit ac477bc

Please sign in to comment.