Skip to content

Commit

Permalink
fix: add tests, clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Dec 18, 2024
1 parent e726acf commit 326c865
Show file tree
Hide file tree
Showing 35 changed files with 663 additions and 71 deletions.
22 changes: 8 additions & 14 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-12-12T11:59:53.609Z\n"
"PO-Revision-Date: 2024-12-12T11:59:53.610Z\n"
"POT-Creation-Date: 2024-12-18T07:54:11.061Z\n"
"PO-Revision-Date: 2024-12-18T07:54:11.062Z\n"

msgid "Yes"
msgstr "Yes"
Expand Down Expand Up @@ -53,12 +53,6 @@ msgstr "Will be added"
msgid "Will be removed"
msgstr "Will be removed"

msgid "Network error"
msgstr "Network error"

msgid "Could not load current user information."
msgstr "Could not load current user information."

msgid "Filter options"
msgstr "Filter options"

Expand Down Expand Up @@ -1012,12 +1006,6 @@ msgstr "Last login"
msgid "Status"
msgstr "Status"

msgid "Verified"
msgstr "Verified"

msgid "Not verified"
msgstr "Not verified"

msgid "Disabled"
msgstr "Disabled"

Expand Down Expand Up @@ -1081,5 +1069,11 @@ msgstr "Interests"
msgid "Birthday"
msgstr "Birthday"

msgid "Network error"
msgstr "Network error"

msgid "Could not load current user information."
msgstr "Could not load current user information."

msgid "Could not load system information."
msgstr "Could not load system information."
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
setupFilesAfterEnv: ['<rootDir>/src/test-utils/setup-tests.js'],
transformIgnorePatterns: ['/node_modules/(?!(lodash-es)/)'],
transformIgnorePatterns: ['/node_modules/(?!(lodash-es|p-debounce)/)'],
}
2 changes: 1 addition & 1 deletion src/AppWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import './locales/index.js'
import { CssVariables } from '@dhis2/ui'
import React from 'react'
import App from './App.js'
import { CurrentUserProvider } from './components/CurrentUserProvider.js'
import { CurrentUserProvider } from './providers/current-user/CurrentUserProvider.js'
import { ReferrerProvider, SystemProvider } from './providers/index.js'

const AppWrapper = () => (
Expand Down
3 changes: 1 addition & 2 deletions src/components/GroupForm/GroupForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { NoticeBox, FinalForm } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React from 'react'
import { useHistory } from 'react-router-dom'
import { useCurrentUser } from '../../hooks/useCurrentUser.js'
import { useReferrerInfo } from '../../providers/index.js'
import { useCurrentUser, useReferrerInfo } from '../../providers/index.js'
import navigateTo from '../../utils/navigateTo.js'
import Attributes from '../Attributes/index.js'
import Form, { FormSection } from '../Form.js'
Expand Down
11 changes: 8 additions & 3 deletions src/components/RoleForm/AssignmentRestrictionsWarning.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ export const AssignmentRestrictionWarning = ({
currentUser,
roleId,
roleAuthorities,
initiallyExpanded,
}) => {
const [detailsExpanded, setDetailsExpanded] = useState(false)
const [detailsExpanded, setDetailsExpanded] = useState(
initiallyExpanded ?? false
)

// check if user is able to assign this role if they are a member
const {
Expand Down Expand Up @@ -57,6 +60,7 @@ export const AssignmentRestrictionWarning = ({
onClick={() => {
setDetailsExpanded((prev) => !prev)
}}
data-test="roles-details-expand"
>
{detailsExpanded ? (
<IconChevronUp24 />
Expand All @@ -67,7 +71,7 @@ export const AssignmentRestrictionWarning = ({
</div>

{detailsExpanded && (
<ul>
<ul data-test="authorities-user-does-not-have-list">
{authoritiesUserDoesNotHave
.sort((a, b) =>
(
Expand All @@ -77,7 +81,7 @@ export const AssignmentRestrictionWarning = ({
)
)
.map((auth) => (
<li key={auth.id}>
<li key={auth}>
{authorityIdToNameMap.get(auth) ?? auth}
</li>
))}
Expand All @@ -92,5 +96,6 @@ export const AssignmentRestrictionWarning = ({
AssignmentRestrictionWarning.propTypes = {
roleId: PropTypes.string.isRequired,
currentUser: PropTypes.object,
initiallyExpanded: PropTypes.bool,
roleAuthorities: PropTypes.arrayOf(PropTypes.string),
}
12 changes: 8 additions & 4 deletions src/components/RoleForm/LegacyAuthoritiesTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ const LegacyAuthoritiesTable = React.memo(
)
}
return (
<div className={styles.container}>
<div
className={styles.container}
data-test="legacy-authorities-table"
>
<DataTable scrollHeight="375px">
<DataTableHead>
<DataTableRow>
Expand Down Expand Up @@ -99,15 +102,16 @@ const LegacyAuthoritiesTableFF = ({
meta,
...props
}) => {
const { value: inputValue, onChange: inputOnChange } = input
const handleAuthorityRemove = useCallback(
({ id }) => {
const newSelectedAuthorities = new Set(input.value)
const newSelectedAuthorities = new Set(inputValue)
if (newSelectedAuthorities.has(id)) {
newSelectedAuthorities.delete(id)
}
input.onChange(newSelectedAuthorities)
inputOnChange(newSelectedAuthorities)
},
[input.value, input.onChange]
[inputValue, inputOnChange]
)

return (
Expand Down
7 changes: 4 additions & 3 deletions src/components/RoleForm/RoleForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { flatMap } from 'lodash-es'
import PropTypes from 'prop-types'
import React from 'react'
import { useHistory } from 'react-router-dom'
import { useCurrentUser } from '../../hooks/useCurrentUser.js'
import { useReferrerInfo } from '../../providers/index.js'
import { useCurrentUser, useReferrerInfo } from '../../providers/index.js'
import navigateTo from '../../utils/navigateTo.js'
import Form, { FormSection, TextField, TransferField } from '../Form.js'
import { AssignmentRestrictionWarning } from './AssignmentRestrictionsWarning.js'
Expand Down Expand Up @@ -56,7 +55,9 @@ const getRoleAuthorityIDs = ({
tracker: role.authorities.filter((id) => trackerIDs.has(id)),
importExport: role.authorities.filter((id) => importExportIDs.has(id)),
system: role.authorities.filter((id) => systemIDs.has(id)),
legacy: role.authorities.filter((id) => !allKnownIDs.has(id)).sort(),
legacy: role.authorities
.filter((id) => !allKnownIDs.has(id))
.sort((a, b) => a.localeCompare(b)),
}
}

Expand Down
Loading

0 comments on commit 326c865

Please sign in to comment.