Skip to content

Commit

Permalink
update aap_31381
Browse files Browse the repository at this point in the history
  • Loading branch information
justjais committed Nov 22, 2024
1 parent 3e68a7d commit 1fc5f5e
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 60 deletions.
98 changes: 61 additions & 37 deletions ansible_ai_connect_admin_portal/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions ansible_ai_connect_admin_portal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"i18next-http-backend": "^2.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^13.1.2",
"react-router-dom": "^6.15.0"
"react-i18next": "^13.1.2"
},
"devDependencies": {
"@testing-library/jest-dom": "^6.1.4",
Expand Down Expand Up @@ -82,7 +81,9 @@
"webpack-dev-server": "^4.6.0",
"webpack-manifest-plugin": "^4.0.2",
"webpack-mock-server": "^1.0.18",
"workbox-webpack-plugin": "^6.4.1"
"workbox-webpack-plugin": "^6.4.1",
"react-router-dom": "^6.28.0",
"identity-obj-proxy": "^3.0.0"
},
"scripts": {
"start": "node scripts/start.js",
Expand Down Expand Up @@ -145,9 +146,8 @@
"moduleNameMapper": {
"^react-native$": "react-native-web",
"^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy",
"react-i18next": "<rootDir>/__mocks__/react-i18next.ts"
},
"module.exports": {
"react-i18next": "<rootDir>/__mocks__/react-i18next.ts",
"\\.(css|less|scss|sass)$": "identity-obj-proxy",
"monaco-editor": "<rootDir>/__mocks__/monaco-editor.ts",
"monaco-yaml": "<rootDir>/__mocks__/monaco-yaml.ts"
},
Expand Down
4 changes: 2 additions & 2 deletions ansible_ai_connect_admin_portal/src/PageMastheadDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function PageMastheadDropdown(props: PageMastheadDropdownProps) {
id={id}
onSelect={onSelect}
toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
<MenuToggle ref={toggleRef} onClick={onToggle} isExpanded={isOpen}>
<MenuToggle ref={toggleRef} onClick={onToggle} isExpanded={isOpen} data-testid="page-masthead-dropdown__button">
<Flex
alignItems={{ default: "alignItemsCenter" }}
flexWrap={{ default: "nowrap" }}
Expand All @@ -46,7 +46,7 @@ export function PageMastheadDropdown(props: PageMastheadDropdownProps) {
isOpen={open}
isPlain
data-cy={id}
data-testid="page-masthead-dropdown"
data-testid="page-masthead-dropdown__button"
>
<DropdownList>
<DropdownItem>{_children}</DropdownItem>
Expand Down
2 changes: 1 addition & 1 deletion ansible_ai_connect_admin_portal/src/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("App", () => {
adminDashboardUrl={"http://admin_dashboard-url/"}
/>,
);
const accountMenu = await screen.findByTestId("page-masthead-dropdown");
const accountMenu = await screen.findByTestId("page-masthead-dropdown__button");
expect(accountMenu).toBeInTheDocument();
expect(accountMenu).toHaveTextContent("Batman");
});
Expand Down
40 changes: 28 additions & 12 deletions ansible_ai_connect_admin_portal/src/__tests__/AppHeader.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { render, screen } from "@testing-library/react";
import { render, screen, waitFor } from "@testing-library/react";

Check warning on line 1 in ansible_ai_connect_admin_portal/src/__tests__/AppHeader.test.tsx

View workflow job for this annotation

GitHub Actions / lint

'waitFor' is defined but never used
import "@testing-library/jest-dom";
import { AppHeader } from "../AppHeader";
import userEvent from "@testing-library/user-event";
import { BrowserRouter } from 'react-router-dom';
import { act } from 'react';

describe("AppHeader", () => {
// Store the original 'location' object so that it can be restored for other tests.
Expand All @@ -20,26 +22,40 @@ describe("AppHeader", () => {
});

it("Rendering", async () => {
render(<AppHeader userName={"Batman"} />);
const accountMenu = await screen.findByTestId("page-masthead-dropdown");
render(
<BrowserRouter>
<AppHeader userName={"Batman"} />
</BrowserRouter>
);
const accountMenu = await screen.findByTestId("page-masthead-dropdown__button");
expect(accountMenu).toBeInTheDocument();
expect(accountMenu).toHaveTextContent("Batman");

// Check "Logout" option is not present
expect(screen.queryByText("Logout")).toBeNull();

// Emulate click on menu button
const accountMenuToggle = await screen.findByTestId(
"page-masthead-dropdown__button",
);
await userEvent.click(accountMenuToggle);

const accountMenuToggle = await act(()=> {

Check failure on line 36 in ansible_ai_connect_admin_portal/src/__tests__/AppHeader.test.tsx

View workflow job for this annotation

GitHub Actions / lint

Avoid wrapping Testing Library util calls in `act`
screen.findByTestId(

Check failure on line 37 in ansible_ai_connect_admin_portal/src/__tests__/AppHeader.test.tsx

View workflow job for this annotation

GitHub Actions / lint

promise returned from `findByTestId` query must be handled
"page-masthead-dropdown__button",
);
});
// const accountMenuToggle = await screen.findByTestId(
// "page-masthead-dropdown__button",
// );
await act(() => {

Check failure on line 44 in ansible_ai_connect_admin_portal/src/__tests__/AppHeader.test.tsx

View workflow job for this annotation

GitHub Actions / lint

Avoid wrapping Testing Library util calls in `act`
userEvent.click(accountMenuToggle);
});
// await userEvent.click(accountMenuToggle);
// "Logout" menu option should now be present
expect(await screen.findByText("Logout")).toBeInTheDocument();

// Emulate clicking on the logout button
const logoutMenuItem = await screen.findByTestId("app-header__logout");
const logoutMenuItem = await act(() => {

Check failure on line 52 in ansible_ai_connect_admin_portal/src/__tests__/AppHeader.test.tsx

View workflow job for this annotation

GitHub Actions / lint

Avoid wrapping Testing Library util calls in `act`
screen.findByTestId("app-header__logout");

Check failure on line 53 in ansible_ai_connect_admin_portal/src/__tests__/AppHeader.test.tsx

View workflow job for this annotation

GitHub Actions / lint

promise returned from `findByTestId` query must be handled
});
// await act(() => {
// userEvent.click(logoutMenuItem);
// });
await userEvent.click(logoutMenuItem);
expect(window.location.assign).toBeCalledWith("/logout");
expect(window.location.assign).toHaveBeenCalledWith("/logout");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ describe("App", () => {
it("Rendering::With Username", async () => {
window.history.pushState({}, "Test page", "/console");
render(<AppDenied userName={"Batman"} hasSubscription={true} />);
const accountMenu = await screen.findByTestId("page-masthead-dropdown");
const accountMenu = await screen.findByTestId("page-masthead-dropdown__button");
expect(accountMenu).toBeInTheDocument();
expect(accountMenu).toHaveTextContent("Batman");
});

it("Rendering::Without Username", async () => {
window.history.pushState({}, "Test page", "/console");
render(<AppDenied hasSubscription={false} />);
const accountMenu = await screen.findByTestId("page-masthead-dropdown");
const accountMenu = await screen.findByTestId("page-masthead-dropdown__button");
expect(accountMenu).toBeInTheDocument();
expect(accountMenu).toHaveTextContent("UnknownUser");
});
Expand Down

0 comments on commit 1fc5f5e

Please sign in to comment.