Browse Source

bugfix: fix authority test

pull/5452/head
陈帅 7 years ago
parent
commit
1e8238cdb9
  1. 1
      jest.config.js
  2. 2
      src/components/Authorized/index.tsx
  3. 3
      src/utils/authority.ts

1
jest.config.js

@ -3,5 +3,6 @@ module.exports = {
preset: 'jest-puppeteer', preset: 'jest-puppeteer',
globals: { globals: {
ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: false, ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: false,
localStorage: null,
}, },
}; };

2
src/components/Authorized/index.tsx

@ -1,11 +1,9 @@
import Authorized from './Authorized'; import Authorized from './Authorized';
import AuthorizedRoute from './AuthorizedRoute';
import Secured from './Secured'; import Secured from './Secured';
import check from './CheckPermissions'; import check from './CheckPermissions';
import renderAuthorize from './renderAuthorize'; import renderAuthorize from './renderAuthorize';
Authorized.Secured = Secured; Authorized.Secured = Secured;
Authorized.AuthorizedRoute = AuthorizedRoute;
Authorized.check = check; Authorized.check = check;
const RenderAuthorize = renderAuthorize(Authorized); const RenderAuthorize = renderAuthorize(Authorized);

3
src/utils/authority.ts

@ -2,9 +2,8 @@ import { reloadAuthorized } from './Authorized';
// use localStorage to store the authority info, which might be sent from server in actual project. // use localStorage to store the authority info, which might be sent from server in actual project.
export function getAuthority(str?: string): string | string[] { export function getAuthority(str?: string): string | string[] {
// return localStorage.getItem('antd-pro-authority') || ['admin', 'user'];
const authorityString = const authorityString =
typeof str === 'undefined' ? localStorage.getItem('antd-pro-authority') : str; typeof str === 'undefined' && localStorage ? localStorage.getItem('antd-pro-authority') : str;
// authorityString could be admin, "admin", ["admin"] // authorityString could be admin, "admin", ["admin"]
let authority; let authority;
try { try {

Loading…
Cancel
Save