Skip to content

Commit

Permalink
[ES-675] Added basic test case for claim-details component and some U…
Browse files Browse the repository at this point in the history
…I fixes. (#749)

Signed-off-by: GurukiranP <talk2gurukiran@gmail.com>
  • Loading branch information
gk-4VII authored Jun 5, 2024
1 parent 091b38d commit 5453db1
Show file tree
Hide file tree
Showing 7 changed files with 14,330 additions and 8,619 deletions.
22,870 changes: 14,258 additions & 8,612 deletions oidc-ui/package-lock.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions oidc-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@
]
},
"devDependencies": {
"@testing-library/jest-dom": "^6.4.5",
"@testing-library/react": "^16.0.0",
"autoprefixer": "^10.4.8",
"postcss": "^8.4.16",
"tailwindcss": "^3.1.8",
"tailwindcss-dir": "^4.0.0"
},
"jest": {
"moduleNameMapper": {
"^axios$": "axios/dist/node/axios.cjs"
}
}
}
11 changes: 11 additions & 0 deletions oidc-ui/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,17 @@ body {
}
}

.align-loading-center {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}

@media screen and (max-width: 768px) {
.section-background .top_left_bg_logo,
.section-background .top_right_bg_logo,
Expand Down
7 changes: 5 additions & 2 deletions oidc-ui/src/common/LoadingIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ const LoadingIndicator = ({
size,
msgParam,
i18nKeyPrefix = "loadingMsgs",
className,
}) => {
const { t } = useTranslation("translation", { keyPrefix: i18nKeyPrefix });

return (
<>
<div
role="status"
className="flex justify-center items-center loading-indicator"
className={
"flex justify-center items-center loading-indicator " + className
}
>
<svg
style={dynamicSize[size]}
Expand All @@ -54,7 +57,7 @@ const LoadingIndicator = ({
};

LoadingIndicator.defaultProps = {
size: "medium"
size: "medium",
};

export default LoadingIndicator;
14 changes: 10 additions & 4 deletions oidc-ui/src/components/ClaimDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ const ClaimDetails = ({
tooltip: createClaimsTooltip("voluntary"),
},
];

setClaimsScopes(claimsScopes);
if (!response?.profileUpdateRequired) {
window.onbeforeunload = null;
if (response?.consentAction === "CAPTURE") {
window.location.replace(new URL("/consent", window.location.href));
window.location.replace(
window.location.href.replace("claim-details", "consent")
);
} else if (response?.consentAction === "NOCAPTURE") {
const { response: authCodeResponse, errors: authCodeErrors } =
await authServices.post_AuthCode(transactionId, [], []);
Expand All @@ -147,6 +147,8 @@ const ClaimDetails = ({
);
}
}
} else {
setClaimsScopes(claimsScopes);
}
} catch (error) {
redirectOnError("authorization_failed_msg", error.message);
Expand Down Expand Up @@ -232,7 +234,11 @@ const ClaimDetails = ({
footerClassname="flex flex-shrink-0 flex-wrap items-center justify-center rounded-b-md p-4 my-4"
/>
) : claimsScopes.length === 0 || isLoading ? (
<LoadingIndicator size="medium" message={"loading_msg"} />
<LoadingIndicator
size="medium"
message={"loading_msg"}
className="align-loading-center"
/>
) : (
<>
<img
Expand Down
2 changes: 1 addition & 1 deletion oidc-ui/src/pages/PageNotFound.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function PageNotFoundPage({ i18nKeyPrefix = "errors" }) {
const { t } = useTranslation("translation", { keyPrefix: i18nKeyPrefix });

return (
<div className="multipurpose-login-card w-full m-16 shadow shadow-lg py-24">
<div className="multipurpose-login-card w-full m-0 sm:shadow sm:shadow-lg py-24 sm:m-16 section-background">
<img
className="mx-auto my-0"
src="images/under_construction.svg"
Expand Down
38 changes: 38 additions & 0 deletions oidc-ui/src/test/ClaimDetails.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from "react";
import ClaimDetails from "../components/ClaimDetails";
import { render } from "@testing-library/react";

const hash =
"#eyJ0cmFuc2FjdGlvbklkIjoiOGNXSFVUWHRaa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VwLmNvbmZpZyI6eyJzaWdudXAuYmFubmVyIjp0cnVlLCJzaWdudXAudXJsIjoiaHR0cDovL2xvY2FsaG9zdDozMDAwL3NpZ251cCJ9LCJmb3Jnb3QtcGFzc3dvcmQuY29uZmlnIjp7ImZvcmdvdC1wYXNzd29yZCI6dHJ1ZSwiZm9yZ290LXBhc3N3b3JkLnVybCI6Imh0dHA6Ly9sb2NhbGhvc3Q6MzAwMC9mb3Jnb3QtcGFzc3dvcmQifSwiZUtZQy1zdGVwcy5jb25maWciOiJodHRwOi8vbG9jYWxob3N0OjMwMDAvaWRlbnRpdHktdmVyaWZpY2F0aW9uIiwiZXJyb3IuYmFubmVyLmNsb3NlLXRpbWVyIjoxMCwiYXV0aC5mYWN0b3Iua2JhLmluZGl2aWR1YWwtaWQtZmllbGQiOiJwb2xpY3lOdW1iZXIiLCJhdXRoLmZhY3Rvci5rYmEuZmllbGQtZGV0YWlscyI6W119LCJyZWRpcmVjdFVyaSI6Imh0dHA6Ly9sb2NhbGhvc3Q6NTAwMC91c2VycHJvZmlsZSIsImNsaWVudE5hbWUiOnsiQG5vbmUiOiJIZWFsdGggc2VydmljZSJ9LCJjcmVkZW50aWFsU2NvcGVzIjpbXX0=";

const url =
"http://localhost:3000/claim-details?nonce=ere973eieljznge2311&state=eree2311&consentAction=CAPTURE&authenticationTime=1717572654" +
hash;

jest.mock("react-i18next", () => ({
// this mock makes sure any components using the translate hook can use it without a warning being shown
useTranslation: () => {
return {
t: (str) => str,
i18n: {
changeLanguage: () => new Promise(() => {}),
// You can include here any property your component may use
},
};
},
initReactI18next: {
type: "3rdParty",
init: () => {},
},
}));

describe("ClaimDetails Component", () => {
test("should render ClaimDetails component", async () => {
Object.defineProperty(window, "location", {
get() {
return { href: url };
},
});
render(<ClaimDetails />);
});
});

0 comments on commit 5453db1

Please sign in to comment.