Skip to content

Commit c58019a

Browse files
authored
Use CountSchedules API (#3258)
* Use CountSchedules API for schedule count * Remove duplicate Create Schedule button in schedules table empty state * Update schedules-list integration test
1 parent 8e795d8 commit c58019a

7 files changed

Lines changed: 52 additions & 37 deletions

File tree

src/lib/pages/schedules.svelte

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script lang="ts">
22
import { onMount } from 'svelte';
33
4-
import { goto } from '$app/navigation';
54
import { page } from '$app/state';
65
76
import SchedulesCount from '$lib/components/schedule/schedules-count.svelte';
@@ -84,8 +83,10 @@
8483
}
8584
});
8685
87-
const onError = (err: APIErrorResponse) => {
88-
error = err?.body?.message || translate('schedules.error-message-fetching');
86+
const onError = (err: unknown) => {
87+
error =
88+
(err as APIErrorResponse)?.body?.message ||
89+
translate('schedules.error-message-fetching');
8990
};
9091
9192
const showFilters = $derived(Number($schedulesCount) > 0 || query);
@@ -170,15 +171,6 @@
170171
>Temporal CLI</Link
171172
>.
172173
</p>
173-
{#if !createDisabled}
174-
<Button
175-
data-testid="create-schedule"
176-
on:click={() => goto(routeForScheduleCreate({ namespace }))}
177-
disabled={!writeActionsAreAllowed()}
178-
>
179-
{translate('schedules.create')}
180-
</Button>
181-
{/if}
182174
</EmptyState>
183175
{/if}
184176
</svelte:fragment>

src/lib/services/workflow-counts.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,17 @@ export const fetchScheduleCount = async ({
7676
namespace: string;
7777
query?: string;
7878
}): Promise<string> => {
79-
return fetchScheduleCountLegacy(namespace, query);
80-
// try {
81-
// const countRoute = routeForApi('schedules.count', { namespace });
82-
// const { count } = await requestFromAPI<CountSchedulesResponse>(countRoute, {
83-
// params: query ? { query } : {},
84-
// notifyOnError: false,
85-
// });
86-
// return count ?? '0';
87-
// } catch (error: unknown) {
88-
// if (isNotImplemented(error) || isNotFound(error)) {
89-
// return fetchScheduleCountLegacy(namespace, query);
90-
// }
91-
// throw error;
92-
// }
79+
try {
80+
const countRoute = routeForApi('schedules.count', { namespace });
81+
const { count } = await requestFromAPI<CountSchedulesResponse>(countRoute, {
82+
params: query ? { query } : {},
83+
notifyOnError: false,
84+
});
85+
return count ?? '0';
86+
} catch (error: unknown) {
87+
if (isNotImplemented(error) || isNotFound(error)) {
88+
return fetchScheduleCountLegacy(namespace, query);
89+
}
90+
throw error;
91+
}
9392
};

tests/e2e/schedules.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ test.describe('Schedules Page', () => {
2323
await scheduleButton.click();
2424
await expect(page).toHaveURL(/schedules/);
2525
const createScheduleButton = page.getByTestId('create-schedule');
26-
await expect(createScheduleButton.first()).toBeVisible();
27-
await createScheduleButton.first().click();
26+
await expect(createScheduleButton).toBeVisible();
27+
await createScheduleButton.click();
2828
await expect(page).toHaveURL(/create/);
2929

3030
await page.getByTestId('schedule-name-input').fill('e2e-schedule-1');

tests/integration/disable-write-actions.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ test.describe('Disable write actions on empty schedules list actions', () => {
5151
const namespace = page.locator('h1');
5252
await expect(namespace).toHaveText('0 Schedules');
5353
const createButton = page.getByTestId('create-schedule');
54-
await expect(createButton.first()).toBeDisabled();
54+
await expect(createButton).toBeDisabled();
5555
});
5656
});

tests/integration/schedule-edit.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect, test } from '@playwright/test';
33
import {
44
mockScheduleApi,
55
mockSchedulesApis,
6-
WORKFLOWS_COUNT_API,
6+
SCHEDULES_COUNT_API,
77
} from '~/test-utilities/mock-apis';
88

99
const schedulesUrl = '/namespaces/default/schedules';
@@ -18,10 +18,10 @@ test.describe('Schedules List with schedules', () => {
1818
test('selects schedule and edits', async ({ page }) => {
1919
await page.goto(schedulesUrl);
2020

21-
await page.waitForResponse(WORKFLOWS_COUNT_API);
21+
await page.waitForResponse(SCHEDULES_COUNT_API);
2222

2323
const createButton = page.getByTestId('create-schedule');
24-
await expect(createButton.first()).toBeEnabled();
24+
await expect(createButton).toBeEnabled();
2525

2626
const scheduleLink = page.getByRole('link', { name: /test-schedule/i });
2727
await expect(scheduleLink).toBeVisible();

tests/integration/schedules-list.spec.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test';
22

33
import {
44
mockSchedulesApis,
5-
WORKFLOWS_COUNT_API,
5+
SCHEDULES_COUNT_API,
66
} from '~/test-utilities/mock-apis';
77

88
const schedulesUrl = '/namespaces/default/schedules';
@@ -17,12 +17,22 @@ test.describe('Schedules List with no schedules', () => {
1717
}) => {
1818
await page.goto(schedulesUrl);
1919

20-
await page.waitForResponse(WORKFLOWS_COUNT_API);
20+
await page.waitForResponse(SCHEDULES_COUNT_API);
2121
const namespace = page.locator('h1');
2222
await expect(namespace).toHaveText('0 Schedules');
2323

2424
const createButton = page.getByTestId('create-schedule');
25-
await expect(createButton.first()).toBeEnabled();
25+
await expect(createButton).toBeEnabled();
26+
});
27+
28+
test('it displays empty state when there are no schedules', async ({
29+
page,
30+
}) => {
31+
await page.goto(schedulesUrl);
32+
33+
await page.waitForResponse(SCHEDULES_COUNT_API);
34+
const emptyState = page.getByText('No Schedules Found');
35+
await expect(emptyState).toBeVisible();
2636
});
2737
});
2838

@@ -36,11 +46,25 @@ test.describe('Schedules List with schedules', () => {
3646
}) => {
3747
await page.goto(schedulesUrl);
3848

39-
await page.waitForResponse(WORKFLOWS_COUNT_API);
49+
await page.waitForResponse(SCHEDULES_COUNT_API);
4050
const namespace = page.locator('h1');
4151
await expect(namespace).toHaveText('15 Schedules');
4252

4353
const createButton = page.getByTestId('create-schedule');
4454
await expect(createButton).toBeEnabled();
4555
});
56+
57+
test('it renders schedule table rows', async ({ page }) => {
58+
await page.goto(schedulesUrl);
59+
60+
await page.waitForResponse(SCHEDULES_COUNT_API);
61+
const tableRows = page.locator('table tbody tr');
62+
await expect(tableRows).toHaveCount(1);
63+
64+
const scheduleLink = page.getByRole('link', { name: 'test-schedule' });
65+
await expect(scheduleLink).toBeVisible();
66+
67+
const workflowType = page.getByText('run-regularly');
68+
await expect(workflowType).toBeVisible();
69+
});
4670
});

tests/test-utilities/mock-apis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export const mockSchedulesApis = (
108108
mockNamespaceApis(page),
109109
mockSearchAttributesApi(page, customSearchAttributes),
110110
mockSchedulesApi(page, empty),
111-
mockWorkflowsCountApi(page, emptySchedulesCount),
111+
mockSchedulesCountApi(page, emptySchedulesCount),
112112
]);
113113
};
114114

0 commit comments

Comments
 (0)