Skip to content

Commit

Permalink
Adds onClear function for the bulk add modules dialog to prevent flic…
Browse files Browse the repository at this point in the history
…ker.
  • Loading branch information
mbusch3 committed Jun 8, 2023
1 parent 011bc41 commit fed9669
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const CollectionBulkAddModulesDialog = props => {

const handleAddClick = () => {
props.bulkAddModulesToCollection(props.selectedModules, selectedCollections)
props.onClose()
props.onClear()
}

const filterCollections = collection => {
Expand Down Expand Up @@ -58,7 +58,12 @@ const CollectionBulkAddModulesDialog = props => {
return (
<div className="collections-bulk-add-modules-dialog">
<div className="top-bar">
<div className="module-count">{props.selectedModules.length} Modules Selected</div>
<div className="module-count">
{props.selectedModules.length +
' Module' +
(props.selectedModules.length !== 1 ? 's' : '') +
' Selected'}
</div>
<Button ariaLabel="Close" className="close-button" onClick={props.onClose}>
×
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ describe('CollectionBulkAddModulesDialog', () => {
],
selectedModules: ['mockDraftId1', 'mockDraftId2'],
bulkAddModulesToCollection: jest.fn(),
onClose: jest.fn()
onClose: jest.fn(),
onClear: jest.fn()
}
})

Expand All @@ -49,6 +50,18 @@ describe('CollectionBulkAddModulesDialog', () => {
expect(component.root.findAllByType(Checkbox).length).toBe(3)
})

test('renders title for single module without an s', () => {
defaultProps.selectedModules = ['mockDraftId1']

let component
act(() => {
component = create(<CollectionBulkAddModulesDialog {...defaultProps} />)
})

const titleDiv = component.root.findByProps({ className: 'module-count' })
expect(titleDiv.children[0]).toBe('1 Module Selected')
})

test('renders collections with no title', () => {
defaultProps.collections = [
{
Expand Down Expand Up @@ -162,7 +175,8 @@ describe('CollectionBulkAddModulesDialog', () => {
clickAddButton(component)

expectAddCallbackCalledWith([])
expect(defaultProps.onClose).toHaveBeenCalledTimes(1)
expect(defaultProps.onClose).toHaveBeenCalledTimes(0)
expect(defaultProps.onClear).toHaveBeenCalledTimes(1)
})

test('the list of selected collections is modified appropriately when collections are clicked', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ const renderModalDialog = props => {
extendedProps.deleteModulePermissions = (draftId, userId) => {
props.deleteModulePermissions(draftId, userId, extendedOptions)
}
extendedProps.onClear = () => {
props.clearSelection()
}
extendedProps.onClose = () => {
props.clearSelection()
props.closeModal()
Expand Down Expand Up @@ -216,6 +219,7 @@ const renderCollectionBulkAddModulesDialog = (props, extension) => (
selectedModules={props.selectedModules}
bulkAddModulesToCollection={props.bulkAddModulesToCollection}
onClose={extension.onClose}
onClear={extension.onClear}
/>
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,6 @@ describe('Dashboard', () => {
dashboardProps.numPartialSelected = 1
dashboardProps.numMinimalSelected = 1
dashboardProps.deselectModules = jest.fn()
dashboardProps.clearSelection = jest.fn()

let component
act(() => {
Expand Down Expand Up @@ -1362,7 +1361,6 @@ describe('Dashboard', () => {
dashboardProps.multiSelectMode = true
dashboardProps.selectedModules = mockSelectedModules
dashboardProps.deselectModules = jest.fn()
dashboardProps.clearSelection = jest.fn()

dashboardProps.mode = MODE_COLLECTION
dashboardProps.collection = {
Expand Down Expand Up @@ -1410,7 +1408,6 @@ describe('Dashboard', () => {
dashboardProps.selectedModules = [standardMyModules[0], standardMyModules[1]]
dashboardProps.multiSelectMode = true
dashboardProps.deselectModules = jest.fn()
dashboardProps.clearSelection = jest.fn()
const reusableComponent = <Dashboard {...dashboardProps} />
let component
act(() => {
Expand Down Expand Up @@ -2031,6 +2028,24 @@ describe('Dashboard', () => {
component.unmount()
})

test('multi-module add dialog clears data but does not close when adding', () => {
dashboardProps.dialog = 'collection-bulk-add-modules'
dashboardProps.deselectModules = jest.fn()

let component
act(() => {
component = create(<Dashboard key="dashboardComponent" {...dashboardProps} />)
})

expectDialogToBeRendered(component, CollectionBulkAddModulesDialog, '')
const dialogComponent = component.root.findByType(CollectionBulkAddModulesDialog)
dialogComponent.children[0].props.onClear()
expect(dashboardProps.deselectModules).toHaveBeenCalledTimes(1)
expect(dashboardProps.closeModal).toHaveBeenCalledTimes(0)

component.unmount()
})

test('renders bulk success dialog and runs callbacks properly', () => {
dashboardProps.dialog = 'bulk-add-successful'

Expand Down Expand Up @@ -2199,7 +2214,6 @@ describe('Dashboard', () => {
test('restoreModules function gets called as expected', async () => {
const originalAlert = global.alert
global.alert = jest.fn()
dashboardProps.clearSelection = jest.fn()

const mockSelectedModules = [standardMyModules[0], standardMyModules[1]]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ModulePermissionsDialog extends React.Component {

if (
this.props.draftPermissions[this.props.draftId] !== null &&
// eslint-disable-next-line no-undefined
this.props.draftPermissions[this.props.draftId] !== undefined
) {
draftPermissions = this.props.draftPermissions[this.props.draftId].items
Expand Down

0 comments on commit fed9669

Please sign in to comment.