Skip to content

Commit

Permalink
fix(admin-ui): resolve all bugs displayed for admin-ui #308
Browse files Browse the repository at this point in the history
  • Loading branch information
syntrydy committed Nov 23, 2021
1 parent 5ff03e6 commit afdf03b
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 27 deletions.
8 changes: 8 additions & 0 deletions app/redux/reducers/AuthReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export default function authReducer(state = INIT_STATE, action) {
...state,
location: action.payload.location,
}
} else {
return {
...state,
}
}
case GET_OAUTH2_CONFIG:
return {
Expand Down Expand Up @@ -88,6 +92,10 @@ export default function authReducer(state = INIT_STATE, action) {
permissions: action.payload.accessToken.scopes,
isAuthenticated: true,
}
} else {
return {
...state,
}
}

default:
Expand Down
8 changes: 8 additions & 0 deletions app/redux/reducers/FidoReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export default function fidoReducer(state = INIT_STATE, action) {
fido: action.payload.data,
loading: false,
}
} else {
return {
...state,
}
}
case PUT_FIDO:
return {
Expand All @@ -40,6 +44,10 @@ export default function fidoReducer(state = INIT_STATE, action) {
fido: action.payload.data,
loading: false,
}
} else {
return {
...state,
}
}

case RESET:
Expand Down
26 changes: 26 additions & 0 deletions app/redux/reducers/InitReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,36 @@ const reducerName = 'initReducer'
export default function initReducer(state = INIT_STATE, action) {
switch (action.type) {
case GET_SCRIPTS_FOR_STAT:
return {
...state,
}

case GET_SCRIPTS_FOR_STAT_RESPONSE:
if (action.payload.data) {
return {
...state,
scripts: action.payload.data,
}
} else {
return {
...state,
}
}

case GET_CLIENTS_FOR_STAT:
return {
...state,
}
case GET_CLIENTS_FOR_STAT_RESPONSE:
if (action.payload.data) {
return {
...state,
clients: action.payload.data,
}
} else {
return {
...state,
}
}

case GET_ATTRIBUTES_FOR_STAT:
Expand All @@ -45,15 +60,26 @@ export default function initReducer(state = INIT_STATE, action) {
...state,
attributes: action.payload.data,
}
} else {
return {
...state,
}
}

case GET_SCOPES_FOR_STAT:
return {
...state,
}
case GET_SCOPES_FOR_STAT_RESPONSE:
if (action.payload.data) {
return {
...state,
scopes: action.payload.data,
}
} else {
return {
...state,
}
}
default:
return {
Expand Down
10 changes: 10 additions & 0 deletions app/redux/reducers/JsonConfigReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export default function jsonConfigReducer(state = INIT_STATE, action) {
loading: false,
}
}
else {
return {
...state,
}
}

case PATCH_JSON_CONFIG:
return {
Expand All @@ -41,6 +46,11 @@ export default function jsonConfigReducer(state = INIT_STATE, action) {
loading: false,
}
}
else {
return {
...state,
}
}
default:
return {
...state,
Expand Down
4 changes: 4 additions & 0 deletions app/redux/reducers/OidcDiscoveryReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export default function oidcDiscoveryReducer(state = INIT_STATE, action) {
configuration: action.payload.configuration,
loading: true,
}
} else {
return {
...state,
}
}

default:
Expand Down
9 changes: 7 additions & 2 deletions app/routes/Apps/Gluu/GluuLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ function GluuLabel({ label, required, size, doc_category, doc_entry }) {
return 3
}
return (
<Label for ={label} sm={getSize()} data-tip data-for={label}>
<Label for={label} sm={getSize()} data-tip data-for={label}>
<h5>
{t(label)}
{required && <span style={{ color: 'red', fontSize: '22px' }}> *</span>}
:
</h5>
{doc_category && (
<ReactTooltip html={true} type="success" id={doc_entry}>
<ReactTooltip
html={true}
type="success"
id={doc_entry}
data-testid={doc_entry}
>
{t('documentation.' + doc_category + '.' + doc_entry)}
</ReactTooltip>
)}
Expand Down
4 changes: 2 additions & 2 deletions app/routes/Apps/Gluu/GluuViewWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from 'react'

function GluuViewWrapper(props) {
return props.canShow ? (
<div>{props.children}</div>
<div data-testid="WRAPPER">{props.children}</div>
) : (
<div>Missing required permission</div>
<div data-testid="MISSING">Missing required permission</div>
)
}

Expand Down
8 changes: 4 additions & 4 deletions app/routes/Apps/Gluu/LanguageMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ const LanguageMenu = () => {
}
return (
<ButtonDropdown isOpen={isOpen} toggle={toggle}>
<DropdownToggle caret color="primary">
<DropdownToggle caret color="primary" data-testid="ACTIVE_LANG">
{lang}
</DropdownToggle>
<DropdownMenu>
<DropdownItem onClick={() => changeLanguage('fr')}>
<DropdownItem onClick={() => changeLanguage('fr')} data-testid="FRE">
{t('languages.french')}
</DropdownItem>
<DropdownItem onClick={() => changeLanguage('pt')}>
<DropdownItem onClick={() => changeLanguage('pt')} data-testid="POR">
{t('languages.portuguese')}
</DropdownItem>
<DropdownItem onClick={() => changeLanguage('en')}>
<DropdownItem onClick={() => changeLanguage('en')} data-testid="ENG">
{t('languages.english')}
</DropdownItem>
</DropdownMenu>
Expand Down
14 changes: 12 additions & 2 deletions app/routes/Apps/Gluu/Tests/GluuAppSiderbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@ import { createStore } from 'redux'
import { Provider } from 'react-redux'
import i18n from '../../../../i18n'
import { I18nextProvider } from 'react-i18next'
import authReducer from '../../../../redux/reducers/AuthReducer'
import Sidebar from '../../../../../app/components/Sidebar'

jest.spyOn(global.console, 'log').mockImplementation(jest.fn())
jest.spyOn(global.console, 'error').mockImplementation(jest.fn())

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 = {
permissions: permissions,
}

const store = createStore(
combineReducers({
authReducer,
authReducer: (state = INIT_STATE) => state,
noReducer: (state = {}) => state,
}),
)
Expand All @@ -37,4 +45,6 @@ const Wrapper = ({ children }) => (
it('Should show the sidebar properly', () => {
const scopes = []
render(<GluuAppSidebar scopes={scopes} />, { wrapper: Wrapper })

expect(true).toBeTruthy()
})
7 changes: 4 additions & 3 deletions app/routes/Apps/Gluu/Tests/GluuInlineInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ it('Should render a boolean select box', () => {
/>
</I18nextProvider>,
)
screen.getByText('Application Type:')
expect(screen.getByText(/Application Type/)).toBeInTheDocument()
fireEvent.click(screen.getByText(VALUE))
fireEvent.click(screen.getByText(false))
})
Expand All @@ -44,7 +44,7 @@ it('Should render a typeahead component with array', () => {
/>
</I18nextProvider>,
)
screen.getByText('Application Type:')
expect(screen.getByText(/Application Type/)).toBeInTheDocument()
fireEvent.click(screen.getByText(VALUE))
})

Expand All @@ -60,6 +60,7 @@ it('Should render a text input', () => {
/>
</I18nextProvider>,
)
screen.getByText('Application Type:')
expect(screen.getByText(/Application Type/)).toBeInTheDocument()
expect(screen.getByDisplayValue(VALUE).id).toBe(NAME)
expect(screen.getByDisplayValue(VALUE).id).toBe(NAME)
})
4 changes: 2 additions & 2 deletions app/routes/Apps/Gluu/Tests/GluuInumInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ it('Should show the disabled input with proper text wit sa', () => {
/>
</I18nextProvider>,
)
screen.getByText('Application Type:')
expect(screen.getByText(/Application Type/)).toBeInTheDocument()
expect(screen.getByDisplayValue(VALUE).id).toBe(NAME)
expect(screen.getByDisplayValue(VALUE)).toBeDisabled
expect(screen.getByDisplayValue(VALUE)).toBeDisabled()
})
11 changes: 6 additions & 5 deletions app/routes/Apps/Gluu/Tests/GluuLabel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ it('Should render a required label with internationalized text', () => {
<GluuLabel label={labelText} required />
</I18nextProvider>,
)
screen.getByText('Application Type:')
screen.getByText('*')
expect(screen.getByText(/Application Type */)).toBeInTheDocument()
})

it('Should render the label with internationalized text', () => {
Expand All @@ -22,7 +21,7 @@ it('Should render the label with internationalized text', () => {
<GluuLabel label={labelText} />
</I18nextProvider>,
)
screen.getByText('Application Type:')
expect(screen.getByText(/Application Type/)).toBeInTheDocument()
})

it('Should render the label with internationalized text and tooltip support', () => {
Expand All @@ -36,6 +35,8 @@ it('Should render the label with internationalized text and tooltip support', ()
/>
</I18nextProvider>,
)
screen.getByText('Application Type:')
screen.getByText('The OpenID connect Client application type.')
expect(screen.getByText(/Application Type/)).toBeInTheDocument()
expect(
screen.getByText(/The OpenID connect Client application type/),
).toBeInTheDocument()
})
6 changes: 4 additions & 2 deletions app/routes/Apps/Gluu/Tests/GluuViewWrapper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ it('Check view wrapper with show', () => {
</GluuViewWrapper>
</I18nextProvider>,
)
screen.getByText(componentText)
expect(screen.getByTestId('WRAPPER')).toHaveTextContent(componentText)
})

it('Check view wrapper with no show', () => {
Expand All @@ -22,5 +22,7 @@ it('Check view wrapper with no show', () => {
<GluuViewWrapper />
</I18nextProvider>,
)
screen.getByText('Missing required permission')
expect(screen.getByTestId('MISSING')).toHaveTextContent(
'Missing required permission',
)
})
10 changes: 5 additions & 5 deletions app/routes/Apps/Gluu/Tests/LanguageMenu.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import {LanguageMenu} from '../LanguageMenu'
import { LanguageMenu } from '../LanguageMenu'
import i18n from '../../../../i18n'
import { I18nextProvider } from 'react-i18next'

Expand All @@ -10,8 +10,8 @@ it('All supported languages will be visible', () => {
<LanguageMenu />
</I18nextProvider>,
)
screen.getByText('en')
screen.getByText('French')
screen.getByText('English')
screen.getByText('Portuguese')
expect(screen.getByTestId('ACTIVE_LANG')).toHaveTextContent('en')
expect(screen.getByTestId('FRE')).toHaveTextContent('French')
expect(screen.getByTestId('ENG')).toHaveTextContent('English')
expect(screen.getByTestId('POR')).toHaveTextContent('Portuguese')
})

0 comments on commit afdf03b

Please sign in to comment.