From b231e68c6eab2f8403275aa30224ac1b6b3be96a Mon Sep 17 00:00:00 2001 From: Shailesh Parmar Date: Fri, 1 Oct 2021 17:51:01 +0530 Subject: [PATCH] Test suit for explore, service, and database page (#622) * Adding test-suits for UI * fixed broken tests * fixed all test fail files * removed parsing errors from files * resolved test-suits error * fiexed all the failing test * fixed tabledatacard title padding * fixed popOver test * fixed eslint issue in file * added eslint disable on top of file * add test for searchData and MyDataHeader * add addtional test for teams page * test suits for teams page and its components * added test cases for tags page * added test for services page * add test for service page and its component * fixed typo * test for databasedetails, myData and explore page * test for service page * fixed some failing test * fixed failing test due to data type change Co-authored-by: darth-coder00 --- .../ui/src/components/app-bar/Appbar.test.tsx | 48 +++- .../ui/src/components/app-bar/Appbar.tsx | 3 +- .../my-data-details/SchemaTab.test.tsx | 4 +- .../my-data-details/SchemaTable.test.tsx | 16 +- .../components/my-data/MyDataHeader.test.tsx | 2 +- .../src/pages/database-details/index.test.tsx | 254 ++++++++++++++++++ .../ui/src/pages/database-details/index.tsx | 43 ++- .../ui/src/pages/explore/index.test.tsx | 33 +-- .../resources/ui/src/pages/explore/index.tsx | 1 + .../ui/src/pages/my-data/index.test.tsx | 23 +- .../ui/src/pages/service/index.test.tsx | 43 +++ .../resources/ui/src/pages/service/index.tsx | 7 +- 12 files changed, 423 insertions(+), 54 deletions(-) create mode 100644 catalog-rest-service/src/main/resources/ui/src/pages/database-details/index.test.tsx diff --git a/catalog-rest-service/src/main/resources/ui/src/components/app-bar/Appbar.test.tsx b/catalog-rest-service/src/main/resources/ui/src/components/app-bar/Appbar.test.tsx index 2415cc07bdb..05601172b36 100644 --- a/catalog-rest-service/src/main/resources/ui/src/components/app-bar/Appbar.test.tsx +++ b/catalog-rest-service/src/main/resources/ui/src/components/app-bar/Appbar.test.tsx @@ -15,7 +15,13 @@ * limitations under the License. */ -import { render } from '@testing-library/react'; +import { + findAllByTestId, + findByTestId, + findByText, + fireEvent, + render, +} from '@testing-library/react'; import React from 'react'; import { MemoryRouter } from 'react-router-dom'; import Appbar from './Appbar'; @@ -26,6 +32,7 @@ jest.mock('../../hooks/authHooks', () => ({ isSignedIn: true, isSignedOut: false, isAuthenticatedRoute: true, + isAuthDisabled: true, }; }, })); @@ -34,34 +41,49 @@ jest.mock('../Modals/WhatsNewModal', () => ({ WhatsNewModal: jest.fn().mockReturnValue(

WhatsNewModal

), })); +jest.mock('../../axiosAPIs/miscAPI', () => ({ + getVersion: jest.fn().mockImplementation(() => + Promise.resolve({ + data: { + version: '0.5.0-SNAPSHOT', + }, + }) + ), +})); + describe('Test Appbar Component', () => { - it('Component should render', () => { - const { getByTestId } = render(, { + it('Component should render', async () => { + const { container } = render(, { wrapper: MemoryRouter, }); - // Check for statis user for now - // TODO: Fix the tests when we have actual data - const dropdown = getByTestId('dropdown-profile'); + + const dropdown = await findByTestId(container, 'dropdown-profile'); + const whatsnewModal = await findByTestId(container, 'whatsnew-modal'); + const greetingText = await findByTestId(container, 'greeting-text'); expect(dropdown).toBeInTheDocument(); + expect(whatsnewModal).toBeInTheDocument(); + expect(greetingText).toBeInTheDocument(); }); - it('Check for render Items by default', () => { - const { getAllByTestId } = render(, { + it('Check for render Items by default', async () => { + const { container } = render(, { wrapper: MemoryRouter, }); - const items = getAllByTestId('appbar-item'); + const items = await findAllByTestId(container, 'appbar-item'); expect(items).toHaveLength(2); expect(items.map((i) => i.textContent)).toEqual(['', 'Explore']); }); - it('Check for render dropdown item', () => { - const { getAllByTestId } = render(, { + it('onClick of whatsNewModal, it should open', async () => { + const { container } = render(, { wrapper: MemoryRouter, }); - const items = getAllByTestId('dropdown-item'); - expect(items).toHaveLength(3); + const whatsnewModal = await findByTestId(container, 'whatsnew-modal'); + fireEvent.click(whatsnewModal); + + expect(await findByText(container, /WhatsNewModal/i)).toBeInTheDocument(); }); }); diff --git a/catalog-rest-service/src/main/resources/ui/src/components/app-bar/Appbar.tsx b/catalog-rest-service/src/main/resources/ui/src/components/app-bar/Appbar.tsx index f03695d8b47..bbdab807652 100644 --- a/catalog-rest-service/src/main/resources/ui/src/components/app-bar/Appbar.tsx +++ b/catalog-rest-service/src/main/resources/ui/src/components/app-bar/Appbar.tsx @@ -130,7 +130,7 @@ const Appbar: React.FC = (): JSX.Element => { : appState.userDetails.displayName || appState.userDetails.name; return ( - + Welcome, {name.split(' ')[0]} ); @@ -238,6 +238,7 @@ const Appbar: React.FC = (): JSX.Element => {