-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #36576 - Fix errors and bugs in edit modal, add tests
- Loading branch information
Trevor Allison
committed
Jul 24, 2023
1 parent
da24d9d
commit 9c33b9a
Showing
8 changed files
with
197 additions
and
26 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
22 changes: 22 additions & 0 deletions
22
webpack/scenes/ActivationKeys/Details/ActivationKeyDetailsHelpers.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { propsToCamelCase } from 'foremanReact/common/helpers'; | ||
|
||
export const REMOTE_EXECUTION = 'remoteExecution'; | ||
export const KATELLO_AGENT = 'katelloAgent'; | ||
|
||
|
||
export const akIsNotRegistered = ({ akDetails }) => { | ||
const { | ||
purpose_usage: purposeUsage, | ||
purpose_role: purposeRole, | ||
release_version: releaseVersion, | ||
service_level: serviceLevel, | ||
} = akDetails; | ||
return !purposeUsage?.uuid; | ||
}; | ||
|
||
export const akIsRegistered = ({ akDetails }) => !akIsNotRegistered({ akDetails }); | ||
|
||
export const akHasRequiredPermissions = (requiredPermissions = [], userPermissions = {}) => { | ||
const permittedActions = Object.keys(userPermissions).filter(key => userPermissions[key]); | ||
return requiredPermissions.every(permission => permittedActions.includes(permission)); | ||
}; |
16 changes: 16 additions & 0 deletions
16
webpack/scenes/ActivationKeys/Details/ActivationKeyDetailsSelectors.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { | ||
selectAPIStatus, | ||
selectAPIError, | ||
selectAPIResponse, | ||
} from 'foremanReact/redux/API/APISelectors'; | ||
import { STATUS } from 'foremanReact/constants'; | ||
import { ACTIVATION_KEY } from './ActivationKeyConstants'; | ||
|
||
export const selectAKDetails = state => | ||
selectAPIResponse(state, ACTIVATION_KEY) ?? {}; | ||
|
||
export const selectAKDetailsStatus = state => | ||
selectAPIStatus(state, ACTIVATION_KEY) ?? STATUS.PENDING; | ||
|
||
export const selectAKDetailsError = state => | ||
selectAPIError(state, ACTIVATION_KEY); |
117 changes: 117 additions & 0 deletions
117
webpack/scenes/ActivationKeys/Details/__tests__/activationKeyDetails.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 |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import React from 'react'; | ||
import { renderWithRedux, patientlyWaitFor, fireEvent } from 'react-testing-lib-wrapper'; | ||
import { assertNockRequest, nockInstance } from '../../../../test-utils/nockWrapper'; | ||
import ActivationKeyDetails from '../ActivationKeyDetails'; | ||
import katelloApi from '../../../../services/api/index'; | ||
|
||
const akDetails = katelloApi.getApiUrl('/activation_keys/1'); | ||
|
||
const baseAKDetails = { | ||
id: 1, | ||
name: 'test', | ||
description: 'test description', | ||
unlimited_hosts: false, | ||
usage_count: 1, | ||
max_hosts: 4, | ||
}; | ||
|
||
const renderOptions = { | ||
initialState: { | ||
// This is the API state that your tests depend on for their data | ||
// You can cross reference the needed useSelectors from your tested components | ||
// with the data found within the redux chrome add-on to help determine this fixture data. | ||
katello: { | ||
hostDetails: {}, | ||
}, | ||
}, | ||
}; | ||
|
||
test('Makes API call and displays AK details on screen', async (done) => { | ||
const akScope = nockInstance | ||
.get(akDetails) | ||
.reply(200, baseAKDetails); | ||
// eslint-disable-next-line max-len | ||
const { getByText, getByRole } = renderWithRedux(<ActivationKeyDetails match={{ params: { id: '1' } }} />, renderOptions); | ||
await patientlyWaitFor(() => expect(getByRole('heading', { name: 'test' })).toBeInTheDocument()); | ||
expect(getByText('test description')).toBeInTheDocument(); | ||
expect(getByText('1/4')).toBeInTheDocument(); | ||
|
||
assertNockRequest(akScope, done); | ||
}); | ||
|
||
test('Displays placeholder when description is missing', async (done) => { | ||
const akScope = nockInstance | ||
.get(akDetails) | ||
.reply( | ||
200, | ||
{ | ||
...baseAKDetails, | ||
description: '', | ||
}, | ||
); | ||
// eslint-disable-next-line max-len | ||
const { getByText, getByRole } = renderWithRedux(<ActivationKeyDetails match={{ params: { id: '1' } }} />, renderOptions); | ||
await patientlyWaitFor(() => expect(getByRole('heading', { name: 'test' })).toBeInTheDocument()); | ||
expect(getByText('No description provided')).toBeInTheDocument(); | ||
|
||
assertNockRequest(akScope, done); | ||
}); | ||
|
||
test('Delete menu appears when toggle is clicked', async (done) => { | ||
const akScope = nockInstance | ||
.get(akDetails) | ||
.reply(200, baseAKDetails); | ||
// eslint-disable-next-line max-len | ||
const { getByText, getByLabelText } = renderWithRedux(<ActivationKeyDetails match={{ params: { id: '1' } }} />, renderOptions); | ||
const deleteToggle = getByLabelText('delete-toggle'); | ||
fireEvent.click(deleteToggle); | ||
await patientlyWaitFor(() => expect(getByText('Delete')).toBeInTheDocument()); | ||
|
||
assertNockRequest(akScope, done); | ||
}); | ||
|
||
test('Edit modal appears when button is clicked', async (done) => { | ||
const akScope = nockInstance | ||
.get(akDetails) | ||
.reply(200, baseAKDetails); | ||
const { getByLabelText, getByText } = renderWithRedux(<ActivationKeyDetails match={{ params: { id: '1' } }} />, renderOptions); | ||
const editButton = getByLabelText('edit-button'); | ||
fireEvent.click(editButton); | ||
await patientlyWaitFor(() => expect(getByText('Edit activation key')).toBeInTheDocument()); | ||
|
||
assertNockRequest(akScope, done); | ||
}); | ||
|
||
test('Page displays 0 when usage count is null', async (done) => { | ||
const akScope = nockInstance | ||
.get(akDetails) | ||
.reply( | ||
200, | ||
{ | ||
...baseAKDetails, | ||
usage_count: null, | ||
}, | ||
); | ||
|
||
const { getByText, getByRole } = renderWithRedux(<ActivationKeyDetails match={{ params: { id: '1' } }} />, renderOptions); | ||
await patientlyWaitFor(() => expect(getByRole('heading', { name: 'test' })).toBeInTheDocument()); | ||
expect(getByText('0/4')).toBeInTheDocument(); | ||
|
||
assertNockRequest(akScope, done); | ||
}); | ||
|
||
test('Delete modal appears when link is clicked', async (done) => { | ||
const akScope = nockInstance | ||
.get(akDetails) | ||
.reply(200, baseAKDetails); | ||
// eslint-disable-next-line max-len | ||
const { getByText, getByLabelText } = renderWithRedux(<ActivationKeyDetails match={{ params: { id: '1' } }} />, renderOptions); | ||
const deleteToggle = getByLabelText('delete-toggle'); | ||
fireEvent.click(deleteToggle); | ||
await patientlyWaitFor(() => expect(getByText('Delete')).toBeInTheDocument()); | ||
const deleteLink = getByLabelText('delete-link'); | ||
fireEvent.click(deleteLink); | ||
await patientlyWaitFor(() => expect(getByText('Activation Key will no longer be available for use. This operation cannot be undone.')).toBeInTheDocument()); | ||
|
||
assertNockRequest(akScope, done); | ||
}); |
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