test: Cleanup tests a bit
This commit is contained in:
parent
5cc5dd1258
commit
ca9d3035ee
2 changed files with 118 additions and 105 deletions
|
|
@ -10,30 +10,6 @@ const getSourceDropdown = async () => {
|
|||
return sourceDropdown;
|
||||
};
|
||||
|
||||
export const addTargetEnvAzure = async () => {
|
||||
const user = userEvent.setup();
|
||||
expect(
|
||||
await screen.findByRole('radio', {
|
||||
name: /use an account configured from sources\./i,
|
||||
})
|
||||
).toHaveFocus();
|
||||
const azureSourceDropdown = await getSourceDropdown();
|
||||
await waitFor(() => user.click(azureSourceDropdown));
|
||||
const azureSource = await screen.findByRole('option', {
|
||||
name: /azureSource1/i,
|
||||
});
|
||||
await waitFor(() => user.click(azureSource));
|
||||
|
||||
const resourceGroupDropdown = await screen.findByPlaceholderText(
|
||||
/select resource group/i
|
||||
);
|
||||
await waitFor(() => user.click(resourceGroupDropdown));
|
||||
await waitFor(async () =>
|
||||
user.click(await screen.findByLabelText('Resource group myResourceGroup1'))
|
||||
);
|
||||
await clickNext();
|
||||
};
|
||||
|
||||
const selectAllEnvironments = async () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
|
|
@ -134,7 +110,28 @@ describe('Keyboard accessibility', () => {
|
|||
await clickNext();
|
||||
|
||||
// Target environment azure
|
||||
await addTargetEnvAzure();
|
||||
expect(
|
||||
await screen.findByRole('radio', {
|
||||
name: /use an account configured from sources\./i,
|
||||
})
|
||||
).toHaveFocus();
|
||||
const azureSourceDropdown = await getSourceDropdown();
|
||||
await waitFor(() => user.click(azureSourceDropdown));
|
||||
const azureSource = await screen.findByRole('option', {
|
||||
name: /azureSource1/i,
|
||||
});
|
||||
await waitFor(() => user.click(azureSource));
|
||||
|
||||
const resourceGroupDropdown = await screen.findByPlaceholderText(
|
||||
/select resource group/i
|
||||
);
|
||||
await waitFor(() => user.click(resourceGroupDropdown));
|
||||
await waitFor(async () =>
|
||||
user.click(
|
||||
await screen.findByLabelText('Resource group myResourceGroup1')
|
||||
)
|
||||
);
|
||||
await clickNext();
|
||||
|
||||
// Registration
|
||||
await screen.findByText(
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import { userEvent } from '@testing-library/user-event';
|
|||
import { CREATE_BLUEPRINT, EDIT_BLUEPRINT } from '../../../../../constants';
|
||||
import { mockBlueprintIds } from '../../../../fixtures/blueprints';
|
||||
import { usersCreateBlueprintRequest } from '../../../../fixtures/editMode';
|
||||
import { addTargetEnvAzure } from '../../CreateImageWizard.test';
|
||||
import {
|
||||
blueprintRequest,
|
||||
clickBack,
|
||||
|
|
@ -14,28 +13,29 @@ import {
|
|||
getNextButton,
|
||||
interceptBlueprintRequest,
|
||||
interceptEditBlueprintRequest,
|
||||
openAndDismissSaveAndBuildModal,
|
||||
renderEditMode,
|
||||
selectGuestImageTarget,
|
||||
verifyCancelButton,
|
||||
} from '../../wizardTestUtils';
|
||||
import {
|
||||
clickRegisterLater,
|
||||
goToRegistrationStep,
|
||||
renderCreateMode,
|
||||
} from '../../wizardTestUtils';
|
||||
import { clickRegisterLater, renderCreateMode } from '../../wizardTestUtils';
|
||||
|
||||
let router: RemixRouter | undefined = undefined;
|
||||
|
||||
const validUserName = 'best';
|
||||
const validSshKey = 'ssh-rsa d';
|
||||
const validPassword = 'validPassword';
|
||||
const invalidPassword = 'inval';
|
||||
|
||||
const goToUsersStep = async () => {
|
||||
await clickNext();
|
||||
await clickNext();
|
||||
await clickNext();
|
||||
await clickNext();
|
||||
await clickNext();
|
||||
await clickNext();
|
||||
await clickNext(); // Registration
|
||||
await clickRegisterLater();
|
||||
await clickNext(); // OpenSCAP
|
||||
await clickNext(); // File system configuration
|
||||
await clickNext(); // Snapshots
|
||||
await clickNext(); // Custom repositories
|
||||
await clickNext(); // Additional packages
|
||||
await clickNext(); // Users
|
||||
};
|
||||
|
||||
const goToReviewStep = async () => {
|
||||
|
|
@ -51,6 +51,29 @@ const goToReviewStep = async () => {
|
|||
await clickNext(); // Review
|
||||
};
|
||||
|
||||
const addAzureTarget = async () => {
|
||||
const user = userEvent.setup();
|
||||
await waitFor(() => user.click(screen.getByTestId('upload-azure')));
|
||||
await clickNext();
|
||||
|
||||
const azureSourceDropdown = await screen.findByPlaceholderText(
|
||||
/select source/i
|
||||
);
|
||||
await waitFor(() => user.click(azureSourceDropdown));
|
||||
const azureSource = await screen.findByRole('option', {
|
||||
name: /azureSource1/i,
|
||||
});
|
||||
await waitFor(() => user.click(azureSource));
|
||||
|
||||
const resourceGroupDropdown = await screen.findByPlaceholderText(
|
||||
/select resource group/i
|
||||
);
|
||||
await waitFor(() => user.click(resourceGroupDropdown));
|
||||
await waitFor(async () =>
|
||||
user.click(await screen.findByLabelText('Resource group myResourceGroup1'))
|
||||
);
|
||||
};
|
||||
|
||||
const clickRevisitButton = async () => {
|
||||
const user = userEvent.setup();
|
||||
const expandable = await screen.findByTestId('users-expandable');
|
||||
|
|
@ -140,22 +163,19 @@ describe('Step Users', () => {
|
|||
router = undefined;
|
||||
});
|
||||
|
||||
test('without adding user loads timezone', async () => {
|
||||
const user = userEvent.setup();
|
||||
test('clicking Next loads Timezone', async () => {
|
||||
await renderCreateMode();
|
||||
await goToRegistrationStep();
|
||||
await clickRegisterLater();
|
||||
await selectGuestImageTarget();
|
||||
await goToUsersStep();
|
||||
const nextButton = await getNextButton();
|
||||
expect(nextButton).toBeEnabled();
|
||||
await waitFor(() => user.click(nextButton));
|
||||
await screen.findByText('Select a timezone for your image.');
|
||||
await clickNext();
|
||||
await screen.findByRole('heading', {
|
||||
name: 'Timezone',
|
||||
});
|
||||
});
|
||||
|
||||
test('clicking Back loads Additional packages', async () => {
|
||||
await renderCreateMode();
|
||||
await goToRegistrationStep();
|
||||
await clickRegisterLater();
|
||||
await selectGuestImageTarget();
|
||||
await goToUsersStep();
|
||||
await clickBack();
|
||||
await screen.findByRole('heading', { name: 'Additional packages' });
|
||||
|
|
@ -163,56 +183,34 @@ describe('Step Users', () => {
|
|||
|
||||
test('clicking Cancel loads landing page', async () => {
|
||||
await renderCreateMode();
|
||||
await selectGuestImageTarget();
|
||||
await goToUsersStep();
|
||||
await verifyCancelButton(router);
|
||||
});
|
||||
|
||||
test('revisit step button on Review works', async () => {
|
||||
await renderCreateMode();
|
||||
await goToRegistrationStep();
|
||||
await clickRegisterLater();
|
||||
await goToUsersStep();
|
||||
await clickAddUser();
|
||||
await addUserName(validUserName);
|
||||
await addSshKey(validSshKey);
|
||||
const nextButton = await getNextButton();
|
||||
await waitFor(() => expect(nextButton).toBeEnabled());
|
||||
await goToReviewStep();
|
||||
await clickRevisitButton();
|
||||
await screen.findByRole('heading', { name: /Users/ });
|
||||
});
|
||||
|
||||
test('with invalid name', async () => {
|
||||
await renderCreateMode();
|
||||
await goToRegistrationStep();
|
||||
await clickRegisterLater();
|
||||
await selectGuestImageTarget();
|
||||
await goToUsersStep();
|
||||
await clickAddUser();
|
||||
await addUserName('ss.');
|
||||
await addSshKey('ssh');
|
||||
const invalidUserMessage = screen.getByText(/invalid user name/i);
|
||||
await waitFor(() => expect(invalidUserMessage));
|
||||
});
|
||||
|
||||
test('with invalid ssh key', async () => {
|
||||
await renderCreateMode();
|
||||
await goToRegistrationStep();
|
||||
await clickRegisterLater();
|
||||
await goToUsersStep();
|
||||
await clickAddUser();
|
||||
await addSshKey('ssh');
|
||||
await addUserName('bestUser');
|
||||
const invalidUserMessage = screen.getByText(/invalid ssh key/i);
|
||||
await waitFor(() => expect(invalidUserMessage));
|
||||
});
|
||||
|
||||
test('try to create Azure image with invalid password', async () => {
|
||||
const user = userEvent.setup();
|
||||
await renderCreateMode();
|
||||
await waitFor(() => user.click(screen.getByTestId('upload-azure')));
|
||||
await addUserName('.');
|
||||
await clickNext();
|
||||
await addTargetEnvAzure();
|
||||
await clickRegisterLater();
|
||||
await waitFor(() => expect(screen.getByText(/invalid user name/i)));
|
||||
});
|
||||
|
||||
test('with invalid SSH key', async () => {
|
||||
await renderCreateMode();
|
||||
await selectGuestImageTarget();
|
||||
await goToUsersStep();
|
||||
await clickAddUser();
|
||||
await addSshKey('ssh');
|
||||
await clickNext();
|
||||
await waitFor(() => expect(screen.getByText(/invalid ssh key/i)));
|
||||
});
|
||||
|
||||
test('Azure target with invalid password', async () => {
|
||||
await renderCreateMode();
|
||||
await addAzureTarget();
|
||||
await goToUsersStep();
|
||||
await clickAddUser();
|
||||
await addUserName(validUserName);
|
||||
|
|
@ -226,14 +224,14 @@ describe('Step Users', () => {
|
|||
);
|
||||
await waitFor(() => expect(invalidUserMessage));
|
||||
await waitFor(() => expect(warningUserMessage));
|
||||
|
||||
const nextButton = await getNextButton();
|
||||
await waitFor(() => expect(nextButton).toBeDisabled());
|
||||
});
|
||||
|
||||
test('with invalid password', async () => {
|
||||
await renderCreateMode();
|
||||
await goToRegistrationStep();
|
||||
await clickRegisterLater();
|
||||
await selectGuestImageTarget();
|
||||
await goToUsersStep();
|
||||
await clickAddUser();
|
||||
await addUserName(validUserName);
|
||||
|
|
@ -243,14 +241,14 @@ describe('Step Users', () => {
|
|||
/Password must be at least 6 characters long/i
|
||||
);
|
||||
await waitFor(() => expect(invalidUserMessage));
|
||||
|
||||
const nextButton = await getNextButton();
|
||||
await waitFor(() => expect(nextButton).toBeDisabled());
|
||||
});
|
||||
|
||||
test('user groups can be added and removed', async () => {
|
||||
await renderCreateMode();
|
||||
await goToRegistrationStep();
|
||||
await clickRegisterLater();
|
||||
await selectGuestImageTarget();
|
||||
await goToUsersStep();
|
||||
await clickAddUser();
|
||||
await addUserGroup('users');
|
||||
|
|
@ -261,8 +259,7 @@ describe('Step Users', () => {
|
|||
|
||||
test('adding wheel group checks Administrator checkbox', async () => {
|
||||
await renderCreateMode();
|
||||
await goToRegistrationStep();
|
||||
await clickRegisterLater();
|
||||
await selectGuestImageTarget();
|
||||
await goToUsersStep();
|
||||
await clickAddUser();
|
||||
const adminCheckbox = await getAdminCheckbox();
|
||||
|
|
@ -283,38 +280,55 @@ describe('Step Users', () => {
|
|||
expect(adminCheckbox).not.toBeChecked();
|
||||
expect(screen.queryByText('wheel')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('revisit step button on Review works', async () => {
|
||||
await renderCreateMode();
|
||||
await selectGuestImageTarget();
|
||||
await goToUsersStep();
|
||||
await clickAddUser();
|
||||
await addUserName(validUserName);
|
||||
await goToReviewStep();
|
||||
await clickRevisitButton();
|
||||
await screen.findByRole('heading', { name: /Users/ });
|
||||
});
|
||||
});
|
||||
|
||||
describe('User request generated correctly', () => {
|
||||
test('create image with valid name, password, ssh key and checked Administrator checkbox', async () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
test('add a user', async () => {
|
||||
await renderCreateMode();
|
||||
await goToRegistrationStep();
|
||||
await clickRegisterLater();
|
||||
await selectGuestImageTarget();
|
||||
await goToUsersStep();
|
||||
await clickAddUser();
|
||||
await addUserName(validUserName);
|
||||
await addSshKey(validSshKey);
|
||||
await addPassword(validPassword);
|
||||
const nextButton = await getNextButton();
|
||||
await waitFor(() => expect(nextButton).toBeEnabled());
|
||||
await checkAdminCheckbox();
|
||||
await addUserGroup('users');
|
||||
await addUserGroup('widget');
|
||||
await goToReviewStep();
|
||||
// informational modal pops up in the first test only as it's tied
|
||||
// to a 'imageBuilder.saveAndBuildModalSeen' variable in localStorage
|
||||
await openAndDismissSaveAndBuildModal();
|
||||
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
|
||||
|
||||
const expectedRequest = {
|
||||
...blueprintRequest,
|
||||
customizations: {
|
||||
users: [
|
||||
{
|
||||
name: 'best',
|
||||
ssh_key: 'ssh-rsa d',
|
||||
name: validUserName,
|
||||
ssh_key: validSshKey,
|
||||
password: validPassword,
|
||||
groups: ['wheel', 'users', 'widget'],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
await waitFor(() => {
|
||||
expect(receivedRequest).toEqual(expectedRequest);
|
||||
});
|
||||
|
|
@ -322,8 +336,7 @@ describe('User request generated correctly', () => {
|
|||
|
||||
test('remove a user', async () => {
|
||||
await renderCreateMode();
|
||||
await goToRegistrationStep();
|
||||
await clickRegisterLater();
|
||||
await selectGuestImageTarget();
|
||||
await goToUsersStep();
|
||||
await clickAddUser();
|
||||
await addUserName('test');
|
||||
|
|
@ -331,13 +344,15 @@ describe('User request generated correctly', () => {
|
|||
await addUserGroup('users');
|
||||
await addUserGroup('widget');
|
||||
await clickRemoveUser();
|
||||
await waitFor(() => expect('add a user to your image'));
|
||||
await waitFor(() => expect(screen.getByText(/add a user to your image/i)));
|
||||
await goToReviewStep();
|
||||
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
|
||||
|
||||
const expectedRequest = {
|
||||
...blueprintRequest,
|
||||
customizations: {},
|
||||
};
|
||||
|
||||
await waitFor(() => {
|
||||
expect(receivedRequest).toEqual(expectedRequest);
|
||||
});
|
||||
|
|
@ -357,6 +372,7 @@ describe('Users edit mode', () => {
|
|||
const receivedRequest = await interceptEditBlueprintRequest(
|
||||
`${EDIT_BLUEPRINT}/${id}`
|
||||
);
|
||||
expect(receivedRequest).toEqual(usersCreateBlueprintRequest);
|
||||
const expectedRequest = usersCreateBlueprintRequest;
|
||||
expect(receivedRequest).toEqual(expectedRequest);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue