Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"version": "v3.4.2",
"require": {
"saucebase/core": "^2.7"
"saucebase/core": "^2.8"
},
"authors": [
{
Expand Down
1 change: 1 addition & 0 deletions resources/js/react/hooks/useVote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function useVote(
{},
{
preserveScroll: true,
preserveUrl: true,
only,
onSuccess: () =>
hadVoted
Expand Down
14 changes: 13 additions & 1 deletion resources/js/vue/components/ItemDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,21 @@ const props = defineProps<{
// Voting updates the count before the server answers, so the item is local state.
const item = reactive({ ...props.item });

// Copied again only when the server's values change. In the slideover, the board's
// reload hands the panel the same item afresh; copying that would undo a vote whose
// answer hasn't arrived, and the next click would vote again instead of removing it.
let received = JSON.stringify(props.item);

watch(
() => props.item,
(updated) => Object.assign(item, updated),
(updated) => {
const next = JSON.stringify(updated);

if (next !== received) {
received = next;
Object.assign(item, updated);
}
},
{ deep: true },
);

Expand Down
1 change: 1 addition & 0 deletions resources/js/vue/composables/useVote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function useVote(authenticated: boolean, only: string[]) {
{},
{
preserveScroll: true,
preserveUrl: true,
only,
onSuccess: () =>
hadVoted
Expand Down
31 changes: 28 additions & 3 deletions tests/e2e/tests/roadmap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ test.describe('Roadmap', () => {
await expect(page).toHaveURL(/\/roadmap$/);
});

test('a vote in the slideover shows on the board behind it', async ({
test('voting in the slideover keeps it open and updates the board', async ({
page,
laravel,
credentials,
Expand All @@ -171,18 +171,43 @@ test.describe('Roadmap', () => {
await page.getByTestId(`roadmap-item-link-${item.id}`).click();

const panel = page.getByTestId('roadmap-item-modal');
// The slideover's own visit ends by pushing its URL; a vote sent before
// that would be cancelled by it.
await expect(page).toHaveURL(new RegExp(`/roadmap/${item.slug}$`));
await panel.getByTestId(`vote-btn-${item.id}`).click();
await expect(panel.getByTestId(`vote-count-${item.id}`)).toHaveText(
'1',
);
await expect(page.locator('[data-sonner-toast]')).toContainText(
'Upvoted!',
);
await expect(panel).toBeVisible();
await expect(page).toHaveURL(new RegExp(`/roadmap/${item.slug}$`));
const card = page.getByTestId(`roadmap-item-${item.id}`);
await expect(card.getByTestId(`vote-count-${item.id}`)).toHaveText('1');

await panel.getByTestId(`vote-btn-${item.id}`).click();
await expect(page.locator('[data-sonner-toast]').last()).toContainText(
'Vote removed',
);
await expect(panel).toBeVisible();
await expect(page).toHaveURL(new RegExp(`/roadmap/${item.slug}$`));
await expect(panel.getByTestId(`vote-count-${item.id}`)).toHaveText(
'0',
);
await expect(panel.getByTestId(`vote-btn-${item.id}`)).toHaveAttribute(
'data-voted',
'false',
);
await expect(card.getByTestId(`vote-count-${item.id}`)).toHaveText('0');

await page.keyboard.press('Escape');
await expect(panel).toHaveCount(0);

await expect(page.getByTestId(`vote-count-${item.id}`)).toHaveText('1');
await expect(page.getByTestId(`vote-count-${item.id}`)).toHaveText('0');
await expect(page.getByTestId(`vote-btn-${item.id}`)).toHaveAttribute(
'data-voted',
'true',
'false',
);
});

Expand Down
Loading