forked from janus-idp/backstage-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rbac): enable save on remove-all button click (janus-idp#1712)
- Loading branch information
1 parent
d56f4af
commit 0502332
Showing
7 changed files
with
127 additions
and
19 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
79 changes: 79 additions & 0 deletions
79
plugins/rbac/src/components/ConditionalAccess/ConditionsForm.test.tsx
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,79 @@ | ||
import React from 'react'; | ||
|
||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
|
||
import { mockTransformedConditionRules } from '../../__fixtures__/mockTransformedConditionRules'; | ||
import { ConditionsForm } from './ConditionsForm'; | ||
|
||
describe('ConditionsForm', () => { | ||
const selPluginResourceType = 'catalog-entity'; | ||
const onSaveMock = jest.fn(); | ||
const onCloseMock = jest.fn(); | ||
|
||
const renderComponent = (props = {}) => | ||
render( | ||
<ConditionsForm | ||
selPluginResourceType={selPluginResourceType} | ||
conditionRulesData={ | ||
mockTransformedConditionRules.catalog['catalog-entity'] | ||
} | ||
onClose={onCloseMock} | ||
onSave={onSaveMock} | ||
{...props} | ||
/>, | ||
); | ||
|
||
beforeEach(() => { | ||
onSaveMock.mockClear(); | ||
onCloseMock.mockClear(); | ||
}); | ||
|
||
it('renders without crashing', () => { | ||
const { getByTestId } = renderComponent(); | ||
expect(getByTestId('conditions-row')).toBeInTheDocument(); | ||
expect(getByTestId('save-conditions')).toBeInTheDocument(); | ||
expect(getByTestId('cancel-conditions')).toBeInTheDocument(); | ||
expect(getByTestId('remove-conditions')).toBeInTheDocument(); | ||
}); | ||
|
||
it('calls onClose when Cancel button is clicked', () => { | ||
const { getByTestId } = renderComponent(); | ||
fireEvent.click(getByTestId('cancel-conditions')); | ||
expect(onCloseMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('resets conditions data when Remove all button is clicked', () => { | ||
const { getByTestId } = renderComponent({ | ||
conditionsFormVal: { | ||
condition: { | ||
rule: 'HAS_LABEL', | ||
resourceType: selPluginResourceType, | ||
params: {}, | ||
}, | ||
}, | ||
}); | ||
|
||
fireEvent.click(getByTestId('remove-conditions')); | ||
fireEvent.click(getByTestId('save-conditions')); | ||
|
||
expect(onSaveMock).toHaveBeenCalledWith(undefined); | ||
}); | ||
|
||
it('disables Save button if conditions are unchanged', () => { | ||
const { getByTestId } = renderComponent(); | ||
expect(getByTestId('save-conditions')).toBeDisabled(); | ||
}); | ||
|
||
it('disables Save button if no rule is selected', () => { | ||
const { getByTestId } = renderComponent(); | ||
|
||
fireEvent.change( | ||
screen.getByRole('textbox', { | ||
name: /rule/i, | ||
}), | ||
{ target: { value: '' } }, | ||
); | ||
|
||
expect(getByTestId('save-conditions')).toBeDisabled(); | ||
}); | ||
}); |
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