Skip to content

Commit

Permalink
fix(admin-ui): write test for all pages under auth-server plugin #301
Browse files Browse the repository at this point in the history
  • Loading branch information
syntrydy committed Nov 12, 2021
1 parent ea4d016 commit 2c1cb78
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function AcrsPage({ acrs, scripts, permissions, loading, dispatch }) {
type="select"
id="defaultAcr"
name="defaultAcr"
data-testid="defaultAcr"
value={acrs.defaultAcr}
onChange={(e) => {
acrs.defaultAcr = e.target.value
Expand Down Expand Up @@ -90,9 +91,9 @@ function AcrsPage({ acrs, scripts, permissions, loading, dispatch }) {
const mapStateToProps = (state) => {
return {
acrs: state.acrReducer.acrs,
loading: state.acrReducer.loading,
permissions: state.authReducer.permissions,
scripts: state.customScriptReducer.items,
loading: state.acrReducer.loading,
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import AcrsPage from './AcrsPage'
import { combineReducers, createStore } from 'redux'
import { Provider } from 'react-redux'
import i18n from '../../../../../app/i18n'
import { I18nextProvider } from 'react-i18next'

const permissions = [
'https://jans.io/oauth/config/acrs.readonly',
'https://jans.io/oauth/config/acrs.write',
'https://jans.io/oauth/config/acrs.delete',
]
const ACRS_STATE = {
acrs: {},
scripts: [],
loading: false,
}

const AUTH_STATE = {
permissions: permissions,
}
const SCRIPT_STATE = {
items: [],
}

const store = createStore(
combineReducers({
authReducer: (state = AUTH_STATE) => state,
acrReducer: (state = ACRS_STATE) => state,
customScriptReducer: (state = SCRIPT_STATE) => state,
noReducer: (state = {}) => state,
}),
)

const Wrapper = ({ children }) => (
<I18nextProvider i18n={i18n}>
<Provider store={store}>{children}</Provider>
</I18nextProvider>
)

it('Should render Acr page properly', () => {
render(<AcrsPage />, {
wrapper: Wrapper,
})
screen.getByText(/simple_password_auth/)
expect(screen.getByTestId('defaultAcr')).toBeInTheDocument()
})
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const mapStateToProps = (state) => {
return {
configuration: state.jsonConfigReducer.configuration,
permissions: state.authReducer.permissions,
loading: state.smtpReducer.loading,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import { useTranslation } from 'react-i18next'

function LoggingPage({ logging, dispatch, permissions, loading }) {
console.log(JSON.stringify(logging))
const { t } = useTranslation()
useEffect(() => {
dispatch(getLoggingConfig())
Expand Down Expand Up @@ -75,6 +76,7 @@ function LoggingPage({ logging, dispatch, permissions, loading }) {
type="select"
id="loggingLevel"
name="loggingLevel"
data-testid="loggingLevel"
value={logging.loggingLevel}
onChange={(e) => {
logging.loggingLevel = e.target.value
Expand All @@ -99,6 +101,7 @@ function LoggingPage({ logging, dispatch, permissions, loading }) {
type="select"
id="loggingLayout"
name="loggingLayout"
data-testid="loggingLayout"
value={logging.loggingLayout}
onChange={(e) => {
logging.loggingLayout = e.target.value
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import LoggingPage from './LoggingPage'
import { combineReducers, createStore } from 'redux'
import { Provider } from 'react-redux'
import i18n from '../../../../../app/i18n'
import { I18nextProvider } from 'react-i18next'

const permissions = [
'https://jans.io/oauth/config/logging.readonly',
'https://jans.io/oauth/config/logging.write',
'https://jans.io/oauth/config/logging.delete',
]

const AUTH_STATE = {
permissions: permissions,
}
const logging = {
loggingLevel: 'TRACE',
loggingLayout: 'text',
httpLoggingEnabled: true,
disableJdkLogger: false,
enabledOAuthAuditLogging: false,
}
const LOGGING_STATE = {
logging: logging,
loading: false,
}

const store = createStore(
combineReducers({
authReducer: (state = AUTH_STATE) => state,
loggingReducer: (state = LOGGING_STATE) => state,
noReducer: (state = {}) => state,
}),
)

const Wrapper = ({ children }) => (
<I18nextProvider i18n={i18n}>
<Provider store={store}>{children}</Provider>
</I18nextProvider>
)

it('Should render Acr page properly', () => {
render(<LoggingPage />, {
wrapper: Wrapper,
})
expect(screen.getByTestId('loggingLayout')).toHaveDisplayValue(
logging.loggingLayout,
)
expect(screen.getByTestId('loggingLevel')).toHaveDisplayValue(
logging.loggingLevel,
)
expect(screen.getByTestId('httpLoggingEnabled')).toBeChecked()
expect(screen.getByTestId('disableJdkLogger')).not.toBeChecked()
expect(screen.getByTestId('enabledOAuthAuditLogging')).not.toBeChecked()
})

0 comments on commit 2c1cb78

Please sign in to comment.