Make reason for adjustment optional in moderator tag adjustment (#18606)

* Makes reason for adjustment optional for mod tag adjustments

* Makes reason for adjustment in notification conditional on adjustment reason

* Fix cypress element lookup by placeholder text
This commit is contained in:
Fernando Valverde 2022-10-20 09:54:52 -06:00 committed by GitHub
parent 569404a108
commit d14d882b13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 29 additions and 19 deletions

View file

@ -1,7 +1,6 @@
class TagAdjustment < ApplicationRecord
validates :tag_name, presence: true,
uniqueness: { scope: :article_id, message: I18n.t("models.tag_adjustment.unique") }
validates :reason_for_adjustment, presence: true
validates :adjustment_type, inclusion: { in: %w[removal addition] }, presence: true
validates :status, inclusion: { in: %w[committed pending committed_and_resolvable resolved] }, presence: true
has_many :notifications, as: :notifiable, inverse_of: :notifiable, dependent: :delete_all

View file

@ -137,7 +137,7 @@
<% end %>
<% end %>
<form id="adjustment-reason-container" class="adjustment-reason-container">
<textarea class="crayons-textfield" placeholder="<%= t("views.moderations.actions.adjust.reason") %>" id="tag-adjustment-reason" required></textarea>
<textarea class="crayons-textfield" placeholder="<%= t("views.moderations.actions.adjust.reason") %>" id="tag-adjustment-reason"></textarea>
<button class="crayons-btn" id="tag-adjust-submit" type="submit"><%= t("views.moderations.actions.adjust.submit") %></button>
</form>
<a href="<%= URL.url %>/tag-moderation#how-to-remove-or-add-tags" target="_blank" rel="noopener">

View file

@ -14,12 +14,14 @@
title: link_to(h(data["article"]["title"]), data["article"]["path"]),
) %>
</p>
<div class="crayons-card crayons-card--secondary p-4 mb-4">
<p class="color-base-70">
<strong><%= t("views.notifications.tag.reason") %></strong>
<em><%= data["reason_for_adjustment"] %></em>
</p>
</div>
<% if data["reason_for_adjustment"].present? %>
<div class="crayons-card crayons-card--secondary p-4 mb-4">
<p class="color-base-70">
<strong><%= t("views.notifications.tag.reason") %></strong>
<em><%= data["reason_for_adjustment"] %></em>
</p>
</div>
<% end %>
<% if removal %>
<p class="mb-2"><%= t("views.notifications.tag.check_html", other: link_to(t("views.notifications.tag.other"), "/tags")) %></p>
<% end %>

View file

@ -19,7 +19,7 @@ en:
icon: Adjust tags
add: Add tag
add_placeholder: Add a tag
reason: Reason for tag adjustment
reason: Reason for tag adjustment (optional)
remove: Remove tag
submit: Submit
approve:

View file

@ -19,7 +19,7 @@ fr:
icon: Adjust tags
add: Add tag
add_placeholder: Add a tag
reason: Reason for tag adjustment
reason: Reason for tag adjustment (optional)
remove: Remove tag
submit: Submit
approve:

View file

@ -18,7 +18,9 @@ describe('Adjust post tags', () => {
cy.getIframeBody('.actions-panel-iframe').within(() => {
cy.findByRole('button', { name: 'Open adjust tags section' }).click();
cy.findByPlaceholderText('Add a tag').type('tag2');
cy.findByPlaceholderText('Reason for tag adjustment').type('testing');
cy.findByPlaceholderText('Reason for tag adjustment (optional)').type(
'testing',
);
cy.findByRole('button', { name: 'Submit' }).click();
});
@ -36,7 +38,9 @@ describe('Adjust post tags', () => {
cy.getIframeBody('.actions-panel-iframe').within(() => {
cy.findByRole('button', { name: 'Open adjust tags section' }).click();
cy.findByPlaceholderText('Reason for tag adjustment').type('testing');
cy.findByPlaceholderText('Reason for tag adjustment (optional)').type(
'testing',
);
cy.findByRole('button', { name: '#tag1 Remove tag' }).click();
cy.findByRole('button', { name: 'Submit' }).click();
@ -84,7 +88,9 @@ describe('Adjust post tags', () => {
cy.getIframeBody('.actions-panel-iframe').within(() => {
cy.findByRole('button', { name: 'Open adjust tags section' }).click();
cy.findByPlaceholderText('Add a tag').type('tag2');
cy.findByPlaceholderText('Reason for tag adjustment').type('testing');
cy.findByPlaceholderText('Reason for tag adjustment (optional)').type(
'testing',
);
cy.findByRole('button', { name: 'Submit' }).click();
});
@ -102,7 +108,9 @@ describe('Adjust post tags', () => {
cy.getIframeBody('.actions-panel-iframe').within(() => {
cy.findByRole('button', { name: 'Open adjust tags section' }).click();
cy.findByPlaceholderText('Reason for tag adjustment').type('testing');
cy.findByPlaceholderText('Reason for tag adjustment (optional)').type(
'testing',
);
cy.findByRole('button', { name: '#tag1 Remove tag' }).click();
cy.findByRole('button', { name: 'Submit' }).click();
@ -144,7 +152,9 @@ describe('Adjust post tags', () => {
.should('have.attr', 'aria-expanded', 'true');
cy.findByPlaceholderText('Add a tag').type('tag2');
cy.findByPlaceholderText('Reason for tag adjustment').type('testing');
cy.findByPlaceholderText('Reason for tag adjustment (optional)').type(
'testing',
);
cy.findByRole('button', { name: 'Submit' }).click();
});
@ -168,7 +178,9 @@ describe('Adjust post tags', () => {
.pipe(click)
.should('have.attr', 'aria-expanded', 'true');
cy.findByPlaceholderText('Reason for tag adjustment').type('testing');
cy.findByPlaceholderText('Reason for tag adjustment (optional)').type(
'testing',
);
cy.findByRole('button', { name: '#tag1 Remove tag' }).click();
cy.findByRole('button', { name: 'Submit' }).click();

View file

@ -8,7 +8,6 @@ RSpec.describe "TagAdjustments", type: :request do
{
tag_name: tag.name,
article_id: article.id,
reason_for_adjustment: "Test #{rand(100)}",
adjustment_type: "removal"
}
end

View file

@ -12,7 +12,6 @@ RSpec.describe TagAdjustmentCreationService, type: :service do
status: "committed",
tag_name: tag.name,
article_id: article.id,
reason_for_adjustment: "Test",
)
end

View file

@ -12,7 +12,6 @@ RSpec.describe TagAdjustmentUpdateService, type: :service do
status: "committed",
tag_name: tag.name,
article_id: article.id,
reason_for_adjustment: "reasons",
)
end