Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] Component test cases for Services #195

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
3a0e350
fix for grouping fields
davedekker Sep 10, 2021
7fc2203
fix for orphaned labels
davedekker Sep 10, 2021
13d369c
fix contrast issue
davedekker Sep 10, 2021
8afb78c
add submit button for accessibility but hide and disable
davedekker Sep 10, 2021
e4b4659
add aria label to dropdown button
davedekker Sep 10, 2021
e20ffcb
update plain markkup with button component
davedekker Sep 10, 2021
8835ab4
Merge pull request #1 from atlanticbt/feature/GPTEINFRA-1601-compliance
davedekker Sep 10, 2021
4a99fe9
Merge branch 'main' of github.com:redhat-cop/babylon
davedekker Sep 11, 2021
a5be84a
Merge branch 'redhat-cop:main' into main
davedekker Sep 11, 2021
d0d7d53
Merge branch 'main' of github.com:atlanticbt/babylon
davedekker Sep 11, 2021
91e5665
fix aria-controls for category tabs
davedekker Sep 14, 2021
e4bd64f
fix contrast error for disbled submit button
davedekker Sep 14, 2021
08fa02e
Merge pull request #2 from atlanticbt/feature/GPTEINFRA-1601-compliance
davedekker Sep 14, 2021
d370f4f
Merge branch 'redhat-cop:main' into main
davedekker Sep 15, 2021
df8a962
Merge branch 'redhat-cop:main' into main
davedekker Sep 17, 2021
6648873
replace react-axe with @axe-core/react
davedekker Sep 17, 2021
5de7167
buid(webpack): add fallback.crypto, fallback.stream in webpack.commmo…
prabalabt Sep 19, 2021
94597b8
test: a add scenario for catalogue page
prabalabt Sep 20, 2021
b56f68d
Merge branch 'redhat-cop:main' into main
davedekker Sep 21, 2021
e2c0e87
Merge branch 'redhat-cop:main' into main
davedekker Sep 22, 2021
c609e34
fix: typeScript errors
prabalabt Sep 24, 2021
6ce5cfd
fixed typescript errors
prabalabt Sep 24, 2021
4ee9755
Merge branch 'feature/0002' of https://github.com/atlanticbt/babylon …
prabalabt Sep 24, 2021
58402c0
refactor: fix conlficts
prabalabt Sep 27, 2021
58f5f71
test: change spec.jsx to spec.tsx, add test-util replace testing-libr…
prabalabt Sep 28, 2021
24d22a4
fix: typescript errors
prabalabt Sep 28, 2021
aeb12da
Merge branch 'feature/GPTEINFRA-1637' of https://github.com/atlanticb…
prabalabt Sep 28, 2021
961dc40
test cases for ServicesItemDeleteModal
prabalabt Sep 28, 2021
1ad7b92
Merge branch 'feature/GPTEINFRA-1637' of https://github.com/atlanticb…
prabalabt Sep 28, 2021
9e54bee
fix: typescript errors
prabalabt Sep 28, 2021
770f181
Merge branch 'redhat-cop:main' into main
davedekker Sep 28, 2021
9df1990
test cases for DeleteButton ServiceItemStartModal serviceItemStopModa…
prabalabt Sep 29, 2021
d50121b
Merge branch 'redhat-cop:main' into main
davedekker Sep 29, 2021
00b5867
changes in test files extension
prabalabt Sep 30, 2021
be78355
Merge branch 'redhat-cop:main' into main
davedekker Oct 1, 2021
a9f884c
Test Cases for Services OpenStackConsole ServicesItemScheduleActionMo…
prabalabt Oct 4, 2021
15890d1
changes done
prabalabt Oct 4, 2021
74b5ce1
Merge branch 'redhat-cop:main' into main
davedekker Oct 5, 2021
2715ac1
Merge branch 'main' of https://github.com/atlanticbt/babylon into fea…
prabalabt Oct 6, 2021
f730fc9
test cases for ServicesStatus and ServiceItem
prabalabt Oct 6, 2021
5693d49
changes done
prabalabt Oct 6, 2021
643da3e
Merge remote-tracking branch 'upstream/main' into feature/GPTEINFRA-1637
prabalabt Oct 6, 2021
96a315c
merge done
prabalabt Oct 6, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion catalog/ui/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module.exports = {
}
},
verbose: true,

// Automatically clear mock calls and instances between every test
clearMocks: true,

Expand Down
2 changes: 2 additions & 0 deletions catalog/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.1.0",
"@reduxjs/toolkit": "^1.6.1",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.1.0",
"@types/react-redux": "^7.1.18",
"asciidoctor": "^2.2.5",
"classnames": "^2.3.1",
Expand Down
Empty file.
11 changes: 11 additions & 0 deletions catalog/ui/src/app/Catalog/Catalog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ const Catalog: React.FunctionComponent<CatalogProps> = ({
}
}

function creationTimestamp(catalogItem: { status: { creationTimestamp: any; }; metadata: { creationTimestamp: any; }; }) {
const ts = catalogItem.status && catalogItem.status.creationTimestamp ? catalogItem.status.creationTimestamp : catalogItem.metadata.creationTimestamp;
return (<LocalTimestamp timestamp={ts}/>);
}

function updateTimestamp(catalogItem: { status: { updateTimestamp: any; }; metadata: { creationTimestamp: any; }; }) {
const ts = catalogItem.status && catalogItem.status.updateTimestamp ? catalogItem.status.updateTimestamp : catalogItem.metadata.creationTimestamp;
return (<LocalTimestamp timestamp={ts}/>);
}

function description(catalogItem, options={}): string {
if (catalogItem.metadata?.annotations?.['babylon.gpte.redhat.com/description']) {
options['format'] = catalogItem.metadata.annotations?.['babylon.gpte.redhat.com/descriptionFormat'] || 'asciidoc';
Expand Down Expand Up @@ -161,6 +171,7 @@ const Catalog: React.FunctionComponent<CatalogProps> = ({
catalogItem: selectedCatalogItem,
catalogNamespace: catalogItemNamespace,
});
console.log("createServiceRequest", resourceClaim);;
history.push(`/services/ns/${resourceClaim.metadata.namespace}/item/${resourceClaim.metadata.name}`);
}
}
Expand Down
27 changes: 27 additions & 0 deletions catalog/ui/src/app/Services/DeleteButton.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// jest.mock('../api');
import "@testing-library/jest-dom";

import React from "react";
import { render, waitFor, queryByAttribute, fireEvent, screen, cleanup } from "@testing-library/react";
import { Provider } from 'react-redux';
import user from "@testing-library/user-event"

import {DeleteButton} from "./DeleteButton"
import { BrowserRouter as Router } from 'react-router-dom';
// import { getApiSession, listClusterCustomObject } from "@app/api";
import { store } from '@app/store';

const getById = queryByAttribute.bind(null, 'id');

// test.afterEach(cleanup)

describe("DeleteButton", () => {
test("When DeleteButton layout renders, should display Delete Button", async () => {
const onClick = jest.fn();
const { getByText, debug } =
render(<DeleteButton onClick={onClick}/>);

const testVar = getByText("Delete");
await waitFor(() => expect(testVar).toBeInTheDocument());
});
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// jest.mock('../api');
import "@testing-library/jest-dom";

import React from "react";
import { render, waitFor, queryByAttribute, fireEvent, screen, cleanup } from "@testing-library/react";
import { Provider } from 'react-redux';
// import user from "@testing-library/user-event";

import {ServicesItemDeleteModal} from "./ServicesItemDeleteModal"
import { BrowserRouter as Router } from 'react-router-dom';
// import { getApiSession, listClusterCustomObject } from "@app/api";
import { store } from '@app/store';

const getById = queryByAttribute.bind(null, 'id');

// test.afterEach(cleanup)

describe("ServicesItemDeleteModal", () => {
test("When ServicesItemDeleteModal layout renders, should display 'Confirm' option", async () => {
const closeModal = jest.fn();
const handleDelete = jest.fn();
const { getByText, debug } =
render(<ServicesItemDeleteModal key="delete"
isOpen={true}
onClose={closeModal}
onConfirm={handleDelete}
resourceClaim= {"ServiceCatalogName"}/>
);

const testVar = getByText("Confirm");
await waitFor(() => expect(testVar).toBeInTheDocument());
});

test("When ServicesItemDeleteModal layout renders, should display 'Cancle' option", async () => {
const closeModal = jest.fn();
const handleDelete = jest.fn();
const { getByText, debug } =
render(<ServicesItemDeleteModal key="delete"
isOpen={true}
onClose={closeModal}
onConfirm={handleDelete}
resourceClaim= {"ServiceCatalogName"}/>
);

const testVar = getByText("Cancel");
await waitFor(() => expect(testVar).toBeInTheDocument());
});

test("When ServicesItemDeleteModal layout renders, should display 'Delete ServiceName?' option", async () => {
const closeModal = jest.fn();
const handleDelete = jest.fn();
const catalogItemDisplayName = "Service";
const { getByText, debug } =
render(<ServicesItemDeleteModal key="delete"
isOpen={true}
onClose={closeModal}
onConfirm={handleDelete}
resourceClaim= {"ServiceCatalogName"}/>
);

const testVar = getByText(`Delete ${catalogItemDisplayName}?`);
await waitFor(() => expect(testVar).toBeInTheDocument());
});

test("When ServicesItemDeleteModal layout renders, should Confirm button click once", async () => {
const closeModal = jest.fn();
const handleDelete = jest.fn();

const { getByText, debug } = render(<ServicesItemDeleteModal key="delete"
isOpen={true}
onClose={closeModal}
onConfirm={handleDelete}
resourceClaim={"ServiceCatalogName"}/>
);
const button = screen.getByText("Confirm");
fireEvent.click(button);
await waitFor(() => expect(handleDelete).toBeCalledTimes(1));
});

test("When ServicesItemDeleteModal layout renders, should Cancle button click once", async () => {
const closeModal = jest.fn();
const handleDelete = jest.fn();

const { getByText, debug } = render(<ServicesItemDeleteModal key="delete"
isOpen={true}
onClose={closeModal}
onConfirm={handleDelete}
resourceClaim={"ServiceCatalogName"}/>
);
const button = screen.getByText("Cancel");
fireEvent.click(button);
await waitFor(() => expect(closeModal).toBeCalledTimes(1));
});
})
46 changes: 46 additions & 0 deletions catalog/ui/src/app/Services/Item/OpenStackConsole.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// jest.mock('../api');
import "@testing-library/jest-dom";

import React from "react";
import { render, waitFor, queryByAttribute, fireEvent, screen, cleanup } from "@testing-library/react";
import { Provider } from 'react-redux';
import user from "@testing-library/user-event"

import {OpenStackConsole} from "./OpenStackConsole"
import { BrowserRouter as Router } from 'react-router-dom';
// import { getApiSession, listClusterCustomObject } from "@app/api";
import { store } from '@app/store';

const getById = queryByAttribute.bind(null, 'id');

// test.afterEach(cleanup)

describe("OpenStackConsole", () => {
test("When OpenStackConsole layout renders, should display 'start' option", async () => {
const { getByText, debug } =
render(<OpenStackConsole
resourceClaim= {"A Practical Introduction to Container Security"}/>
);
const testVar = getByText("Start");
await waitFor(() => expect(testVar).toBeInTheDocument());
});

test("When OpenStackConsole layout renders, should display 'Reconnect' option", async () => {
const { getByText, debug } =
render(<OpenStackConsole
resourceClaim= {"A Practical Introduction to Container Security"}/>
);
const testVar = getByText("Reconnect");
await waitFor(() => expect(testVar).toBeInTheDocument());
});

test("When OpenStackConsole layout renders, should display 'Reboot' option", async () => {
const { getByText, debug } =
render(<OpenStackConsole
resourceClaim= {"A Practical Introduction to Container Security"}/>
);
const testVar = getByText("Reboot");
await waitFor(() => expect(testVar).toBeInTheDocument());
});

})
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// jest.mock('../api');
import "@testing-library/jest-dom";

import React from "react";
import { render, waitFor, queryByAttribute, fireEvent, screen, cleanup } from "@testing-library/react";
import { Provider } from 'react-redux';
import user from "@testing-library/user-event"

import {ServicesItemStartModal} from "./ServicesItemStartModal"
import { BrowserRouter as Router } from 'react-router-dom';
// import { getApiSession, listClusterCustomObject } from "@app/api";
import { store } from '@app/store';

const getById = queryByAttribute.bind(null, 'id');

// test.afterEach(cleanup)

describe("ServicesItemStartModal", () => {
test("When ServicesItemStartModal layout renders, should display 'Confirm' option", async () => {
const closeModal = jest.fn();
const handleStart = jest.fn();
const { getByText, debug } =
render(<ServicesItemStartModal key="start"
isOpen={true}
onClose={closeModal}
onConfirm={handleStart}
resourceClaim= {"ServiceCatalogName"}/>
);

const testVar = getByText("Confirm");
await waitFor(() => expect(testVar).toBeInTheDocument());
});

test("When ServicesItemStartModal layout renders, should display 'Cancle' option", async () => {
const closeModal = jest.fn();
const handleStart = jest.fn();
const { getByText, debug } =
render(<ServicesItemStartModal key="start"
isOpen={true}
onClose={closeModal}
onConfirm={handleStart}
resourceClaim= {"ServiceCatalogName"}/>
);

const testVar = getByText("Cancel");
await waitFor(() => expect(testVar).toBeInTheDocument());
});

test("When ServicesItemStartModal layout renders, should display 'Start Service?' option", async () => {
const closeModal = jest.fn();
const handleStart = jest.fn();
const catalogItemDisplayName = "Service";
const { getByText, debug } =
render(<ServicesItemStartModal key="start"
isOpen={true}
onClose={closeModal}
onConfirm={handleStart}
resourceClaim= {"ServiceCatalogName"}/>
);

const testVar = getByText(`Start ${catalogItemDisplayName}?`);
await waitFor(() => expect(testVar).toBeInTheDocument());
});

test("When ServicesItemStartModal layout renders, should Confirm button click once", async () => {
const closeModal = jest.fn();
const handleStart = jest.fn();

const { getByText, debug } = render(<ServicesItemStartModal key="start"
isOpen={true}
onClose={closeModal}
onConfirm={handleStart}
resourceClaim={"ServiceCatalogName"}/>
);
const button = screen.getByText("Confirm");
fireEvent.click(button);
await waitFor(() => expect(handleStart).toBeCalledTimes(1));
});

test("When ServicesItemStartModal layout renders, should Cancle button click once", async () => {
const closeModal = jest.fn();
const handleStart = jest.fn();

const { getByText, debug } = render(<ServicesItemStartModal key="start"
isOpen={true}
onClose={closeModal}
onConfirm={handleStart}
resourceClaim={"ServiceCatalogName"}/>
);
const button = screen.getByText("Cancel");
fireEvent.click(button);
await waitFor(() => expect(closeModal).toBeCalledTimes(1));
});


// test.only("When ServicesItemStartModal layout renders, should display selected service will stop in ", async () => {
// const closeModal = jest.fn();
// const handleStart = jest.fn();

// const { getByText, debug } = render(<ServicesItemStartModal key="start"
// isOpen={"true"}
// onClose={closeModal}
// onConfirm={handleStart}
// resourceClaim={"ServiceCatalogName"}>
// service will stop in
// {/* <TimeInterval interval={defaultRuntime} />. */}
// </ServicesItemStartModal>
// );

// const testVar = getByText(`service will stop in`);
// await waitFor(() => expect(testVar).toBeInTheDocument());
// });
})
Loading