Skip to content

Commit

Permalink
Merge pull request #32 from Orfium/feat/state-indicators
Browse files Browse the repository at this point in the history
  • Loading branch information
panvourtsis committed Oct 27, 2022
2 parents 58fcf21 + e305ee7 commit e4ba3ee
Show file tree
Hide file tree
Showing 21 changed files with 3,067 additions and 1,630 deletions.
103 changes: 54 additions & 49 deletions __mocks__/@auth0/auth0-spa-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,60 +32,65 @@ export const onRedirectCallback = jest.fn();
export const getTokenSilently = jest.fn();
export const loginWithRedirect = jest.fn();
export const getUser = jest.fn();
export const handleRedirectCallback = jest.fn();
export const handleRedirectCallback = jest.fn(() => {
return { appState: '' };
});
export const isAuthenticated = jest.fn();
export const logout = jest.fn();
export const loginWithPopup = jest.fn();

/*
* Mock auth0 client with predefined values
* All necessary functions are mocked jest.fn() that can be used to run tests internally.
*/
export default (options: any) => ({
getTokenSilently,
loginWithRedirect,
loginWithPopup,
getUser,
logout,
handleRedirectCallback,
isAuthenticated,
options: {
...options,
onRedirectCallback,
},
cacheLocation: 'localstorage',
httpTimeoutMs: 10000,
cookieStorage: {
get: jest.fn(),
save: jest.fn(),
remove: jest.fn(),
},
orgHintCookieName: 'auth0..organization_hint',
isAuthenticatedCookieName: 'auth0..is.authenticated',
sessionCheckExpiryDays: 1,
scope: 'offline_access',
transactionManager: {
storage: {
export const createAuth0 = jest.fn().mockImplementation((options: any) =>
Promise.resolve({
getTokenSilently,
loginWithRedirect,
loginWithPopup,
getUser,
logout,
handleRedirectCallback,
isAuthenticated,
options: {
...options,
onRedirectCallback,
},
cacheLocation: 'localstorage',
httpTimeoutMs: 10000,
cookieStorage: {
get: jest.fn(),
save: jest.fn(),
remove: jest.fn(),
},
clientId: '',
storageKey: 'a0.spajs.txs.',
transaction: null,
},
nowProvider: jest.fn(),
cacheManager: {
cache: {},
keyManifest: null,
orgHintCookieName: 'auth0..organization_hint',
isAuthenticatedCookieName: 'auth0..is.authenticated',
sessionCheckExpiryDays: 1,
scope: 'offline_access',
transactionManager: {
storage: {
get: jest.fn(),
save: jest.fn(),
remove: jest.fn(),
},
clientId: '',
storageKey: 'a0.spajs.txs.',
transaction: null,
},
nowProvider: jest.fn(),
},
domainUrl: 'https://',
tokenIssuer: 'https:///',
defaultScope: 'openid profile email',
customOptions: {
onRedirectCallback,
organization: undefined,
},
useRefreshTokensFallback: true,
});
cacheManager: {
cache: {},
keyManifest: null,
nowProvider: jest.fn(),
},
domainUrl: 'https://',
tokenIssuer: 'https:///',
defaultScope: 'openid profile email',
customOptions: {
onRedirectCallback,
organization: undefined,
},
useRefreshTokensFallback: true,
})
);

/*
* Mock auth0 client with predefined values
* All necessary functions are mocked jest.fn() that can be used to run tests internally.
*/
export default createAuth0;
10 changes: 10 additions & 0 deletions __mocks__/fileMock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';

// eslint-disable-next-line react/display-name
const SvgrMock = React.forwardRef((props, ref) => {
// @ts-ignore
return <span ref={ref} {...props} />;
});

export const ReactComponent = SvgrMock;
export default SvgrMock;
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ module.exports = {
setupFilesAfterEnv: [`<rootDir>/setup-jest.ts`],
collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/**/*.stories.{ts,tsx,js,jsx,mdx,md}'],
coveragePathIgnorePatterns: ['/node_modules/', '/test/', '/documentation/'],
testResultsProcessor: 'jest-sonar-reporter',
};
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"license": "MIT",
"dependencies": {
"@auth0/auth0-spa-js": "^1.22.2",
"@emotion/react": "^11.10.4",
"@emotion/styled": "^11.10.4",
"axios": "^0.21.4",
"axios-mock-adapter": "^1.19.0",
"jwt-decode": "^3.1.2",
Expand All @@ -22,6 +24,7 @@
"@rollup/plugin-typescript": "^8.3.2",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@svgr/rollup": "^6.5.0",
"@testing-library/jest-dom": "^5.16.3",
"@testing-library/react": "^13.0.0",
"@testing-library/react-hooks": "^7.0.2",
Expand All @@ -35,20 +38,22 @@
"axios": "^0.26.1",
"axios-mock-adapter": "^1.20.0",
"cross-env": "^7.0.3",
"eslint": "^8.15.0",
"eslint": "8.22.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.5.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.31.10",
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^8.0.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^27.5.1",
"jest-sonar-reporter": "^2.0.0",
"jwt-encode": "^1.0.1",
"lint-staged": "^12.4.1",
"prettier": "^2.6.2",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-error-boundary": "^3.1.4",
"react-query": "^3.22.0",
"rimraf": "^3.0.2",
"rollup": "^2.72.0",
Expand Down
3 changes: 2 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import svgr from '@svgr/rollup';
import dts from 'rollup-plugin-dts';
import external from 'rollup-plugin-peer-deps-external';
import { terser } from 'rollup-plugin-terser';
Expand All @@ -20,7 +21,7 @@ export default [
},
],
external: [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})],
plugins: [external(), resolve(), typescript({ tsconfig: './tsconfig.json' }), terser()],
plugins: [external(), resolve(), typescript({ tsconfig: './tsconfig.json' }), svgr(), terser()],
},
{
input: './src/index.ts',
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ sonar.language=ts
sonar.sourceEncoding=UTF-8
sonar.exclusions=documentation/**, typeDocs/**, **/__snapshots__/**, __mocks__/**, setup-jest.ts, rollup.config.js, jest.config.js
sonar.gitlab.max_critical_issues_gate=4
sonar.coverage.exclusions=**/test/**, **/tests/**, typeDocs/**, __mocks__/**, documentation/**, docs/**, **/__snapshots__/**, **/*.stories.mdx, **/*.test.{ts,tsx}, **/*.tests.{ts,tsx}, setup-jest.ts, rollup.config.js, jest.config.js
sonar.coverage.exclusions=**/test/**, **/tests/**, typeDocs/**, __mocks__/**, documentation/**, docs/**, **/__snapshots__/**, **/*.stories.mdx, **/*.test.{ts,tsx}, **/*.tests.{ts,tsx}, **/*.style.ts,setup-jest.ts, rollup.config.js, jest.config.js
sonar.javascript.lcov.reportPaths=./coverage/lcov.info
Loading

0 comments on commit e4ba3ee

Please sign in to comment.