Skip to content

Commit

Permalink
UIEUS-297-possible-to-set-RequestorId-and-ApiKey (#373)
Browse files Browse the repository at this point in the history
* UIEUS-297-possible-to-set-RequestorId-and-ApiKey

* UIEUS-297-possible-to-set-RequestorId-and-ApiKey adapt tests

* UIEUS-297-possible-to-set-RequestorId-and-ApiKey disable api for counter 4

Co-authored-by: elsenhans <[email protected]>
  • Loading branch information
elsenhans and elsenhans authored Jun 27, 2022
1 parent e1c0ec0 commit 5ededee
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ const SushiCredentialsForm = (props) => {
const { useAggregator, values, form } = props;
const intl = useIntl();

const isDisableRequestorId = !!(values.harvestingConfig?.reportRelease === 5 && values.sushiCredentials?.apiKey);

const isDisableApiKey = !!(values.harvestingConfig?.reportRelease === 4 ||
(values.harvestingConfig?.reportRelease === 5 && values.sushiCredentials?.requestorId));
const isDisableApiKey = values.harvestingConfig?.reportRelease === 4;

return (
<React.Fragment>
Expand Down Expand Up @@ -41,11 +38,9 @@ const SushiCredentialsForm = (props) => {
id: 'ui-erm-usage.udp.form.placeholder.sushi.requestorId',
})}
component={TextField}
disabled={isDisableRequestorId}
fullWidth
onChange={(e) => {
form.change(e.target.name, e.target.value);
if (isDisableApiKey) form.change('sushiCredentials.apiKey', undefined);
}}
/>
</Col>
Expand All @@ -62,7 +57,6 @@ const SushiCredentialsForm = (props) => {
fullWidth
onChange={(e) => {
form.change(e.target.name, e.target.value);
if (isDisableRequestorId) form.change('sushiCredentials.requestorId', undefined);
}}
/>
</Col>
Expand Down
11 changes: 3 additions & 8 deletions src/components/views/UDPForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,21 +483,16 @@ describe('UDPForm', () => {
const testSelectReportRelease = (reportRelease) => {
renderUDPForm(stripes, reportReleaseProvider);
const reqIdBox = screen.getByRole('textbox', { name: 'Requestor ID' });
const apiKeyBox = screen.getByRole('textbox', { name: 'API key' });
// const apiKeyBox = screen.getByRole('textbox', { name: 'API key' });
const releaseSelectBox = screen.getByLabelText('Report release', { exact: false });

expect(reqIdBox).not.toBeDisabled();
expect(reqIdBox.value).toBe('id1234');
expect(apiKeyBox).not.toBeDisabled();
expect(apiKeyBox.value).toBe('key1234');

userEvent.selectOptions(releaseSelectBox, reportRelease.toString());

expect(releaseSelectBox.value).toBe(reportRelease.toString());
expect(reqIdBox).not.toBeDisabled();
expect(reqIdBox.value).toBe('id1234');
expect(apiKeyBox.value).toBe('');
expect(apiKeyBox).toBeDisabled();
};

test('select reportRelease 4', async () => {
Expand All @@ -518,13 +513,13 @@ describe('UDPForm', () => {

userEvent.type(reqIdBox, 'a');
expect(reqIdBox.value).toBe('a');
expect(apiKeyBox).toBeDisabled();
expect(apiKeyBox).not.toBeDisabled();
userEvent.clear(reqIdBox);
expect(apiKeyBox).not.toBeDisabled();

userEvent.type(apiKeyBox, 'a');
expect(apiKeyBox.value).toBe('a');
expect(reqIdBox).toBeDisabled();
expect(reqIdBox).not.toBeDisabled();
userEvent.clear(apiKeyBox);
expect(reqIdBox).not.toBeDisabled();
});
Expand Down

0 comments on commit 5ededee

Please sign in to comment.