-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into stalenessKeys
- Loading branch information
Showing
10 changed files
with
186 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 122 additions & 3 deletions
125
src/components/InventoryGroups/Modals/CreateGroupModal.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,144 @@ | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { validateGroupName } from '../utils/api'; | ||
import { validate } from './CreateGroupModal'; | ||
import CreateGroupModal, { validate } from './CreateGroupModal'; | ||
import userEvent from '@testing-library/user-event'; | ||
import '@testing-library/jest-dom'; | ||
|
||
jest.mock('../utils/api'); | ||
jest.mock('react-redux'); | ||
|
||
describe('validate function', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('works with basic input', async () => { | ||
const result = await validate('test'); | ||
|
||
expect(result).toBe(undefined); | ||
expect(result).toBeUndefined(); | ||
expect(validateGroupName).toHaveBeenCalledWith('test'); | ||
}); | ||
|
||
it('trims input', async () => { | ||
const result = await validate(' test '); | ||
|
||
expect(result).toBe(undefined); | ||
expect(result).toBeUndefined(); | ||
expect(validateGroupName).toHaveBeenCalledWith('test'); | ||
}); | ||
|
||
it('throws error if the name is present', async () => { | ||
validateGroupName.mockResolvedValue(true); | ||
|
||
await expect(validate('test')).rejects.toBe('Group name already exists'); | ||
}); | ||
|
||
it('does not check on undefined input', async () => { | ||
const result = await validate(undefined); | ||
|
||
expect(result).toBeUndefined(); | ||
expect(validateGroupName).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('does not check on empty input', async () => { | ||
const result = await validate(''); | ||
|
||
expect(result).toBeUndefined(); | ||
expect(validateGroupName).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('create group modal', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const setIsModalOpen = jest.fn(); | ||
const reloadData = jest.fn(); | ||
|
||
it('create button is initially disabled', () => { | ||
render( | ||
<CreateGroupModal | ||
isModalOpen | ||
setIsModalOpen={setIsModalOpen} | ||
reloadData={reloadData} | ||
/> | ||
); | ||
|
||
expect( | ||
screen.getByRole('button', { | ||
name: /create/i, | ||
}) | ||
).toBeDisabled(); | ||
}); | ||
|
||
it('can create a group with new name', async () => { | ||
validateGroupName.mockResolvedValue(false); | ||
|
||
render( | ||
<CreateGroupModal | ||
isModalOpen | ||
setIsModalOpen={setIsModalOpen} | ||
reloadData={reloadData} | ||
/> | ||
); | ||
|
||
await userEvent.type( | ||
screen.getByRole('textbox', { | ||
name: /group name/i, | ||
}), | ||
'_abc' | ||
); | ||
|
||
await waitFor(() => { | ||
expect( | ||
screen.getByRole('button', { | ||
name: /create/i, | ||
}) | ||
).toBeEnabled(); | ||
}); | ||
}); | ||
|
||
it('cannot create a group with incorrect name', async () => { | ||
render( | ||
<CreateGroupModal | ||
isModalOpen | ||
setIsModalOpen={setIsModalOpen} | ||
reloadData={reloadData} | ||
/> | ||
); | ||
|
||
expect( | ||
screen.getByRole('button', { | ||
name: /create/i, | ||
}) | ||
).toBeDisabled(); | ||
|
||
await userEvent.type( | ||
screen.getByRole('textbox', { | ||
name: /group name/i, | ||
}), | ||
'###' | ||
); | ||
|
||
expect( | ||
screen.getByRole('button', { | ||
name: /create/i, | ||
}) | ||
).toBeDisabled(); | ||
|
||
await userEvent.click( | ||
screen.getByRole('button', { | ||
name: /create/i, | ||
}) | ||
); // must change focus for the hint to appear (DDF implementation) | ||
|
||
await waitFor(() => { | ||
expect( | ||
screen.getByText( | ||
'Valid characters include letters, numbers, spaces, hyphens ( - ), and underscores ( _ ).' | ||
) | ||
).toBeVisible(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useEffect, useState } from 'react'; | ||
import useFeatureFlag from '../../Utilities/useFeatureFlag'; | ||
import useChrome from '@redhat-cloud-services/frontend-components/useChrome'; | ||
|
||
const useGlobalFilter = () => { | ||
const chrome = useChrome(); | ||
const edgeParityFilterDeviceEnabled = useFeatureFlag( | ||
'edgeParity.inventory-list-filter' | ||
); | ||
const [globalFilter, setGlobalFilter] = useState(); | ||
|
||
useEffect(() => { | ||
chrome.hideGlobalFilter(false); | ||
const unlisten = chrome.on('GLOBAL_FILTER_UPDATE', ({ data }) => { | ||
const [workloads, SID, tags] = chrome.mapGlobalFilter(data, false, true); | ||
|
||
setGlobalFilter({ | ||
tags, | ||
filter: { | ||
...globalFilter?.filter, | ||
system_profile: { | ||
...globalFilter?.filter?.system_profile, | ||
...(workloads?.SAP?.isSelected && { sap_system: true }), | ||
...(workloads && | ||
workloads['Ansible Automation Platform']?.isSelected && { | ||
ansible: 'not_nil', | ||
}), | ||
...(workloads?.['Microsoft SQL']?.isSelected && { | ||
mssql: 'not_nil', | ||
}), | ||
...(edgeParityFilterDeviceEnabled && { host_type: 'nil' }), | ||
...(SID?.length > 0 && { sap_sids: SID }), | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
return () => unlisten(); | ||
}, [edgeParityFilterDeviceEnabled]); | ||
|
||
return globalFilter; | ||
}; | ||
|
||
export default useGlobalFilter; |