-
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 scopes management #300
- Loading branch information
Showing
4 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
plugins/auth-server/components/Scopes/ScopeAddPage.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,70 @@ | ||
import React from 'react' | ||
import { render, screen } from '@testing-library/react' | ||
import ScopeAddPage from './ScopeAddPage' | ||
import { combineReducers } from 'redux' | ||
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 attributeReducer from '../../../schema/redux/reducers/AttributeReducer' | ||
import customScriptReducer from '../../../admin/redux/reducers/CustomScriptReducer' | ||
import scopeReducer from '../../redux/reducers/ScopeReducer' | ||
|
||
const scopes = [] | ||
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, | ||
} | ||
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 }, | ||
}, | ||
], | ||
item: {}, | ||
loading: false, | ||
} | ||
const store = createStore( | ||
combineReducers({ | ||
authReducer: (state = INIT_STATE) => state, | ||
customScriptReducer: (state = INIT_SCPOPES_STATE) => state, | ||
attributeReducer: (state = INIT_SCPOPES_STATE) => state, | ||
scopeReducer, | ||
noReducer: (state = {}) => state, | ||
}), | ||
) | ||
|
||
const Wrapper = ({ children }) => ( | ||
<I18nextProvider i18n={i18n}> | ||
<Provider store={store}>{children}</Provider> | ||
</I18nextProvider> | ||
) | ||
|
||
it('Should render the scope add page properly', () => { | ||
render( | ||
<ScopeAddPage scopes={scopes} permissions={permissions} scopes={[]} />, | ||
{ wrapper: Wrapper }, | ||
) | ||
screen.getByText(/Display Name/) | ||
screen.getByText(/Description/) | ||
screen.getByText(/Default Scope/) | ||
}) |
25 changes: 25 additions & 0 deletions
25
plugins/auth-server/components/Scopes/ScopeDetailPage.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,25 @@ | ||
import React from 'react' | ||
import { render, screen } from '@testing-library/react' | ||
import ScopeDetailPage from './ScopeDetailPage' | ||
import i18n from '../../../../app/i18n' | ||
import scopes from './scopes' | ||
import { I18nextProvider } from 'react-i18next' | ||
|
||
const Wrapper = ({ children }) => ( | ||
<I18nextProvider i18n={i18n}>{children}</I18nextProvider> | ||
) | ||
const permissions = [ | ||
'https://jans.io/oauth/config/scopes.readonly', | ||
'https://jans.io/oauth/config/scopes.write', | ||
'https://jans.io/oauth/config/scopes.delete', | ||
] | ||
const scope = scopes[0] | ||
|
||
it('Should render the scope detail page properly', () => { | ||
render(<ScopeDetailPage row={scope} permissions={permissions} />, { | ||
wrapper: Wrapper, | ||
}) | ||
screen.getByText(/Display Name/) | ||
screen.getByText(/Description/) | ||
screen.getByText(/Default Scope/) | ||
}) |
56 changes: 56 additions & 0 deletions
56
plugins/auth-server/components/Scopes/ScopeEditPage.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,56 @@ | ||
import React from 'react' | ||
import { render, screen } from '@testing-library/react' | ||
import ScopeEditPage from './ScopeEditPage' | ||
import { combineReducers } from 'redux' | ||
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 attributeReducer from '../../../schema/redux/reducers/AttributeReducer' | ||
import customScriptReducer from '../../../admin/redux/reducers/CustomScriptReducer' | ||
import scopeReducer from '../../redux/reducers/ScopeReducer' | ||
|
||
const scopes = [] | ||
const permissions = [ | ||
'https://jans.io/oauth/config/scopes.readonly', | ||
'https://jans.io/oauth/config/scopes.write', | ||
'https://jans.io/oauth/config/scopes.delete', | ||
] | ||
const INIT_STATE = { | ||
isAuthenticated: false, | ||
userinfo: null, | ||
userinfo_jwt: null, | ||
token: null, | ||
issuer: null, | ||
permissions: permissions, | ||
} | ||
const INIT_SCPOPES_STATE = { | ||
items: [scopes[0]], | ||
item: {}, | ||
loading: false, | ||
} | ||
const store = createStore( | ||
combineReducers({ | ||
authReducer: (state = INIT_STATE) => state, | ||
customScriptReducer, | ||
attributeReducer, | ||
scopeReducer: (state = INIT_SCPOPES_STATE) => state, | ||
noReducer: (state = {}) => state, | ||
}), | ||
) | ||
|
||
const Wrapper = ({ children }) => ( | ||
<I18nextProvider i18n={i18n}> | ||
<Provider store={store}>{children}</Provider> | ||
</I18nextProvider> | ||
) | ||
|
||
it('Should render the scope edit page properly', () => { | ||
render(<ScopeEditPage scope={scopes[0]} permissions={permissions} />, { | ||
wrapper: Wrapper, | ||
}) | ||
screen.getByText(/Display Name/) | ||
screen.getByText(/Description/) | ||
screen.getByText(/Default Scope/) | ||
}) |
58 changes: 58 additions & 0 deletions
58
plugins/auth-server/components/Scopes/ScopeListPage.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,58 @@ | ||
import React from 'react' | ||
import { render, screen } from '@testing-library/react' | ||
import ScopeListPage from './ScopeListPage' | ||
import { combineReducers } from 'redux' | ||
import { createStore } from 'redux' | ||
import { Provider } from 'react-redux' | ||
import scopes from './scopes' | ||
import i18n from '../../../../app/i18n' | ||
import { I18nextProvider } from 'react-i18next' | ||
import authReducer from '../../../../app/redux/reducers/AuthReducer' | ||
import scopeReducer from '../../redux/reducers/ScopeReducer' | ||
|
||
const permissions = [ | ||
'https://jans.io/oauth/config/scopes.readonly', | ||
'https://jans.io/oauth/config/scopes.write', | ||
'https://jans.io/oauth/config/scopes.delete', | ||
] | ||
const INIT_STATE = { | ||
isAuthenticated: false, | ||
userinfo: null, | ||
userinfo_jwt: null, | ||
token: null, | ||
issuer: null, | ||
permissions: permissions, | ||
} | ||
|
||
const INIT_SCPOPES_STATE = { | ||
items: [scopes[0]], | ||
item: {}, | ||
loading: false, | ||
} | ||
const store = createStore( | ||
combineReducers({ | ||
authReducer: (state = INIT_STATE) => state, | ||
scopeReducer: (state = INIT_SCPOPES_STATE) => state, | ||
noReducer: (state = {}) => state, | ||
}), | ||
) | ||
|
||
const Wrapper = ({ children }) => ( | ||
<I18nextProvider i18n={i18n}> | ||
<Provider store={store}>{children}</Provider> | ||
</I18nextProvider> | ||
) | ||
|
||
it('Should render the scope list page properly', () => { | ||
render(<ScopeListPage scopes={scopes} permissions={permissions} />, { | ||
wrapper: Wrapper, | ||
}) | ||
const inum = scopes[0].inum | ||
const description = scopes[0].description | ||
screen.getByText(/Display Name/) | ||
screen.getByText(/Description/) | ||
screen.getByText(/Scopes/) | ||
screen.getByText(/search/) | ||
screen.getByText(inum) | ||
screen.getByText(description) | ||
}) |