Skip to content

Commit

Permalink
Migrated unit tests on CustomDashboarList and View packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Sara4994 committed Jul 31, 2023
1 parent 89c50cb commit 914e001
Show file tree
Hide file tree
Showing 20 changed files with 1,112 additions and 1,518 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ describe('FormRenderer test', () => {

const { container } = render(<FormRenderer {...props} />);
expect(screen).toMatchSnapshot();
// screen.debug()
// const form = container.findWhere((node) => node.type() === AutoForm);

// expect(form.exists()).toBeTruthy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const CustomDashboardListToolbar: React.FC<
id="apply-filter"
variant="primary"
onClick={doApplyFilter}
data-testit="apply-filter"
data-testid="apply-filter"
>
Apply Filter
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,17 @@
import React from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
import CustomDashboardListToolbar from '../CustomDashboardListToolbar';
import { act } from 'react-dom/test-utils';
import { ToolbarFilter } from '@patternfly/react-core/dist/js/components/Toolbar';
import { Button } from '@patternfly/react-core/dist/js/components/Button';
import { Tooltip } from '@patternfly/react-core/dist/js/components/Tooltip';

describe('CustomDashboard list toolbar tests', () => {
it('render toolbar', () => {
render(
const { container } = render(
<CustomDashboardListToolbar
applyFilter={jest.fn()}
setFilterDashboardNames={jest.fn()}
filterDashboardNames={[]}
/>
);
expect(screen).toMatchSnapshot();
expect(container).toMatchSnapshot();
});

it('apply filter click', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,145 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CustomDashboard list toolbar tests render toolbar 1`] = `
Object {
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"logTestingPlaygroundURL": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
}
<div>
<div
class="pf-c-toolbar pf-m-toggle-group-container"
data-ouia-component-id="OUIA-Generated-Toolbar-1"
data-ouia-component-type="custom-dashboard-list-toolbar"
data-ouia-safe="true"
id="custom-dashboard-list-with-filter"
>
<div
class="pf-c-toolbar__content"
>
<div
class="pf-c-toolbar__content-section"
>
<div
class="pf-c-toolbar__group pf-m-toggle-group pf-m-show-on-xl"
>
<div
class="pf-c-toolbar__toggle"
>
<button
aria-controls="custom-dashboard-list-with-filter-expandable-content-1"
aria-disabled="false"
aria-haspopup="false"
aria-label="Show Filters"
class="pf-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-1"
data-ouia-component-type="PF4/Button"
data-ouia-safe="true"
type="button"
>
<svg
aria-hidden="true"
fill="currentColor"
height="1em"
role="img"
style="vertical-align: -0.125em;"
viewBox="0 0 512 512"
width="1em"
>
<path
d="M487.976 0H24.028C2.71 0-8.047 25.866 7.058 40.971L192 225.941V432c0 7.831 3.821 15.17 10.237 19.662l80 55.98C298.02 518.69 320 507.493 320 487.98V225.941l184.947-184.97C520.021 25.896 509.338 0 487.976 0z"
/>
</svg>
</button>
</div>
<div
class="pf-c-toolbar__group pf-m-filter-group"
>
<div
class="pf-c-toolbar__item"
>
<div
class="pf-c-input-group"
>
<input
aria-invalid="false"
aria-label="Dashboard name"
class="pf-c-form-control"
data-ouia-component-id="OUIA-Generated-TextInputBase-2"
data-ouia-component-type="PF4/TextInput"
data-ouia-safe="true"
id="customDashboardName"
name="customDashboardName"
placeholder="Filter by dashboard name"
type="search"
value=""
/>
</div>
</div>
<div
class="pf-c-toolbar__item"
>
<button
aria-disabled="false"
class="pf-c-button pf-m-primary"
data-ouia-component-id="OUIA-Generated-Button-primary-1"
data-ouia-component-type="PF4/Button"
data-ouia-safe="true"
data-testid="apply-filter"
id="apply-filter"
type="button"
>
Apply Filter
</button>
</div>
</div>
</div>
<div
class="pf-c-toolbar__group pf-m-icon-button-group"
>
<div
class="pf-c-toolbar__item"
>
<button
aria-disabled="false"
class="pf-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-2"
data-ouia-component-type="PF4/Button"
data-ouia-safe="true"
id="refresh"
type="button"
>
<svg
aria-hidden="true"
fill="currentColor"
height="1em"
role="img"
style="vertical-align: -0.125em;"
viewBox="0 0 512 512"
width="1em"
>
<path
d="M440.65 12.57l4 82.77A247.16 247.16 0 0 0 255.83 8C134.73 8 33.91 94.92 12.29 209.82A12 12 0 0 0 24.09 224h49.05a12 12 0 0 0 11.67-9.26 175.91 175.91 0 0 1 317-56.94l-101.46-4.86a12 12 0 0 0-12.57 12v47.41a12 12 0 0 0 12 12H500a12 12 0 0 0 12-12V12a12 12 0 0 0-12-12h-47.37a12 12 0 0 0-11.98 12.57zM255.83 432a175.61 175.61 0 0 1-146-77.8l101.8 4.87a12 12 0 0 0 12.57-12v-47.4a12 12 0 0 0-12-12H12a12 12 0 0 0-12 12V500a12 12 0 0 0 12 12h47.35a12 12 0 0 0 12-12.6l-4.15-82.57A247.17 247.17 0 0 0 255.83 504c121.11 0 221.93-86.92 243.55-201.82a12 12 0 0 0-11.8-14.18h-49.05a12 12 0 0 0-11.67 9.26A175.86 175.86 0 0 1 255.83 432z"
/>
</svg>
</button>
</div>
</div>
</div>
<div
class="pf-c-toolbar__expandable-content"
id="custom-dashboard-list-with-filter-expandable-content-1"
>
<div
class="pf-c-toolbar__group"
/>
</div>
</div>
<div
class="pf-c-toolbar__content pf-m-hidden"
hidden=""
>
<div
aria-hidden="true"
class="pf-c-toolbar__group pf-m-hidden"
hidden=""
/>
</div>
</div>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import React from 'react';
import CustomDashboardsGallery from '../CustomDashboardsGallery';
import { mount } from 'enzyme';
import { render, screen } from '@testing-library/react';
import {
customDashboardInfos,
MockedCustomDashboardListDriver
Expand All @@ -28,59 +28,43 @@ const MockedComponent = (): React.ReactElement => {
return <></>;
};

jest.mock(
'@kogito-apps/components-common/dist/components/KogitoEmptyState',
() =>
Object.assign({}, jest.requireActual('@kogito-apps/components-common'), {
KogitoEmptyState: () => {
return <MockedComponent />;
}
})
);

jest.mock('@kogito-apps/components-common/dist/components/KogitoSpinner', () =>
Object.assign({}, jest.requireActual('@kogito-apps/components-common'), {
KogitoSpinner: () => {
return <MockedComponent />;
}
})
);

describe('customDashboard gallery tests', () => {
Date.now = jest.fn(() => 1487076708000);
const driver = new MockedCustomDashboardListDriver();
it('renders gallery of customDashboard', () => {
const wrapper = mount(
const { container } = render(
<CustomDashboardsGallery
driver={driver}
isLoading={false}
customDashboardsDatas={customDashboardInfos}
/>
);
expect(wrapper).toMatchSnapshot();
expect(container).toMatchSnapshot();
});

it('renders loading component', () => {
const wrapper = mount(
const { container } = render(
<CustomDashboardsGallery
driver={driver}
isLoading={true}
customDashboardsDatas={customDashboardInfos}
/>
);
expect(wrapper).toMatchSnapshot();
expect(wrapper.find(KogitoSpinner)).toBeTruthy();
expect(container).toMatchSnapshot();
const checkLoading = screen.getByText('Loading customDashboard...');
expect(checkLoading).toBeTruthy();
});

it('renders empty state component', () => {
const wrapper = mount(
const { container } = render(
<CustomDashboardsGallery
driver={driver}
isLoading={false}
customDashboardsDatas={[]}
/>
);
expect(wrapper).toMatchSnapshot();
expect(wrapper.find(KogitoEmptyState)).toBeTruthy();
expect(container).toMatchSnapshot();
const checkEmptyState = screen.getByText('No results found');
expect(checkEmptyState).toBeTruthy();
});
});
Loading

0 comments on commit 914e001

Please sign in to comment.