Skip to content

Commit 8535629

Browse files
authored
fix(Tenant): fix infinite load if describe returns empty data (#1167)
1 parent ac380ba commit 8535629

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Install all Playwright dependencies and chromium to run tests.
9494
npm run test:e2e:install
9595
```
9696

97-
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.
97+
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.
9898

9999
```
100100
npm run test:e2e

src/containers/Tenant/Tenant.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,19 @@ export function Tenant(props: TenantProps) {
9191
dispatchSummaryVisibilityAction(PaneVisibilityActionTypes.clear);
9292
};
9393

94+
const [initialLoading, setInitialLoading] = React.useState(true);
95+
if (initialLoading && !isLoading) {
96+
setInitialLoading(false);
97+
}
98+
9499
const title = path || i18n('page.title');
95100
return (
96101
<div className={b()}>
97102
<Helmet
98103
defaultTitle={`${title} — YDB Monitoring`}
99104
titleTemplate={`%s — ${title} — YDB Monitoring`}
100105
/>
101-
<LoaderWrapper loading={isLoading}>
106+
<LoaderWrapper loading={initialLoading}>
102107
<PageError error={showBlockingError ? error : undefined}>
103108
<SplitPane
104109
defaultSizePaneKey={DEFAULT_SIZE_TENANT_KEY}
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import {expect, test} from '@playwright/test';
2+
3+
import {backend, tenantName} from '../../utils/constants';
4+
5+
import {TenantPage} from './TenantPage';
6+
7+
const pageQueryParams = {
8+
schema: tenantName,
9+
name: tenantName,
10+
tenantPage: 'diagnostics',
11+
};
12+
13+
test.describe('Tenant initial load', () => {
14+
test('Tenant diagnostics page is visible', async ({page}) => {
15+
const tenantPage = new TenantPage(page);
16+
await tenantPage.goto(pageQueryParams);
17+
18+
await expect(page.locator('.kv-tenant-diagnostics')).toBeVisible();
19+
});
20+
21+
test('Tenant diagnostics page is visible when describe returns no data', async ({page}) => {
22+
await page.route(`${backend}/viewer/json/describe?*`, async (route) => {
23+
await route.fulfill({json: ''});
24+
});
25+
26+
const tenantPage = new TenantPage(page);
27+
await tenantPage.goto(pageQueryParams);
28+
29+
await expect(page.locator('.kv-tenant-diagnostics')).toBeVisible();
30+
});
31+
32+
test('Tenant page shows error message when describe returns 401', async ({page}) => {
33+
await page.route(`${backend}/viewer/json/describe?*`, async (route) => {
34+
await route.fulfill({status: 401});
35+
});
36+
37+
const tenantPage = new TenantPage(page);
38+
await tenantPage.goto(pageQueryParams);
39+
40+
await expect(page.locator('.empty-state')).toBeVisible();
41+
await expect(page.locator('.empty-state__title')).toHaveText('Access denied');
42+
});
43+
44+
test('Tenant page shows error message when describe returns 403', async ({page}) => {
45+
await page.route(`${backend}/viewer/json/describe?*`, async (route) => {
46+
await route.fulfill({status: 403});
47+
});
48+
49+
const tenantPage = new TenantPage(page);
50+
await tenantPage.goto(pageQueryParams);
51+
52+
await expect(page.locator('.empty-state')).toBeVisible();
53+
await expect(page.locator('.empty-state__title')).toHaveText('Access denied');
54+
});
55+
});

tests/utils/constants.ts

+3
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ export const tenantPage = 'tenant';
88

99
// Entities
1010
export const tenantName = '/local';
11+
12+
// URLs
13+
export const backend = process.env.PLAYWRIGHT_APP_BACKEND || 'http://localhost:8765';

0 commit comments

Comments
 (0)