Skip to content

Commit

Permalink
fix(Tenant): fix infinite load if describe returns empty data (#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeraS authored Aug 15, 2024
1 parent ac380ba commit 8535629
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Install all Playwright dependencies and chromium to run tests.
npm run test:e2e:install
```

Run tests. If `PLAYWRIGHT_BASE_URL` is provided, tests run on this url, otherwise Playwright `webServer` is started with `npm run dev` on `http://localhost:3000` and all tests run there.
Run tests. If `PLAYWRIGHT_BASE_URL` is provided, tests run on this url, otherwise Playwright `webServer` is started with `npm run dev` on `http://localhost:3000` and all tests run there. If `PLAYWRIGHT_APP_BACKEND` is provided, tests will be use this url as backend, otherwise `http://localhost:8765` will be used.

```
npm run test:e2e
Expand Down
7 changes: 6 additions & 1 deletion src/containers/Tenant/Tenant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,19 @@ export function Tenant(props: TenantProps) {
dispatchSummaryVisibilityAction(PaneVisibilityActionTypes.clear);
};

const [initialLoading, setInitialLoading] = React.useState(true);
if (initialLoading && !isLoading) {
setInitialLoading(false);
}

const title = path || i18n('page.title');
return (
<div className={b()}>
<Helmet
defaultTitle={`${title} — YDB Monitoring`}
titleTemplate={`%s — ${title} — YDB Monitoring`}
/>
<LoaderWrapper loading={isLoading}>
<LoaderWrapper loading={initialLoading}>
<PageError error={showBlockingError ? error : undefined}>
<SplitPane
defaultSizePaneKey={DEFAULT_SIZE_TENANT_KEY}
Expand Down
55 changes: 55 additions & 0 deletions tests/suites/tenant/initialLoad.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {expect, test} from '@playwright/test';

import {backend, tenantName} from '../../utils/constants';

import {TenantPage} from './TenantPage';

const pageQueryParams = {
schema: tenantName,
name: tenantName,
tenantPage: 'diagnostics',
};

test.describe('Tenant initial load', () => {
test('Tenant diagnostics page is visible', async ({page}) => {
const tenantPage = new TenantPage(page);
await tenantPage.goto(pageQueryParams);

await expect(page.locator('.kv-tenant-diagnostics')).toBeVisible();
});

test('Tenant diagnostics page is visible when describe returns no data', async ({page}) => {
await page.route(`${backend}/viewer/json/describe?*`, async (route) => {
await route.fulfill({json: ''});
});

const tenantPage = new TenantPage(page);
await tenantPage.goto(pageQueryParams);

await expect(page.locator('.kv-tenant-diagnostics')).toBeVisible();
});

test('Tenant page shows error message when describe returns 401', async ({page}) => {
await page.route(`${backend}/viewer/json/describe?*`, async (route) => {
await route.fulfill({status: 401});
});

const tenantPage = new TenantPage(page);
await tenantPage.goto(pageQueryParams);

await expect(page.locator('.empty-state')).toBeVisible();
await expect(page.locator('.empty-state__title')).toHaveText('Access denied');
});

test('Tenant page shows error message when describe returns 403', async ({page}) => {
await page.route(`${backend}/viewer/json/describe?*`, async (route) => {
await route.fulfill({status: 403});
});

const tenantPage = new TenantPage(page);
await tenantPage.goto(pageQueryParams);

await expect(page.locator('.empty-state')).toBeVisible();
await expect(page.locator('.empty-state__title')).toHaveText('Access denied');
});
});
3 changes: 3 additions & 0 deletions tests/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ export const tenantPage = 'tenant';

// Entities
export const tenantName = '/local';

// URLs
export const backend = process.env.PLAYWRIGHT_APP_BACKEND || 'http://localhost:8765';

0 comments on commit 8535629

Please sign in to comment.