Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ import ABSGeoIpFormGroup from './ABSGeoIpFormGroup';

describe('ABSGeoIpFormGroup', () => {
const newConfig = {
enabled: true,
azure_container: '',
azure_account: '',
azure_endpoint: '',
azure_account_key: { set_value: '' },
} as Partial<GeoIpConfigType>;

const existingConfig = {
enabled: true,
azure_container: 'my-container',
azure_account: 'my-account',
azure_endpoint: 'https://myaccount.blob.core.windows.net',
Expand Down Expand Up @@ -81,6 +83,15 @@ describe('ABSGeoIpFormGroup', () => {
});
});

it('disables all fields when the resolver is not enabled', async () => {
renderComponent({ ...newConfig, enabled: false });

expect(await screen.findByLabelText(/azure blob container name/i)).toBeDisabled();
expect(screen.getByLabelText(/azure blob endpoint url/i)).toBeDisabled();
expect(screen.getByLabelText(/azure account name/i)).toBeDisabled();
expect(screen.getByTestId('azure-account-key-input')).toBeDisabled();
});

it('updates formik values correctly', async () => {
render(
<Formik initialValues={existingConfig as GeoIpConfigType} onSubmit={jest.fn()}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const ABSGeoIpFormGroup = () => {
help="Your Azure Blob Container name."
labelClassName=""
required
disabled={!values.enabled}
wrapperClassName=""
/>
<FormikFormGroup
Expand All @@ -70,6 +71,7 @@ const ABSGeoIpFormGroup = () => {
label="Azure Blob Endpoint URL"
help="Your Azure Blob Endpoint URL, only required if you want to override the default endpoint."
labelClassName=""
disabled={!values.enabled}
wrapperClassName=""
/>
<FormikFormGroup
Expand All @@ -79,12 +81,15 @@ const ABSGeoIpFormGroup = () => {
placeholder="your-account-name"
help="The name of your Azure storage account."
required
disabled={!values.enabled}
labelClassName=""
wrapperClassName=""
/>
{showResetPasswordButton ? (
<Input id="azure_account_reset" label="Azure Account Key" labelClassName="col-sm-3" wrapperClassName="col-sm-9">
<Button onClick={toggleAccountKeyReset}>Reset password</Button>
<Button onClick={toggleAccountKeyReset} disabled={!values.enabled}>
Reset password
</Button>
</Input>
) : (
<Input
Expand All @@ -93,10 +98,11 @@ const ABSGeoIpFormGroup = () => {
data-testid="azure-account-key-input"
type="password"
label="Azure account key"
disabled={!values.enabled}
onChange={({ target: { value } }) => setAccessKey({ set_value: value })}
buttonAfter={
!isCreate ? (
<Button type="button" onClick={toggleAccountKeyReset}>
<Button type="button" onClick={toggleAccountKeyReset} disabled={!values.enabled}>
Undo Reset
</Button>
) : undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const GCSGeoIpFormGroup = () => {
disabled={!values.enabled}
label={
<>
Googe Cloud Storage Project ID <InputOptionalInfo />
Google Cloud Storage Project ID <InputOptionalInfo />
</>
}
name="gcs_project_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('GeoIpResolverConfig', () => {

expect(
screen.getByRole('textbox', {
name: /googe cloud storage project id \(opt\.\)/i,
name: /google cloud storage project id \(opt\.\)/i,
}),
).toBeInTheDocument();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,11 @@ const GeoIpResolverConfig = ({ config = defaultConfig, updateConfig }: Props) =>
onChange={(option) => {
setFieldValue('pull_from_cloud', option);

if (option !== CLOUD_STORAGE_OPTION.GCS) {
setFieldValue('gcs_project_id', undefined);
}
setFieldValue('gcs_project_id', undefined);
setFieldValue('azure_endpoint', undefined);
setFieldValue('azure_account_key', undefined);
setFieldValue('azure_account', undefined);
setFieldValue('azure_container', undefined);
}}
/>
</Input>
Expand Down
Loading