mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 23:03:34 +01:00
Merge pull request '[v8.0/forgejo] fix(ui): allow unreacting from comment popover' (#4919) from bp-v8.0/forgejo-b8a5ca2 into v8.0/forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4919 Reviewed-by: Otto <otto@codeberg.org>
This commit is contained in:
commit
7b31a541c0
3 changed files with 80 additions and 27 deletions
|
@ -3299,12 +3299,6 @@ func ChangeIssueReaction(ctx *context.Context) {
|
||||||
log.Info("CreateIssueReaction: %s", err)
|
log.Info("CreateIssueReaction: %s", err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// Reload new reactions
|
|
||||||
issue.Reactions = nil
|
|
||||||
if err = issue.LoadAttributes(ctx); err != nil {
|
|
||||||
log.Info("issue.LoadAttributes: %s", err)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Trace("Reaction for issue created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, reaction.ID)
|
log.Trace("Reaction for issue created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, reaction.ID)
|
||||||
case "unreact":
|
case "unreact":
|
||||||
|
@ -3313,19 +3307,19 @@ func ChangeIssueReaction(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reload new reactions
|
|
||||||
issue.Reactions = nil
|
|
||||||
if err := issue.LoadAttributes(ctx); err != nil {
|
|
||||||
log.Info("issue.LoadAttributes: %s", err)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Trace("Reaction for issue removed: %d/%d", ctx.Repo.Repository.ID, issue.ID)
|
log.Trace("Reaction for issue removed: %d/%d", ctx.Repo.Repository.ID, issue.ID)
|
||||||
default:
|
default:
|
||||||
ctx.NotFound(fmt.Sprintf("Unknown action %s", ctx.Params(":action")), nil)
|
ctx.NotFound(fmt.Sprintf("Unknown action %s", ctx.Params(":action")), nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reload new reactions
|
||||||
|
issue.Reactions = nil
|
||||||
|
if err := issue.LoadAttributes(ctx); err != nil {
|
||||||
|
ctx.ServerError("ChangeIssueReaction.LoadAttributes", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if len(issue.Reactions) == 0 {
|
if len(issue.Reactions) == 0 {
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSON(http.StatusOK, map[string]any{
|
||||||
"empty": true,
|
"empty": true,
|
||||||
|
@ -3406,12 +3400,6 @@ func ChangeCommentReaction(ctx *context.Context) {
|
||||||
log.Info("CreateCommentReaction: %s", err)
|
log.Info("CreateCommentReaction: %s", err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// Reload new reactions
|
|
||||||
comment.Reactions = nil
|
|
||||||
if err = comment.LoadReactions(ctx, ctx.Repo.Repository); err != nil {
|
|
||||||
log.Info("comment.LoadReactions: %s", err)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Trace("Reaction for comment created: %d/%d/%d/%d", ctx.Repo.Repository.ID, comment.Issue.ID, comment.ID, reaction.ID)
|
log.Trace("Reaction for comment created: %d/%d/%d/%d", ctx.Repo.Repository.ID, comment.Issue.ID, comment.ID, reaction.ID)
|
||||||
case "unreact":
|
case "unreact":
|
||||||
|
@ -3420,19 +3408,19 @@ func ChangeCommentReaction(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reload new reactions
|
|
||||||
comment.Reactions = nil
|
|
||||||
if err = comment.LoadReactions(ctx, ctx.Repo.Repository); err != nil {
|
|
||||||
log.Info("comment.LoadReactions: %s", err)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Trace("Reaction for comment removed: %d/%d/%d", ctx.Repo.Repository.ID, comment.Issue.ID, comment.ID)
|
log.Trace("Reaction for comment removed: %d/%d/%d", ctx.Repo.Repository.ID, comment.Issue.ID, comment.ID)
|
||||||
default:
|
default:
|
||||||
ctx.NotFound(fmt.Sprintf("Unknown action %s", ctx.Params(":action")), nil)
|
ctx.NotFound(fmt.Sprintf("Unknown action %s", ctx.Params(":action")), nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reload new reactions
|
||||||
|
comment.Reactions = nil
|
||||||
|
if err = comment.LoadReactions(ctx, ctx.Repo.Repository); err != nil {
|
||||||
|
ctx.ServerError("ChangeCommentReaction.LoadReactions", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if len(comment.Reactions) == 0 {
|
if len(comment.Reactions) == 0 {
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSON(http.StatusOK, map[string]any{
|
||||||
"empty": true,
|
"empty": true,
|
||||||
|
|
65
tests/e2e/reaction-selectors.test.e2e.js
Normal file
65
tests/e2e/reaction-selectors.test.e2e.js
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
// @ts-check
|
||||||
|
import {test, expect} from '@playwright/test';
|
||||||
|
import {login_user, load_logged_in_context} from './utils_e2e.js';
|
||||||
|
|
||||||
|
test.beforeAll(async ({browser}, workerInfo) => {
|
||||||
|
await login_user(browser, workerInfo, 'user2');
|
||||||
|
});
|
||||||
|
|
||||||
|
const assertReactionCounts = (comment, counts) =>
|
||||||
|
expect(async () => {
|
||||||
|
await expect(comment.locator('.reactions')).toBeVisible();
|
||||||
|
|
||||||
|
const reactions = Object.fromEntries(
|
||||||
|
await Promise.all(
|
||||||
|
(
|
||||||
|
await comment
|
||||||
|
.locator(`.reactions [role=button][data-reaction-content]`)
|
||||||
|
.all()
|
||||||
|
).map(async (button) => [
|
||||||
|
await button.getAttribute('data-reaction-content'),
|
||||||
|
parseInt(await button.locator('.reaction-count').textContent()),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return expect(reactions).toStrictEqual(counts);
|
||||||
|
}).toPass();
|
||||||
|
|
||||||
|
async function toggleReaction(menu, reaction) {
|
||||||
|
await menu.evaluateAll((menus) => menus[0].focus());
|
||||||
|
await menu.locator('.add-reaction').click();
|
||||||
|
await menu.locator(`[role=menuitem][data-reaction-content="${reaction}"]`).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
test('Reaction Selectors', async ({browser}, workerInfo) => {
|
||||||
|
const context = await load_logged_in_context(browser, workerInfo, 'user2');
|
||||||
|
const page = await context.newPage();
|
||||||
|
|
||||||
|
const response = await page.goto('/user2/repo1/issues/1');
|
||||||
|
await expect(response?.status()).toBe(200);
|
||||||
|
|
||||||
|
const comment = page.locator('.comment#issuecomment-2').first();
|
||||||
|
|
||||||
|
const topPicker = comment.locator('.actions [role=menu].select-reaction');
|
||||||
|
const bottomPicker = comment.locator('.reactions').getByRole('menu');
|
||||||
|
|
||||||
|
await assertReactionCounts(comment, {'laugh': 2});
|
||||||
|
|
||||||
|
await toggleReaction(topPicker, '+1');
|
||||||
|
await assertReactionCounts(comment, {'laugh': 2, '+1': 1});
|
||||||
|
|
||||||
|
await toggleReaction(bottomPicker, '+1');
|
||||||
|
await assertReactionCounts(comment, {'laugh': 2});
|
||||||
|
|
||||||
|
await toggleReaction(bottomPicker, '-1');
|
||||||
|
await assertReactionCounts(comment, {'laugh': 2, '-1': 1});
|
||||||
|
|
||||||
|
await toggleReaction(topPicker, '-1');
|
||||||
|
await assertReactionCounts(comment, {'laugh': 2});
|
||||||
|
|
||||||
|
await comment.locator('.reactions [role=button][data-reaction-content=laugh]').click();
|
||||||
|
await assertReactionCounts(comment, {'laugh': 1});
|
||||||
|
|
||||||
|
await toggleReaction(topPicker, 'laugh');
|
||||||
|
await assertReactionCounts(comment, {'laugh': 2});
|
||||||
|
});
|
|
@ -9,7 +9,7 @@ export function initCompReactionSelector($parent) {
|
||||||
|
|
||||||
const actionUrl = this.closest('[data-action-url]')?.getAttribute('data-action-url');
|
const actionUrl = this.closest('[data-action-url]')?.getAttribute('data-action-url');
|
||||||
const reactionContent = this.getAttribute('data-reaction-content');
|
const reactionContent = this.getAttribute('data-reaction-content');
|
||||||
const hasReacted = this.closest('.ui.segment.reactions')?.querySelector(`a[data-reaction-content="${reactionContent}"]`)?.getAttribute('data-has-reacted') === 'true';
|
const hasReacted = this.closest('.comment')?.querySelector(`.ui.segment.reactions a[data-reaction-content="${reactionContent}"]`)?.getAttribute('data-has-reacted') === 'true';
|
||||||
|
|
||||||
const res = await POST(`${actionUrl}/${hasReacted ? 'unreact' : 'react'}`, {
|
const res = await POST(`${actionUrl}/${hasReacted ? 'unreact' : 'react'}`, {
|
||||||
data: new URLSearchParams({content: reactionContent}),
|
data: new URLSearchParams({content: reactionContent}),
|
||||||
|
|
Loading…
Reference in a new issue