Remove duplicate jquery import, remove jquery-rails and use @rails/ujs (#13891)

* Remove unused jQuery include in Listings

* Use @rails/ujs in the admin

* Remove jquery-rails

* Content is mandatory for listings

* form_with defaults to local: true

* Update app/views/listings/delete_confirm.html.erb

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>

* Update cypress/integration/listingFlows/deleteListing.spec.js

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>

* Update cypress/integration/listingFlows/deleteListing.spec.js

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>

* Update cypress/integration/listingFlows/deleteListing.spec.js

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>

* Apply feedback on e2e and fix a bullet warning

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
This commit is contained in:
rhymes 2021-06-01 15:28:09 +02:00 committed by GitHub
parent a1180c918d
commit 3be26dae97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 91 additions and 57 deletions

View file

@ -50,7 +50,6 @@ gem "httparty", "~> 0.18" # Makes http fun! Also, makes consuming restful web se
gem "imgproxy", "~> 2.0" # A gem that easily generates imgproxy URLs for your images
gem "inline_svg", "~> 1.7" # Embed SVG documents in your Rails views and style them with CSS
gem "jbuilder", "~> 2.11" # Create JSON structures via a Builder-style DSL
gem "jquery-rails", "~> 4.4" # A gem to automate using jQuery with Rails
gem "jsonapi-serializer", "~> 2.2" # Serializer for Ruby objects
gem "kaminari", "~> 1.2" # A Scope & Engine based, clean, powerful, customizable and sophisticated paginator
gem "katex", "~> 0.8.0" # This rubygem enables you to render TeX math to HTML using KaTeX. It uses ExecJS under the hood

View file

@ -386,10 +386,6 @@ GEM
actionpack (>= 3.1)
railties (>= 3.1)
sass (>= 3.2)
jquery-rails (4.4.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (2.5.1)
jsonapi-serializer (2.2.0)
activesupport (>= 4.2)
@ -905,7 +901,6 @@ DEPENDENCIES
imgproxy (~> 2.0)
inline_svg (~> 1.7)
jbuilder (~> 2.11)
jquery-rails (~> 4.4)
jsonapi-serializer (~> 2.2)
kaminari (~> 1.2)
katex (~> 0.8.0)

View file

@ -1,15 +0,0 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require_tree .

View file

@ -1,14 +0,0 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs

View file

@ -151,7 +151,7 @@ class ListingsController < ApplicationController
def listings_for_index_view
Listing.where(published: true)
.order(bumped_at: :desc)
.includes(:user, :organization, :taggings)
.includes(:user, :organization, :taggings, :listing_category)
.limit(12)
end
end

View file

@ -1,5 +1,10 @@
import { Application } from 'stimulus';
import { definitionsFromContext } from 'stimulus/webpack-helpers';
import Rails from '@rails/ujs';
// Initialize Rails unobtrusive scripting adapter
// https://github.com/rails/rails/blob/main/actionview/app/assets/javascripts/README.md#es2015
Rails.start();
// This loads all the Stimulus controllers at the same time for the admin
// section of the application.

View file

@ -1,4 +1,4 @@
<%= form_with model: [:admin, tag], data: { remote: false } do |f| %>
<%= form_with model: [:admin, tag] do |f| %>
<% if !tag.persisted? %>
<div class="crayons-field">
<%= f.label :name, class: "crayons-field__label" %>

View file

@ -20,7 +20,7 @@
<% @tag_moderators.each do |user| %>
<li class="flex justify-between mb-2">
<a href="<%= URL.user(user) %>" target="_blank" rel="noopener noreferer">@<%= user.username %></a>
<%= form_with url: admin_tag_moderator_path(@tag.id), model: [:admin, @tag], method: :delete, data: { remote: false } do |f| %>
<%= form_with url: admin_tag_moderator_path(@tag.id), model: [:admin, @tag], method: :delete do |f| %>
<%= f.hidden_field :user_id, value: user.id %>
<%= f.submit "Remove", class: "crayons-btn crayons-btn--danger crayons-btn--s" %>
<% end %>
@ -32,7 +32,7 @@
This tag currently has no moderators.
</div>
<% end %>
<%= form_with url: admin_tag_moderator_path(@tag.id), model: [:admin, @tag], method: :post, data: { remote: false } do |f| %>
<%= form_with url: admin_tag_moderator_path(@tag.id), model: [:admin, @tag], method: :post do |f| %>
<div class="crayons-field w-50">
<%= f.label :user_id, "Add Moderator (ID):", class: "crayons-field__label" %>
<%= f.text_field :user_id, class: "crayons-textfield" %>

View file

@ -91,8 +91,5 @@
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.16/js/bootstrap-select.min.js" integrity="sha256-COIM4OdXvo3jkE0/jD/QIEDe3x0jRuqHhOdGTkno3uM=" crossorigin="anonymous"></script>
<%= javascript_include_tag "internal" %>
</body>
</html>

View file

@ -1,6 +1,4 @@
<%= javascript_include_tag "application" %>
<div class="crayons-layout crayons-layout--limited-l gap-0">
<main id="main-content" class="crayons-layout crayons-layout--limited-l gap-0">
<div class="crayons-card crayons-card--secondary text-styles text-styles--secondary text-padding -mb-1 mx-3 m:mx-6 mt-3">
<%= @listing.title %>
</div>
@ -8,17 +6,18 @@
<h1 class="crayons-subtitle-1 mb-2">Are you sure you want to delete this listing?</h1>
<p class="fs-l mb-4">
You cannot undo this action, perhaps you just want to
<a data-no-instant href="/listings/<%= @listing.id %>/edit">
<a data-no-instant href="<%= edit_listing_path(@listing) %>">
<%= @listing.published ? "unpublish" : "edit" %>
</a>
instead?
</p>
<%= form_tag "/listings/#{@listing.id}", method: :delete do %>
<%= form_tag listing_path(@listing), method: :delete do %>
<button class="crayons-btn crayons-btn--danger">Delete</button>
<a data-no-instant href="/listings/<%= @listing.id %>/edit" class="crayons-btn crayons-btn--secondary">
<a data-no-instant href="<%= edit_listing_path(@listing) %>" class="crayons-btn crayons-btn--secondary">
<%= @listing.published ? "Unpublish" : "Edit" %>
</a>
<% end %>
</div>
</div>
</main>

View file

@ -0,0 +1,20 @@
describe('Badge Achievements', () => {
beforeEach(() => {
cy.testSetup();
cy.fixture('users/adminUser.json').as('user');
cy.get('@user').then((user) => {
cy.loginUser(user).then(() => {
cy.visit('/admin/content_manager/badge_achievements');
});
});
});
it('delete a badge achievement', () => {
cy.findByText('Remove').as('removeBadgeButton');
cy.get('@removeBadgeButton').click();
cy.get('@removeBadgeButton').should('not.exist');
});
});

View file

@ -0,0 +1,30 @@
describe('Delete listing', () => {
beforeEach(() => {
cy.testSetup();
cy.viewport('macbook-16');
cy.fixture('users/adminUser.json').as('user');
cy.get('@user').then((user) => {
cy.loginUser(user).then(() => {
cy.visit('/listings/dashboard');
});
});
});
it('deletes a listing', () => {
cy.findByRole('main')
.findByRole('heading', { name: 'Listing title' })
.should('exist');
cy.findByRole('link', { name: 'Delete' }).click();
cy.findByRole('main')
.findByRole('button', { name: /^Delete$/i })
.click();
cy.findByRole('main')
.findByRole('heading', { name: 'Listing title' })
.should('not.exist');
});
});

View file

@ -149,6 +149,7 @@
"@babel/preset-env": "^7.14.4",
"@github/clipboard-copy-element": "^1.1.2",
"@honeybadger-io/webpack": "^1.2.0",
"@rails/ujs": "6.0.3-7",
"@rails/webpacker": "5.4.0",
"@reach/combobox": "^0.15.1",
"ahoy.js": "^0.3.8",

View file

@ -47,6 +47,8 @@ seeder.create_if_doesnt_exist(User, "email", "admin@forem.local") do
user.add_role(:trusted)
end
admin_user = User.find_by(email: "admin@forem.local")
##############################################################################
seeder.create_if_doesnt_exist(User, "email", "change-password-user@forem.com") do
@ -181,16 +183,15 @@ end
##############################################################################
seeder.create_if_none(Listing) do
user = User.first
Credit.add_to(user, rand(100))
Credit.add_to(admin_user, rand(100))
Listing.create!(
user: user,
user: admin_user,
title: "Listing title",
body_markdown: Faker::Markdown.random,
location: Faker::Address.city,
organization_id: user.organizations.first&.id,
listing_category_id: ListingCategory.first&.id,
organization_id: admin_user.organizations.first&.id,
listing_category_id: ListingCategory.first.id,
contact_via_connect: true,
published: true,
originally_published_at: Time.current,
@ -201,8 +202,6 @@ end
##############################################################################
moderator = User.where(email: "admin@forem.local").first
seeder.create_if_none(Tag) do
tag = Tag.create!(
name: "tag1",
@ -211,10 +210,23 @@ seeder.create_if_none(Tag) do
supported: true,
)
moderator.add_role(:tag_moderator, tag)
admin_user.add_role(:tag_moderator, tag)
end
# Show the tag in the sidebar
Settings::General.sidebar_tags = %i[tag1]
##############################################################################
seeder.create_if_none(Badge) do
Badge.create!(
title: "#{Faker::Lorem.word} #{rand(100)}",
description: Faker::Lorem.sentence,
badge_image: File.open(Rails.root.join("app/assets/images/#{rand(1..40)}.png")),
)
admin_user.badge_achievements.create!(
badge: Badge.first,
rewarding_context_message_markdown: Faker::Markdown.random,
)
end

Binary file not shown.

View file

@ -1803,6 +1803,11 @@
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.9.1.tgz#7f554e7368c9ab679a11f4a042ca17149d70cf12"
integrity sha512-DvJbbn3dUgMxDnJLH+RZQPnXak1h4ZVYQ7CWiFWjQwBFkVajT4rfw2PdpHLTSTwxrYfnoEXkuBiwkDm6tPMQeA==
"@rails/ujs@6.0.3-7":
version "6.0.3-7"
resolved "https://registry.yarnpkg.com/@rails/ujs/-/ujs-6.0.3-7.tgz#8be007e500baafed256895830ae446178511773b"
integrity sha512-J7dvCTkZ/zaQLge1mttypoE/1j5YDcSAuu4fun8CoTqVGkcbwZu4f4jy+HKxdomtrZzXWSHlSeIe9vOtLnhmeA==
"@rails/webpacker@5.4.0":
version "5.4.0"
resolved "https://registry.yarnpkg.com/@rails/webpacker/-/webpacker-5.4.0.tgz#2c64a9ea7e85d2a33e50e86319fe6751df0c47e8"