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

Update unit tests and related configurations #5716

Merged
merged 10 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions .github/workflows/pr-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ jobs:

test:
name: 👾 Unit Test (TESTING)
if: ${{ false }} # disable temporarily (https://github.com/wso2/product-is/issues/16619)
# needs: [ lint, typecheck ]
needs: [ lint, typecheck ]
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
27 changes: 12 additions & 15 deletions apps/console/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
* Copyright (c) 2020-2024, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand All @@ -18,11 +18,6 @@

module.exports = {
displayName: "console",
globals: {
"ts-jest": {
tsconfig: "<rootDir>/tsconfig.json"
}
},
moduleDirectories: [
"node_modules",
"test-configs",
Expand All @@ -37,19 +32,19 @@ module.exports = {
"node"
],
moduleNameMapper: {
"@oxygen-ui/react": "<rootDir>/node_modules/@oxygen-ui/react",
"@wso2is/common": "<rootDir>/../../modules/common/dist",
"@wso2is/dynamic-forms": "<rootDir>/../../modules/dynamic-forms/dist",
"@wso2is/form": "<rootDir>/../../modules/form/dist",
"@wso2is/forms": "<rootDir>/../../modules/forms/dist",
"@wso2is/react-components": "<rootDir>/../../modules/react-components/dist",
"\\.(css|less|scss)$": "<rootDir>/test-configs/__mocks__/style-file.ts",
"\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|md)$":
"<rootDir>/test-configs/__mocks__/file.ts",
"\\.svg": "<rootDir>/test-configs/__mocks__/svgr.ts",
"^@unit-testing(.*)$": "<rootDir>/test-configs/utils",
"^lodash-es/(.*)$": "<rootDir>/../../node_modules/lodash/$1",
"^react($|/.+)": "<rootDir>/node_modules/react$1",
"@wso2is/form": "<rootDir>/../../modules/form/dist",
"@wso2is/forms": "<rootDir>/../../modules/forms/dist",
"@wso2is/common": "<rootDir>/../../modules/common/dist",
"@wso2is/dynamic-forms": "<rootDir>/../../modules/dynamic-forms/dist",
"@wso2is/react-components": "<rootDir>/../../modules/react-components/dist",
"@oxygen-ui/react": "<rootDir>/node_modules/@oxygen-ui/react"
"uuid": "<rootDir>/node_modules/uuid"
},
modulePaths: [
"<rootDir>"
Expand All @@ -69,11 +64,13 @@ module.exports = {
],
transform: {
"^.+\\.(js|jsx)?$": "babel-jest",
"^.+\\.(ts|tsx)?$": "ts-jest"
"^.+\\.(ts|tsx)?$": [ "ts-jest", {
tsconfig: "<rootDir>/tsconfig.json"
} ]
},
transformIgnorePatterns: [
"/node_modules/?(?!@wso2is)",
"/node_modules/(?!@oxygen-ui/react/)"
],
verbose: true,
verbose: true
};
19 changes: 10 additions & 9 deletions apps/console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@
"devDependencies": {
"@pmmmwh/react-refresh-webpack-plugin": "^0.4.3",
"@svgr/webpack": "4.3.2",
"@testing-library/dom": "^7.24.3",
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/user-event": "^12.7.3",
"@testing-library/dom": "^9.3.4",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^14.2.1",
"@testing-library/user-event": "^14.5.2",
"@types/file-saver": "^2.0.1",
"@types/history": "^4.7.3",
"@types/jest": "^26.0.14",
"@types/jest": "^29.5.12",
"@types/lodash-es": "^4.17.4",
"@types/node": "^13.9.2",
"@types/node-forge": "^0.9.3",
Expand Down Expand Up @@ -139,18 +140,18 @@
"eslint-plugin-testing-library": "^5.0.5",
"eslint-webpack-plugin": "^2.5.3",
"fork-ts-checker-webpack-plugin": "^6.1.0",
"jest": "^26.4.2",
"jest-environment-jsdom": "^26.3.0",
"jest-environment-jsdom-global": "^2.0.4",
"json-minimizer-webpack-plugin": "^4.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-environment-jsdom-global": "^4.0.0",
"json-minimizer-webpack-plugin": "^5.0.0",
"msw": "^0.36.8",
"process": "^0.11.10",
"react-refresh": "^0.9.0",
"redux-devtools-extension": "^2.13.8",
"rimraf": "^3.0.2",
"style-loader": "^0.23.1",
"thread-loader": "^2.1.3",
"ts-jest": "^26.4.0",
"ts-jest": "^29.1.2",
"ts-node": "^10.8.1",
"typescript": "^4.6.4"
},
Expand Down
14 changes: 7 additions & 7 deletions apps/console/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@
import { StaticContext } from "react-router";
import { Redirect, Route, RouteComponentProps, Router, Switch } from "react-router-dom";
import { Dispatch } from "redux";
import { commonConfig } from "@wso2is/features/admin.extensions.v1";

Check warning on line 49 in apps/console/src/app.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

`@wso2is/features/admin.extensions.v1` import should occur before import of `@wso2is/i18n`
import { useGetAllFeatures } from "@wso2is/features/admin.extensions.v1/components/feature-gate/api/feature-gate";

Check warning on line 50 in apps/console/src/app.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

`@wso2is/features/admin.extensions.v1/components/feature-gate/api/feature-gate` import should occur before import of `@wso2is/i18n`
import { featureGateConfig } from "@wso2is/features/admin.extensions.v1/configs/feature-gate";

Check warning on line 51 in apps/console/src/app.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

`@wso2is/features/admin.extensions.v1/configs/feature-gate` import should occur before import of `@wso2is/i18n`
import { AccessControlUtils } from "@wso2is/features/admin.access-control.v1/configs/access-control";

Check warning on line 52 in apps/console/src/app.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

`@wso2is/features/admin.access-control.v1/configs/access-control` import should occur before import of `@wso2is/i18n`
import { EventPublisher, PreLoader } from "@wso2is/features/admin.core.v1";

Check warning on line 53 in apps/console/src/app.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

`@wso2is/features/admin.core.v1` import should occur before import of `@wso2is/i18n`
import { ProtectedRoute } from "@wso2is/features/admin.core.v1/components";

Check warning on line 54 in apps/console/src/app.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

`@wso2is/features/admin.core.v1/components` import should occur before import of `@wso2is/i18n`
import { Config, DocumentationLinks, getBaseRoutes } from "@wso2is/features/admin.core.v1/configs";

Check warning on line 55 in apps/console/src/app.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

`@wso2is/features/admin.core.v1/configs` import should occur before import of `@wso2is/i18n`
import { AppConstants } from "@wso2is/features/admin.core.v1/constants";

Check warning on line 56 in apps/console/src/app.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

`@wso2is/features/admin.core.v1/constants` import should occur before import of `@wso2is/i18n`
import { history } from "@wso2is/features/admin.core.v1/helpers";

Check warning on line 57 in apps/console/src/app.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

`@wso2is/features/admin.core.v1/helpers` import should occur before import of `@wso2is/i18n`
import {

Check warning on line 58 in apps/console/src/app.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

`@wso2is/features/admin.core.v1/models` import should occur before import of `@wso2is/i18n`
ConfigReducerStateInterface,
DocumentationLinksInterface,
FeatureConfigInterface,
Expand Down Expand Up @@ -94,12 +94,12 @@
const [ baseRoutes, setBaseRoutes ] = useState<RouteInterface[]>(getBaseRoutes());
const [ sessionTimedOut, setSessionTimedOut ] = useState<boolean>(false);
const [ orgId, setOrgId ] = useState<string>();
const [ featureGateConfigData, setFeatureGateConfigData ] =
const [ featureGateConfigData, setFeatureGateConfigData ] =
useState<FeatureGateInterface | null>(featureGateConfigUpdated);

const {
const {
data: allFeatures,
error: featureGateAPIException
error: featureGateAPIException
} = useGetAllFeatures(orgId, state.isAuthenticated);

useEffect(() => {
Expand Down Expand Up @@ -135,13 +135,13 @@
const path: string = feature.featureIdentifier.replace(/-/g, ".");
// Obtain the status and set it to the feature gate config.
const featureStatusPath: string = `${ path }.status`;

set(featureGateConfigUpdated,featureStatusPath, feature.featureStatus);

const featureTagPath: string = `${ path }.tags`;

set(featureGateConfigUpdated,featureTagPath, feature.featureTags);

setFeatureGateConfigData(featureGateConfigUpdated);
});
}
Expand Down
27 changes: 3 additions & 24 deletions apps/console/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
* under the License.
*/

import { AuthParams, AuthProvider, ResponseMode, SPAUtils } from "@asgardeo/auth-react";
import { AuthProvider } from "@asgardeo/auth-react";
import { ThemeProvider } from "@oxygen-ui/react/theme";
import { AppConfigProvider } from "@wso2is/common/src/providers/app-config-provider";
import { ContextUtils, StringUtils } from "@wso2is/core/utils";
import axios, { AxiosResponse } from "axios";
import { ContextUtils } from "@wso2is/core/utils";
import * as React from "react";
import { ReactElement } from "react";
import * as ReactDOM from "react-dom";
Expand All @@ -38,26 +37,6 @@ import { ProtectedApp } from "./protected-app";
// Set the runtime config in the context.
ContextUtils.setRuntimeConfig(Config.getDeploymentConfig());

const getAuthParams = (): Promise<AuthParams> => {
if (!SPAUtils.hasAuthSearchParamsInURL()
&& Config.getDeploymentConfig()?.idpConfigs?.responseMode === ResponseMode.formPost) {

const contextPath: string = window[ "AppUtils" ].getConfig().appBase
? `/${ StringUtils.removeSlashesFromPath(window[ "AppUtils" ].getConfig().appBase) }`
: "";

return axios.get(contextPath + "/auth").then((response: AxiosResponse ) => {
return Promise.resolve({
authorizationCode: response?.data?.authCode,
sessionState: response?.data?.sessionState,
state: response?.data?.state
});
});
}

return;
};

/**
* Render root component with configs.
*
Expand Down Expand Up @@ -90,7 +69,7 @@ const RootWithConfig = (): ReactElement => {
<AuthProvider
config={ AuthenticateUtils.getInitializeConfig() }
fallback={ <PreLoader /> }
getAuthParams={ getAuthParams }
getAuthParams={ AuthenticateUtils.getAuthParams }
>
<AppConfigProvider>
<OrganizationsProvider>
Expand Down
34 changes: 34 additions & 0 deletions apps/console/test-configs/__mocks__/@asgardeo/auth-react/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright (c) 2022-2023, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { DecodedIDTokenPayload } from "@asgardeo/auth-react";

export default {
getDecodedIDToken: (): Promise<DecodedIDTokenPayload> => {
return new Promise((resolve, reject) => {
resolve({
aud: "",
sub: "",
iss: "",
email: "",
preferred_username: "",
tenant_domain: "",
})
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ const ReduxStoreStateMock = {
structureFileType: "YAML",
structureFileURL: "https://api.github.com/repos/wso2/docs-is/contents/en/mkdocs.yml"
},
extensions: {
asgardeoTryItURL: ""
},
idpConfigs: {
serverOrigin: "https://localhost:9443",
enablePKCE: true,
Expand Down
10 changes: 9 additions & 1 deletion apps/console/test-configs/__mocks__/window/app-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
*/

interface CustomWindow extends Window {
AppUtils: {
AppUtils: {
getConfig: () => any;
getOrganizationPath: () => string;
getOrganizationType: () => string;
};
}

Expand Down Expand Up @@ -481,6 +483,12 @@ interface CustomWindow extends Window {
}
}
};
},
getOrganizationPath: function () {
return "";
},
getOrganizationType: function () {
return "FIRST_LEVEL_ORGANIZATION";
}
/* eslint-disable sort-keys, max-len */
};
4 changes: 3 additions & 1 deletion apps/console/test-configs/__mocks__/window/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2022, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
* Copyright (c) 2022, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand All @@ -16,6 +16,8 @@
* under the License.
*/

jest.mock("./worker.ts");

import "./app-utils";
import "./document";
import "./worker";
45 changes: 33 additions & 12 deletions apps/console/test-configs/__mocks__/window/worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
* Copyright (c) 2020-2024, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand All @@ -17,8 +17,6 @@
*/

/**
* @fileoverview Worker API Mocks.
*
* @remarks If you had to mock a certain Worker API,
* document the reason and any references clearly in this file.
*/
Expand All @@ -31,20 +29,43 @@
* Mock Reference @see {@link https://github.com/facebook/jest/issues/3449#issuecomment-347337666}
*/
class WorkerMock {
constructor(stringUrl) {
// @ts-ignore
private url: string | URL;

constructor(stringUrl: string | URL) {
this.url = stringUrl;
// @ts-ignore
this.onmessage = () => { };
}

postMessage(msg) {
// @ts-ignore
onmessage(this: Worker, _ev: MessageEvent<any>){
return "";
}

postMessage(msg: MessageEvent<any>) {
this.onmessage(msg);
}

onmessageerror(this: Worker, _ev: MessageEvent<any>) {
return "";
}

terminate() {

}

addEventListener() {

}

removeEventListener() {

}

dispatchEvent() {
return true;
}

onerror() {

}
}

// @ts-ignore
window.Worker = WorkerMock;

/* eslint-enable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-empty-function */
3 changes: 1 addition & 2 deletions apps/console/test-configs/setup-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
* Copyright (c) 2020, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand All @@ -17,7 +17,6 @@
*/

import { configure } from "@testing-library/react";
import "@testing-library/jest-dom/extend-expect";
import "./__mocks__/global";
import "./__mocks__/module";
import "./__mocks__/window";
Expand Down
Loading
Loading