Add more test automation. Refs #40

- Make activation key input field required

- Registration step in CreateImageWizard
  - should allow choosing activation keys
  - should hide input fields when clicking Register the system later
This commit is contained in:
Aleksandar Todorov 2020-11-09 15:55:24 +02:00 committed by Sanne Raymaekers
parent 68954d854b
commit f01568c263
2 changed files with 39 additions and 1 deletions

View file

@ -145,6 +145,7 @@ const SubscriptionComponent = (props) => {
helperTextInvalid={ (props.errors['subscription-activation'] && props.errors['subscription-activation'].value) || '' }
validated={ (props.errors['subscription-activation'] && 'error') || 'default' }>
<TextInput value={ props.subscription['activation-key'] || '' } type="password"
data-testid="subscription-activation" isRequired
id="subscription-activation" aria-label="Subscription activation key"
onChange={ value => props.setSubscription(Object.assign(props.subscription, { 'activation-key': value })) } />
</FormGroup>

View file

@ -1,7 +1,7 @@
import '@testing-library/jest-dom';
import React from 'react';
import { screen, getByText, waitFor } from '@testing-library/react';
import { screen, getByText, waitFor, waitForElementToBeRemoved } from '@testing-library/react';
import { renderWithReduxRouter } from '../../testUtils';
import CreateImageWizard from '../../../SmartComponents/CreateImageWizard/CreateImageWizard';
@ -142,6 +142,43 @@ describe('Step Registration', () => {
const [ , , cancel ] = verifyButtons();
verifyCancelButton(cancel);
});
test('should allow choosing activation keys', () => {
screen
.getByLabelText('Embed an activation key and register systems on first boot')
.click();
const organizationId = screen.getByLabelText('Organization ID');
expect(organizationId).not.toHaveValue();
expect(organizationId).toBeDisabled();
// can't getByLabelText b/c the label contains an extra <span>
// with a `*` to denote required
const activationKey = screen.getByTestId('subscription-activation');
expect(activationKey).toHaveValue('');
expect(activationKey).toBeEnabled();
expect(activationKey).toBeRequired();
});
test('should hide input fields when clicking Register the system later', async () => {
// first check the other radio button which causes extra widgets to be shown
screen
.getByLabelText('Embed an activation key and register systems on first boot')
.click();
// then click the first radio button which should remove any input fields
screen
.getByLabelText('Register the system later')
.click();
waitForElementToBeRemoved(screen.queryByLabelText('Organization ID')).then(() =>
expect(screen.queryByLabelText('Organization ID')).not.toBeInTheDocument()
);
waitForElementToBeRemoved(screen.queryByTestId('subscription-activation')).then(() =>
expect(screen.queryByTestId('subscription-activation')).not.toBeInTheDocument()
);
});
});
describe('Step Review', () => {