Enable automatic browsing upvotes
This commit is contained in:
1 parent
27012399ec
commit
7bf1aa9d24
26 files changed
+339
-57
No files matched your search
@@ -55,6 +55,7 @@ function browsing(includeRecent = false) {
|
||||
minimumGapMs: 2_700_000,
|
||||
jitterMs: 900_000,
|
||||
allowNsfw: false,
|
||||
autoVoteEnabled: false,
|
||||
nextDueAt: null,
|
||||
updatedAt: 1_700_000_000_000,
|
||||
},
|
||||
@@ -158,7 +159,19 @@ const server = setupServer(
|
||||
return HttpResponse.json({ success: true, account: detailPayload });
|
||||
}),
|
||||
http.patch('/api/growth/:accountId/browsing', async ({ request }) => {
|
||||
requests.push({ method: 'PATCH', url: request.url, body: await request.json() });
|
||||
const body = await request.json() as Record<string, unknown>;
|
||||
requests.push({ method: 'PATCH', url: request.url, body });
|
||||
const currentBrowsing = detailPayload.browsing as ReturnType<typeof browsing>;
|
||||
detailPayload = detail({
|
||||
browsing: {
|
||||
...currentBrowsing,
|
||||
settings: { ...currentBrowsing.settings, ...body },
|
||||
},
|
||||
});
|
||||
return HttpResponse.json({ success: true, account: detailPayload });
|
||||
}),
|
||||
http.post('/api/growth/:accountId/browsing/run', ({ request }) => {
|
||||
requests.push({ method: 'POST', url: request.url, body: null });
|
||||
return HttpResponse.json({ success: true, account: detailPayload });
|
||||
}),
|
||||
http.post('/api/growth/:accountId/pause', async ({ request }) => {
|
||||
@@ -215,19 +228,42 @@ describe('GrowthPage', () => {
|
||||
expect(screen.getByText(/posted without review/i)).toBeVisible();
|
||||
});
|
||||
|
||||
it('shows browsing as an explicit no-vote simulation and can enable it', async () => {
|
||||
it('shows browsing sessions and can enable automatic upvotes', async () => {
|
||||
renderGrowth();
|
||||
const user = userEvent.setup();
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Browsing simulation' })).toBeVisible();
|
||||
expect(screen.getByText('No Reddit votes were submitted.')).toBeVisible();
|
||||
expect(await screen.findByRole('heading', { name: 'Browsing sessions' })).toBeVisible();
|
||||
expect(screen.getByText('No Reddit votes will be submitted.')).toBeVisible();
|
||||
expect(screen.getByText('0 / 4')).toBeVisible();
|
||||
await user.click(screen.getByLabelText('Simulate browsing selections'));
|
||||
await user.click(screen.getByLabelText('Run browsing sessions'));
|
||||
|
||||
await waitFor(() => expect(requests).toContainEqual(expect.objectContaining({
|
||||
method: 'PATCH', body: { enabled: true },
|
||||
})));
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: 'Simulate session now' })).toBeEnabled());
|
||||
expect(requests[0].url).toContain('/api/growth/%40t2_grower%3Areddit.com/browsing');
|
||||
await user.click(screen.getByLabelText('Submit selected upvotes'));
|
||||
await waitFor(() => expect(requests).toContainEqual(expect.objectContaining({
|
||||
method: 'PATCH', body: { autoVoteEnabled: true },
|
||||
})));
|
||||
});
|
||||
|
||||
it('runs an enabled browsing simulation immediately', async () => {
|
||||
const currentBrowsing = browsing(true);
|
||||
detailPayload = detail({
|
||||
browsing: {
|
||||
...currentBrowsing,
|
||||
settings: { ...currentBrowsing.settings, enabled: true },
|
||||
},
|
||||
});
|
||||
renderGrowth();
|
||||
const user = userEvent.setup();
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: 'Simulate session now' }));
|
||||
|
||||
await waitFor(() => expect(requests).toContainEqual(expect.objectContaining({
|
||||
method: 'POST', body: null,
|
||||
})));
|
||||
});
|
||||
|
||||
it('shows an empty state when there are no accounts', async () => {
|
||||
|
||||
Reference in new issue
Block a user