Skip to content

Commit

Permalink
add state tests
Browse files Browse the repository at this point in the history
Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>
(cherry picked from commit 01c538d)
  • Loading branch information
ps48 committed Apr 2, 2024
1 parent c966381 commit eb6e392
Show file tree
Hide file tree
Showing 4 changed files with 359 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Test Catalog tree Loading state S3 catalog tree 1`] = `
<div>
<div>
<div
class="euiText euiText--medium euiTreeView__wrapper"
>
<p
class="euiScreenReaderOnly"
id="some_html_id--instruction"
>
You can quickly navigate this list using arrow keys.
</p>
<ul
aria-describedby="some_html_id--instruction"
aria-label="S3 Datasource Folder Tree"
class="euiTreeView workbench-tree"
data-test-subj="s3-datasource-tree"
id="some_html_id"
>
<li
class="euiTreeView__node"
>
<button
aria-controls="some_html_id"
aria-expanded="false"
class="euiTreeView__nodeInner"
data-test-subj="euiTreeViewButton-some_html_id"
id="element_0"
>
<span
class="euiTreeView__iconWrapper"
>
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiIcon-isLoading"
focusable="false"
height="16"
role="img"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M5.277 10.088c.02.014.04.03.057.047.582.55 1.134.812 1.666.812.586 0 1.84-.293 3.713-.88L9 6.212V2H7v4.212l-1.723 3.876Zm-.438.987L3.539 14h8.922l-1.32-2.969C9.096 11.677 7.733 12 7 12c-.74 0-1.463-.315-2.161-.925ZM6 2H5V1h6v1h-1v4l3.375 7.594A1 1 0 0 1 12.461 15H3.54a1 1 0 0 1-.914-1.406L6 6V2Z"
/>
</svg>
</span>
<span
class="euiTreeView__nodeLabel"
>
<div>
<span
class="euiToolTipAnchor"
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--directionRow euiFlexGroup--responsive"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<div
class="euiText euiText--medium"
>
db1
</div>
</div>
</div>
</span>
</div>
</span>
</button>
<div
id="some_html_id"
/>
</li>
<li
class="euiTreeView__node"
>
<button
aria-controls="some_html_id"
aria-expanded="false"
class="euiTreeView__nodeInner"
data-test-subj="euiTreeViewButton-some_html_id"
id="element_1"
>
<span
class="euiTreeView__iconWrapper"
>
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiIcon-isLoading"
focusable="false"
height="16"
role="img"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M5.277 10.088c.02.014.04.03.057.047.582.55 1.134.812 1.666.812.586 0 1.84-.293 3.713-.88L9 6.212V2H7v4.212l-1.723 3.876Zm-.438.987L3.539 14h8.922l-1.32-2.969C9.096 11.677 7.733 12 7 12c-.74 0-1.463-.315-2.161-.925ZM6 2H5V1h6v1h-1v4l3.375 7.594A1 1 0 0 1 12.461 15H3.54a1 1 0 0 1-.914-1.406L6 6V2Z"
/>
</svg>
</span>
<span
class="euiTreeView__nodeLabel"
>
<div>
<span
class="euiToolTipAnchor"
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--directionRow euiFlexGroup--responsive"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<div
class="euiText euiText--medium"
>
db2
</div>
</div>
</div>
</span>
</div>
</span>
</button>
<div
id="some_html_id"
/>
</li>
</ul>
</div>
</div>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Test Catalog tree Loading state S3 catalog tree 1`] = `
<div>
<div>
<div
class="euiFlexGroup euiFlexGroup--gutterSmall euiFlexGroup--alignItemsCenter euiFlexGroup--directionColumn euiFlexGroup--responsive"
>
<div
class="euiSpacer euiSpacer--l"
/>
<div
class="euiFlexItem"
>
<span
class="euiLoadingSpinner euiLoadingSpinner--large"
/>
</div>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
Loading databases
</div>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<div
style="padding: 10px;"
>
<div
class="euiFlexItem"
>
<div
class="euiText euiText--medium"
>
<div
class="euiTextAlign euiTextAlign--center"
>
<div
class="euiTextColor euiTextColor--subdued"
>
Loading may take over 30 seconds
</div>
</div>
</div>
</div>
<div
class="euiFlexItem"
>
<div
class="euiText euiText--medium"
>
<div
class="euiTextAlign euiTextAlign--center"
>
<div
class="euiTextColor euiTextColor--subdued"
>
Status:
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { render, waitFor } from '@testing-library/react';
import React from 'react';
import { httpClientMock } from '../../../../../test/mocks';
import { mockDataSelectQuery, mockHttpQuery } from '../../../../../test/mocks/mockData';
import { CatalogTree } from '../catalog_tree';

jest.mock('../../../../dependencies/register_observability_dependencies', () => ({
getRenderAccelerationDetailsFlyout: jest.fn(() => jest.fn()),
getRenderCreateAccelerationFlyout: jest.fn(() => jest.fn()),
setRenderAccelerationDetailsFlyout: jest.fn(() => jest.fn()),
setRenderCreateAccelerationFlyout: jest.fn(() => jest.fn()),
}));

jest.mock('../../../../framework/catalog_cache_refs', () => ({
catalogCacheRefs: {
useLoadDatabasesToCache: jest.fn(() => ({
loadStatus: '',
startLoading: jest.fn(),
stopLoading: jest.fn(),
})),
useLoadTablesToCache: jest.fn(() => ({
loadStatus: '',
startLoading: jest.fn(),
stopLoading: jest.fn(),
})),
useLoadTableColumnsToCache: jest.fn(() => ({
loadStatus: '',
startLoading: jest.fn(),
stopLoading: jest.fn(),
})),
useLoadAccelerationsToCache: jest.fn(() => ({
loadStatus: '',
startLoading: jest.fn(),
stopLoading: jest.fn(),
})),
CatalogCacheManager: {
getOrCreateDataSource: jest.fn(() => ({
name: 'my_s3',
lastUpdated: '',
status: 'Updated',
databases: [
{
name: 'db1',
},
{
name: 'db2',
},
],
})),
},
},
}));

describe('Test Catalog tree', () => {
it('Loading state S3 catalog tree', async () => {
const client = httpClientMock;
client.post = jest.fn().mockResolvedValue(mockHttpQuery);
client.get = jest.fn().mockResolvedValue(mockDataSelectQuery);
const { getByText } = render(
<CatalogTree
selectedItems={[{ label: 'my_s3' }]}
updateSQLQueries={jest.fn()}
refreshTree={true}
/>
);

await waitFor(() => {
expect(getByText('db1')).toBeInTheDocument();
});

expect(document.body.children[0]).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { render, waitFor } from '@testing-library/react';
import React from 'react';
import { httpClientMock } from '../../../../../test/mocks';
import { mockDataSelectQuery, mockHttpQuery } from '../../../../../test/mocks/mockData';
import { CatalogTree } from '../catalog_tree';

jest.mock('../../../../dependencies/register_observability_dependencies', () => ({
getRenderAccelerationDetailsFlyout: jest.fn(() => jest.fn()),
getRenderCreateAccelerationFlyout: jest.fn(() => jest.fn()),
setRenderAccelerationDetailsFlyout: jest.fn(() => jest.fn()),
setRenderCreateAccelerationFlyout: jest.fn(() => jest.fn()),
}));

jest.mock('../../../../framework/catalog_cache_refs', () => ({
catalogCacheRefs: {
useLoadDatabasesToCache: jest.fn(() => ({
loadStatus: '',
startLoading: jest.fn(),
stopLoading: jest.fn(),
})),
useLoadTablesToCache: jest.fn(() => ({
loadStatus: '',
startLoading: jest.fn(),
stopLoading: jest.fn(),
})),
useLoadTableColumnsToCache: jest.fn(() => ({
loadStatus: '',
startLoading: jest.fn(),
stopLoading: jest.fn(),
})),
useLoadAccelerationsToCache: jest.fn(() => ({
loadStatus: '',
startLoading: jest.fn(),
stopLoading: jest.fn(),
})),
CatalogCacheManager: {
getOrCreateDataSource: jest.fn(() => ({
name: 'my_s3',
lastUpdated: '',
status: '',
databases: [],
})),
},
},
}));

describe('Test Catalog tree', () => {
it('Loading state S3 catalog tree', async () => {
const client = httpClientMock;
client.post = jest.fn().mockResolvedValue(mockHttpQuery);
client.get = jest.fn().mockResolvedValue(mockDataSelectQuery);
const { getByText } = render(
<CatalogTree
selectedItems={[{ label: 'my_s3' }]}
updateSQLQueries={jest.fn()}
refreshTree={true}
/>
);

await waitFor(() => {
expect(getByText('Loading databases')).toBeInTheDocument();
});

expect(document.body.children[0]).toMatchSnapshot();
});
});

0 comments on commit eb6e392

Please sign in to comment.