-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(admin-ui): write test for all Gluu custom base UI components #290
- Loading branch information
Showing
3 changed files
with
213 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,69 @@ | ||
import React from 'react' | ||
import { render, screen } from '@testing-library/react' | ||
import GluuAppSidebar from '../GluuAppSidebar' | ||
import { combineReducers } from 'redux' | ||
import { BrowserRouter as Router } from 'react-router-dom' | ||
import { createStore } from 'redux' | ||
import { Provider } from 'react-redux' | ||
import i18n from '../../../../i18n' | ||
import { I18nextProvider } from 'react-i18next' | ||
import reducerRegistry from '../../../../redux/reducers/ReducerRegistry' | ||
//import store from '../../../../redux/store' | ||
import appReducers from '../../../../redux/reducers' | ||
import authReducer from '../../../../redux/reducers/AuthReducer' | ||
import Sidebar from '../../../../../app/components/Sidebar' | ||
|
||
it('Should show the sidebar properly', () => { | ||
/* const scopes = [] | ||
render( | ||
<I18nextProvider i18n={i18n}> | ||
<GluuAppSidebar scopes={scopes} /> | ||
</I18nextProvider>, | ||
) | ||
screen.getByText('Sign out') | ||
*/ | ||
jest.spyOn(global.console, 'log').mockImplementation(jest.fn()); | ||
jest.spyOn(global.console, 'error').mockImplementation(jest.fn()); | ||
|
||
const combine = (reducers) => { | ||
const reducerNames = Object.keys(reducers) | ||
Object.keys(appReducers).forEach((item) => { | ||
if (reducerNames.indexOf(item) === -1) { | ||
reducers[item] = (state = null) => state | ||
} | ||
}) | ||
|
||
return combineReducers(reducers) | ||
} | ||
const reducers = combine(reducerRegistry.getReducers()) | ||
|
||
const INIT_STATE = { | ||
isAuthenticated: false, | ||
userinfo: null, | ||
userinfo_jwt: null, | ||
token: null, | ||
issuer: null, | ||
permissions: [], | ||
location: {}, | ||
config: {}, | ||
backendIsUp: true, | ||
} | ||
|
||
//const store1 = createStore(reducers, INIT_STATE) | ||
const store = createStore( | ||
combineReducers({ | ||
authReducer, | ||
noReducer: (state = {}) => state, | ||
}), | ||
) | ||
const pageConfig ={} | ||
const Wrapper = ({ children }) => ( | ||
<I18nextProvider i18n={i18n}> | ||
<Provider store={store}> | ||
<Router basename="/admin"> | ||
<Sidebar.MobileFluid pageConfig={pageConfig}> | ||
<Sidebar.Section fluid cover> | ||
{children} | ||
</Sidebar.Section> | ||
</Sidebar.MobileFluid> | ||
</Router> | ||
</Provider> | ||
</I18nextProvider> | ||
) | ||
|
||
it('Should show the sidebar properly', () => { | ||
const scopes = [] | ||
render(<GluuAppSidebar scopes={scopes} />, { wrapper: Wrapper }) | ||
|
||
// screen.getByText('Sign out') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
plugins/auth-server/components/Clients/ClientListPage.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
import React from 'react' | ||
import { render, screen } from '@testing-library/react' | ||
import ClientListPage from './ClientListPage' | ||
import { combineReducers } from 'redux' | ||
import { BrowserRouter as Router } from 'react-router-dom' | ||
import { createStore } from 'redux' | ||
import { Provider } from 'react-redux' | ||
import i18n from '../../../../app/i18n' | ||
import { I18nextProvider } from 'react-i18next' | ||
import authReducer from '../../../../app/redux/reducers/AuthReducer' | ||
import oidcReducer from '../../redux/reducers/OIDCReducer' | ||
import scopeReducer from '../../redux/reducers/ScopeReducer' | ||
|
||
const permissions = [ | ||
'https://jans.io/oauth/config/openid/clients.readonly', | ||
'https://jans.io/oauth/config/openid/clients.write', | ||
'https://jans.io/oauth/config/openid/clients.delete', | ||
] | ||
const INIT_STATE = { | ||
isAuthenticated: false, | ||
userinfo: null, | ||
userinfo_jwt: null, | ||
token: null, | ||
issuer: null, | ||
permissions: permissions, | ||
location: {}, | ||
config: {}, | ||
backendIsUp: true, | ||
} | ||
|
||
const INIT_CLIENTS_STATE = { | ||
items: [ | ||
{ | ||
applicationType: 'web', | ||
includeClaimsInIdToken: false, | ||
dn: 'inum=2073c8e7-1060-4c09-b0f6-7d46fb6ff8f5,ou=clients,o=jans', | ||
inum: '2073c8e7-1060-4c09-b0f6-7d46fb6ff8f5', | ||
clientSecret: '92bc4d8e-2f4c-4a4d-80ae-1e4eb1f5f463', | ||
frontChannelLogoutUri: 'http://localhost:4100/logout', | ||
frontChannelLogoutSessionRequired: false, | ||
registrationAccessToken: 'de5aaa9c-d6b4-44a1-912f-40c97063544a', | ||
clientIdIssuedAt: '2021-07-28T06:35:09.000Z', | ||
redirectUris: [ | ||
'http://localhost:4100', | ||
'https://admin-ui-test.gluu.org/admin', | ||
], | ||
responseTypes: ['code'], | ||
grantTypes: ['authorization_code', 'refresh_token', 'client_credentials'], | ||
clientName: 'admin-ui', | ||
subjectType: 'pairwise', | ||
idTokenSignedResponseAlg: 'RS256', | ||
userInfoSignedResponseAlg: 'RS256', | ||
tokenEndpointAuthMethod: 'client_secret_basic', | ||
requireAuthTime: false, | ||
defaultAcrValues: ['simple_password_auth'], | ||
postLogoutRedirectUris: [ | ||
'http://localhost:4100', | ||
'https://admin-ui-test.gluu.org/admin', | ||
], | ||
scopes: [ | ||
'inum=F0C4,ou=scopes,o=jans', | ||
'inum=6D90,ou=scopes,o=jans', | ||
'inum=43F1,ou=scopes,o=jans', | ||
], | ||
trustedClient: false, | ||
lastAccessTime: '2021-07-28T06:35:09.000Z', | ||
lastLogonTime: '2021-07-28T06:35:09.000Z', | ||
persistClientAuthorizations: true, | ||
customAttributes: [], | ||
customObjectClasses: ['top'], | ||
rptAsJwt: false, | ||
accessTokenAsJwt: true, | ||
accessTokenSigningAlg: 'RS256', | ||
disabled: false, | ||
attributes: { | ||
runIntrospectionScriptBeforeAccessTokenAsJwtCreationAndIncludeClaims: false, | ||
keepClientAuthorizationAfterExpiration: false, | ||
allowSpontaneousScopes: false, | ||
backchannelLogoutSessionRequired: false, | ||
}, | ||
deletable: false, | ||
}, | ||
], | ||
item: {}, | ||
view: false, | ||
loading: false, | ||
} | ||
|
||
const INIT_SCPOPES_STATE = { | ||
items: [ | ||
{ | ||
id: 'https://jans.io/oauth/config/smtp.delete', | ||
scopeType: 'oauth', | ||
dn: 'inum=1800.85A227,ou=scopes,o=jans', | ||
inum: '1800.85A227', | ||
displayName: 'Config API scope https://jans.io/oauth/config/smtp.delete', | ||
description: 'Delete SMTP related information', | ||
defaultScope: false, | ||
attributes: { showInConfigurationEndpoint: false }, | ||
umaType: false, | ||
tableData: { id: 0 }, | ||
}, | ||
{ | ||
id: 'openid', | ||
scopeType: 'openid', | ||
dn: 'inum=F0C4,ou=scopes,o=jans', | ||
inum: 'F0C4', | ||
displayName: 'authenticate_openid_connect', | ||
description: 'Authenticate using OpenID Connect.', | ||
defaultScope: true, | ||
attributes: { showInConfigurationEndpoint: true }, | ||
umaType: false, | ||
tableData: { id: 1 }, | ||
}, | ||
], | ||
item: {}, | ||
loading: false, | ||
} | ||
const store = createStore( | ||
combineReducers({ | ||
authReducer: (state = INIT_STATE) => state, | ||
oidcReducer: (state = INIT_SCPOPES_STATE) => state, | ||
scopeReducer, | ||
noReducer: (state = {}) => state, | ||
}), | ||
) | ||
|
||
const Wrapper = ({ children }) => ( | ||
<I18nextProvider i18n={i18n}> | ||
<Provider store={store}> | ||
<Router basename="/admin">{children}</Router> | ||
</Provider> | ||
</I18nextProvider> | ||
) | ||
const emptyArray = [] | ||
|
||
it('Should show the sidebar properly', () => { | ||
render( | ||
<ClientListPage | ||
clients={emptyArray} | ||
permissions={permissions} | ||
scopes={emptyArray} | ||
/>, | ||
{ wrapper: Wrapper }, | ||
) | ||
screen.getByText(/OIDC Clients/) | ||
screen.getByTitle('Add Client') | ||
screen.getByText(/refresh/) | ||
screen.getByText(/search/) | ||
}) |