Skip to content
Open
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
16 changes: 4 additions & 12 deletions src/lib/pages/schedules.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script lang="ts">
import { onMount } from 'svelte';

import { goto } from '$app/navigation';
import { page } from '$app/state';

import SchedulesCount from '$lib/components/schedule/schedules-count.svelte';
Expand Down Expand Up @@ -84,8 +83,10 @@
}
});

const onError = (err: APIErrorResponse) => {
error = err?.body?.message || translate('schedules.error-message-fetching');
const onError = (err: unknown) => {
error =
(err as APIErrorResponse)?.body?.message ||
translate('schedules.error-message-fetching');
};

const showFilters = $derived(Number($schedulesCount) > 0 || query);
Expand Down Expand Up @@ -170,15 +171,6 @@
>Temporal CLI</Link
>.
</p>
{#if !createDisabled}
<Button
data-testid="create-schedule"
on:click={() => goto(routeForScheduleCreate({ namespace }))}
disabled={!writeActionsAreAllowed()}
>
{translate('schedules.create')}
</Button>
{/if}
</EmptyState>
{/if}
</svelte:fragment>
Expand Down
27 changes: 13 additions & 14 deletions src/lib/services/workflow-counts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,17 @@ export const fetchScheduleCount = async ({
namespace: string;
query?: string;
}): Promise<string> => {
return fetchScheduleCountLegacy(namespace, query);
// try {
// const countRoute = routeForApi('schedules.count', { namespace });
// const { count } = await requestFromAPI<CountSchedulesResponse>(countRoute, {
// params: query ? { query } : {},
// notifyOnError: false,
// });
// return count ?? '0';
// } catch (error: unknown) {
// if (isNotImplemented(error) || isNotFound(error)) {
// return fetchScheduleCountLegacy(namespace, query);
// }
// throw error;
// }
try {
const countRoute = routeForApi('schedules.count', { namespace });
const { count } = await requestFromAPI<CountSchedulesResponse>(countRoute, {
params: query ? { query } : {},
notifyOnError: false,
});
return count ?? '0';
} catch (error: unknown) {
if (isNotImplemented(error) || isNotFound(error)) {
return fetchScheduleCountLegacy(namespace, query);
}
throw error;
}
};
4 changes: 2 additions & 2 deletions tests/e2e/schedules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ test.describe('Schedules Page', () => {
await scheduleButton.click();
await expect(page).toHaveURL(/schedules/);
const createScheduleButton = page.getByTestId('create-schedule');
await expect(createScheduleButton.first()).toBeVisible();
await createScheduleButton.first().click();
await expect(createScheduleButton).toBeVisible();
await createScheduleButton.click();
await expect(page).toHaveURL(/create/);

await page.getByTestId('schedule-name-input').fill('e2e-schedule-1');
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/disable-write-actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ test.describe('Disable write actions on empty schedules list actions', () => {
const namespace = page.locator('h1');
await expect(namespace).toHaveText('0 Schedules');
const createButton = page.getByTestId('create-schedule');
await expect(createButton.first()).toBeDisabled();
await expect(createButton).toBeDisabled();
});
});
6 changes: 3 additions & 3 deletions tests/integration/schedule-edit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect, test } from '@playwright/test';
import {
mockScheduleApi,
mockSchedulesApis,
WORKFLOWS_COUNT_API,
SCHEDULES_COUNT_API,
} from '~/test-utilities/mock-apis';

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

await page.waitForResponse(WORKFLOWS_COUNT_API);
await page.waitForResponse(SCHEDULES_COUNT_API);

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

const scheduleLink = page.getByRole('link', { name: /test-schedule/i });
await expect(scheduleLink).toBeVisible();
Expand Down
32 changes: 28 additions & 4 deletions tests/integration/schedules-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test';

import {
mockSchedulesApis,
WORKFLOWS_COUNT_API,
SCHEDULES_COUNT_API,
} from '~/test-utilities/mock-apis';

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

await page.waitForResponse(WORKFLOWS_COUNT_API);
await page.waitForResponse(SCHEDULES_COUNT_API);
const namespace = page.locator('h1');
await expect(namespace).toHaveText('0 Schedules');

const createButton = page.getByTestId('create-schedule');
await expect(createButton.first()).toBeEnabled();
await expect(createButton).toBeEnabled();
});

test('it displays empty state when there are no schedules', async ({
page,
}) => {
await page.goto(schedulesUrl);

await page.waitForResponse(SCHEDULES_COUNT_API);
const emptyState = page.getByText('No Schedules Found');
await expect(emptyState).toBeVisible();
});
});

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

await page.waitForResponse(WORKFLOWS_COUNT_API);
await page.waitForResponse(SCHEDULES_COUNT_API);
const namespace = page.locator('h1');
await expect(namespace).toHaveText('15 Schedules');

const createButton = page.getByTestId('create-schedule');
await expect(createButton).toBeEnabled();
});

test('it renders schedule table rows', async ({ page }) => {
await page.goto(schedulesUrl);

await page.waitForResponse(SCHEDULES_COUNT_API);
const tableRows = page.locator('table tbody tr');
await expect(tableRows).toHaveCount(1);

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

const workflowType = page.getByText('run-regularly');
await expect(workflowType).toBeVisible();
});
});
2 changes: 1 addition & 1 deletion tests/test-utilities/mock-apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const mockSchedulesApis = (
mockNamespaceApis(page),
mockSearchAttributesApi(page, customSearchAttributes),
mockSchedulesApi(page, empty),
mockWorkflowsCountApi(page, emptySchedulesCount),
mockSchedulesCountApi(page, emptySchedulesCount),
]);
};

Expand Down
Loading