Skip to content

Commit

Permalink
feat: write test for all pages under admin plugin #302
Browse files Browse the repository at this point in the history
  • Loading branch information
fausto-gluu committed Dec 2, 2021
1 parent 37275a9 commit a69f4a4
Show file tree
Hide file tree
Showing 11 changed files with 338 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const permissions = [
'https://jans.io/oauth/config/attributes.write',
'https://jans.io/oauth/config/attributes.delete',
]
const item = license[0]
const item = license
it('Should render the license detail page properly', () => {
render(<LicenseDetailsForm item={item} permissions={permissions} />, {
wrapper: Wrapper,
Expand Down
40 changes: 40 additions & 0 deletions plugins/admin/components/Configuration/LicenseDetailsPage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import LicenseDetailsPage from './LicenseDetailsPage'
import { createStore, combineReducers } from 'redux'
import { Provider } from 'react-redux'
import i18n from '../../../../app/i18n'
import { I18nextProvider } from 'react-i18next'
import license from "./license"

const permissions = [
'https://jans.io/oauth/config/attributes.readonly',
'https://jans.io/oauth/config/attributes.write',
'https://jans.io/oauth/config/attributes.delete',
]
const INIT_LICENSE_DETAIL_STATE = {
item: license,
loading: false,
}
const store = createStore(
combineReducers({
licenseDetailsReducer: (state = INIT_LICENSE_DETAIL_STATE) => state,
noReducer: (state = {}) => state,
}),
)

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

it('Should render the Custom Script add page properly', () => {
render(<LicenseDetailsPage />, { wrapper: Wrapper })
const key = license.licenseKey
screen.getByText(/Product Name/)
screen.getByText(/Product Code/)
screen.getByText(/License Type/)
screen.getByText(/License Key/)
screen.getByText(key)
})
30 changes: 14 additions & 16 deletions plugins/admin/components/Configuration/license.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
export const license = [
{
companyName: "Gluu",
customerEmail: "arnab@gluu.org",
customerFirstName: "Arnab",
customerLastName: "Dutta",
licenseActive: true,
licenseEnable: true,
licenseKey: "GFXJ-AB8B-YDJK-L4AD",
licenseType: "TIME_LIMITED",
maxActivations: 14,
productCode: "adminui001",
productName: "Gluu Admin UI",
validityPeriod: "2022-10-01T00:00Z",
}
]
export const license = {
companyName: "Gluu",
customerEmail: "arnab@gluu.org",
customerFirstName: "Arnab",
customerLastName: "Dutta",
licenseActive: true,
licenseEnable: true,
licenseKey: "GFXJ-AB8B-YDJK-L4AD",
licenseType: "TIME_LIMITED",
maxActivations: 14,
productCode: "adminui001",
productName: "Gluu Admin UI",
validityPeriod: "2022-10-01T00:00Z",
}
export default license
42 changes: 42 additions & 0 deletions plugins/admin/components/CustomScripts/CustomScriptAddPage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import CustomScriptAddPage from './CustomScriptAddPage'
import { createStore, combineReducers } from 'redux'
import { Provider } from 'react-redux'
import i18n from '../../../../app/i18n'
import { I18nextProvider } from 'react-i18next'
import item from "./item"

const permissions = [
'https://jans.io/oauth/config/attributes.readonly',
'https://jans.io/oauth/config/attributes.write',
'https://jans.io/oauth/config/attributes.delete',
]
const INIT_STATE = {
permissions: permissions,
}
const INIT_CUSTOM_SCRIPT_STATE = {
items: [
item,
],
loading: false,
}
const store = createStore(
combineReducers({
authReducer: (state = INIT_STATE) => state,
customScriptReducer: (state = INIT_CUSTOM_SCRIPT_STATE) => state,
noReducer: (state = {}) => state,
}),
)

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

it('Should render the Custom Script add page properly', () => {
render(<CustomScriptAddPage />, { wrapper: Wrapper })
screen.getByText(/Name/)
screen.getByText(/Description/)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import CustomScriptEditPage from './CustomScriptEditPage'
import { createStore, combineReducers } from 'redux'
import { Provider } from 'react-redux'
import i18n from '../../../../app/i18n'
import { I18nextProvider } from 'react-i18next'
import item from "./item"
import script from "./script"

const permissions = [
'https://jans.io/oauth/config/attributes.readonly',
'https://jans.io/oauth/config/attributes.write',
'https://jans.io/oauth/config/attributes.delete',
]
const INIT_STATE = {
permissions: permissions,
}
const INIT_CUSTOM_SCRIPT_STATE = {
items: [
script,
],
item: item,
loading: false,
}
const store = createStore(
combineReducers({
authReducer: (state = INIT_STATE) => state,
customScriptReducer: (state = INIT_CUSTOM_SCRIPT_STATE) => state,
noReducer: (state = {}) => state,
}),
)

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

it('Should render the Custom Script edit page properly', () => {
render(<CustomScriptEditPage />, { wrapper: Wrapper })
screen.getByText(/Name/)
screen.getByText(/Description/)
screen.getByText(/Select SAML ACRS/)
screen.getByText(/Script Type/)
})
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const permissions = [
'https://jans.io/oauth/config/attributes.delete',
]

it('Should render the Custom Script detail page properly', () => {
it('Should render the Custom Script form page properly', () => {
render(<CustomScriptForm item={item} scripts={script} permissions={permissions} />, {
wrapper: Wrapper,
})
Expand Down
111 changes: 111 additions & 0 deletions plugins/admin/components/MonthlyActiveUsersPage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import MonthlyActiveUsersPage from './MonthlyActiveUsersPage'
import { createStore, combineReducers } from 'redux'
import { Provider } from 'react-redux'
import i18n from '../../../app/i18n'
import { I18nextProvider } from 'react-i18next'

const stat = [
{
"month": 202108,
"monthly_active_users": 5,
"token_count_per_granttype": {
"client_credentials": {
"access_token": 107
},
"authorization_code": {
"access_token": 623,
"id_token": 622
}
}
},
{
"month": 202109,
"monthly_active_users": 1,
"token_count_per_granttype": {
"client_credentials": {
"access_token": 957
},
"authorization_code": {
"access_token": 2387,
"id_token": 2387
}
}
},
{
"month": 202110,
"monthly_active_users": 1,
"token_count_per_granttype": {
"client_credentials": {
"access_token": 89
},
"authorization_code": {
"access_token": 350,
"id_token": 350
}
}
},
{
"month": 202111,
"monthly_active_users": 1,
"token_count_per_granttype": {
"client_credentials": {
"access_token": 1036
},
"password": {
"access_token": 2
},
"authorization_code": {
"access_token": 347,
"id_token": 347
}
}
},
{
"month": 202112,
"monthly_active_users": 1,
"token_count_per_granttype": {
"client_credentials": {
"access_token": 411
},
"authorization_code": {
"access_token": 132,
"id_token": 132
}
}
}
]

const permissions = [
'https://jans.io/oauth/config/attributes.readonly',
'https://jans.io/oauth/config/attributes.write',
'https://jans.io/oauth/config/attributes.delete',
]
const INIT_STATE = {
permissions: permissions,
}
const INIT_MAU_STATE = {
stat: stat,
}
const INIT_OIDC_STATE = {
loading: false,
}
const store = createStore(
combineReducers({
authReducer: (state = INIT_STATE) => state,
mauReducer: (state = INIT_MAU_STATE) => state,
oidcReducer: (state = INIT_OIDC_STATE) => state,
noReducer: (state = {}) => state,
}),
)

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

it('Should render the api role list page properly', () => {
render(<MonthlyActiveUsersPage />, { wrapper: Wrapper })
})
25 changes: 25 additions & 0 deletions plugins/admin/components/Roles/UiRoleDetailPage.test.js
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 UiRoleDetailPage from './UiRoleDetailPage'
import roles from "./roles"
import i18n from '../../../../app/i18n'
import { I18nextProvider } from 'react-i18next'

const Wrapper = ({ children }) => (
<I18nextProvider i18n={i18n}>{children}</I18nextProvider>
)
const permissions = [
'https://jans.io/oauth/config/attributes.readonly',
'https://jans.io/oauth/config/attributes.write',
'https://jans.io/oauth/config/attributes.delete',
]
const row = roles[0]
it('Should render the license detail page properly', () => {
render(<UiRoleDetailPage row={row} permissions={permissions} />, {
wrapper: Wrapper,
})
const name = row.name
screen.getByText(/Name/)
screen.getByText(/Description/)
screen.getByText(name)
})
39 changes: 39 additions & 0 deletions plugins/admin/components/Roles/UiRoleListPage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import UiRoleListPage from './UiRoleListPage'
import { createStore, combineReducers } from 'redux'
import { Provider } from 'react-redux'
import i18n from '../../../../app/i18n'
import { I18nextProvider } from 'react-i18next'
import roles from "./roles"

const permissions = [
'https://jans.io/oauth/config/attributes.readonly',
'https://jans.io/oauth/config/attributes.write',
'https://jans.io/oauth/config/attributes.delete',
]
const INIT_STATE = {
permissions: permissions,
}
const INIT_API_ROLE_STATE = {
items: roles,
loading: false,
}
const store = createStore(
combineReducers({
authReducer: (state = INIT_STATE) => state,
apiRoleReducer: (state = INIT_API_ROLE_STATE) => state,
noReducer: (state = {}) => state,
}),
)

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

it('Should render the api role list page properly', () => {
render(<UiRoleListPage />, { wrapper: Wrapper })

})
7 changes: 1 addition & 6 deletions plugins/admin/components/Settings/SettingsPage.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React, { useState } from 'react'
import { connect } from 'react-redux'
import GluuLabel from '../../../../app/routes/Apps/Gluu/GluuLabel'
import GluuTooltip from '../../../../app/routes/Apps/Gluu/GluuTooltip'
import { SETTINGS } from '../../../../app/utils/ApiResources'

import {
Card,
CardBody,
Expand Down Expand Up @@ -99,7 +97,4 @@ function SettingsPage() {
)
}

const mapStateToProps = (state) => {
return {}
}
export default connect(mapStateToProps)(SettingsPage)
export default SettingsPage
18 changes: 18 additions & 0 deletions plugins/admin/components/Settings/SettingsPage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import SettingsPage from './SettingsPage'
import i18n from '../../../../app/i18n'
import { I18nextProvider } from 'react-i18next'

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

it('Should render the license detail page properly', () => {
render(<SettingsPage />, {
wrapper: Wrapper,
})
screen.getByText(/List paging size/)
screen.getByText(/Dark Mode/)
screen.getByText(/Config API URL/)
})

0 comments on commit a69f4a4

Please sign in to comment.