Skip to content

Commit

Permalink
Replace getByLabelText with getAllByLabelText
Browse files Browse the repository at this point in the history
  • Loading branch information
dlabrecq committed Sep 17, 2024
1 parent e9f66a7 commit 5c76f0f
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions src/routes/settings/costModels/costModel/updateRateModel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ describe('update-rate', () => {
render(<RenderFormDataUI index={0} />);

const descInput = screen.getByDisplayValue('openshift-aws-node');
const saveButton = screen.getByText(regExp(messages.save));
const saveButton = screen.getByRole('button', { name: regExp(messages.save)} );
expect(saveButton.getAttribute('disabled')).not.toBeNull();

await user.clear(descInput);
Expand All @@ -289,7 +289,7 @@ describe('update-rate', () => {

render(<RenderFormDataUI index={0} />);

const saveButton = screen.getByText(regExp(messages.save));
const saveButton = screen.getByRole('button', { name: regExp(messages.save)} );

await user.click(screen.getByLabelText('Select Measurement'));
options = await screen.findAllByRole('option');
Expand Down Expand Up @@ -327,31 +327,35 @@ describe('update-rate', () => {
test('regular', async () => {
const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
render(<RenderFormDataUI index={0} />);
const saveButton = screen.getByText(regExp(messages.save));

await user.click(screen.getByLabelText(/infrastructure/i));
const saveButton = screen.getByRole('button', { name: regExp(messages.save)} );

await user.click(screen.getByRole('radio', { name: /infrastructure/i }));
expect(saveButton.getAttribute('disabled')).toBeNull();
await user.click(screen.getByLabelText(/supplementary/i));
await user.click(screen.getByRole('radio', { name: /supplementary/i }));
expect(saveButton.getAttribute('disabled')).not.toBeNull();

await user.type(screen.getByDisplayValue(/55/i), '.3');
expect(saveButton.getAttribute('disabled')).toBeNull();
await user.type(screen.getByDisplayValue(/55.3/i), '{backspace}{backspace}');
expect(saveButton.getAttribute('disabled')).not.toBeNull();

await user.click(screen.getByLabelText(regExp(messages.costModelsEnterTagRate)));
await user.click(screen.getByRole('switch', { name: regExp(messages.costModelsEnterTagRate)} ));
expect(saveButton.getAttribute('disabled')).not.toBeNull();
await user.type(screen.getByLabelText(regExp(messages.costModelsFilterTagKey)), 'openshift');
await user.type(screen.getByLabelText(regExp(messages.costModelsTagRateTableValue)), 'worker');
await user.type(screen.getByLabelText(regExp(messages.rate)), '0.321');

// Todo: The following did not return multiple label text prior to PatternFly v6
await user.type(screen.getAllByLabelText(regExp(messages.costModelsFilterTagKey))[1], 'openshift');
await user.type(screen.getAllByLabelText(regExp(messages.costModelsTagRateTableValue))[1], 'worker');
await user.type(screen.getAllByLabelText(regExp(messages.rate))[1], '0.321');

expect(saveButton.getAttribute('disabled')).toBeNull();
await user.click(saveButton);
});

test('tag', async () => {
const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
render(<RenderFormDataUI index={1} />);
const saveButton = screen.getByText(regExp(messages.save));
const saveButton = screen.getByRole('button', { name: regExp(messages.save)} );
expect(saveButton.getAttribute('disabled')).not.toBeNull();
await user.type(screen.getByDisplayValue(/^container$/i), '1');
expect(saveButton.getAttribute('disabled')).toBeNull();
Expand All @@ -368,16 +372,21 @@ describe('update-rate', () => {
await user.type(screen.getByDisplayValue(/^0.43$/i), '{backspace}');
expect(saveButton.getAttribute('disabled')).not.toBeNull();

await user.click(screen.getAllByLabelText(regExp(messages.default))[1]);
// Todo: Was [1] prior to PatternFly v6
await user.click(screen.getAllByLabelText(regExp(messages.default))[2]);
expect(saveButton.getAttribute('disabled')).toBeNull();
await user.click(screen.getAllByLabelText(regExp(messages.default))[0]);
// Todo: Was [0] prior to PatternFly v6
await user.click(screen.getAllByLabelText(regExp(messages.default))[1]);
expect(saveButton.getAttribute('disabled')).not.toBeNull();

await user.click(screen.getByText(/Add more tag values/i));
await act(async () =>
user.type(screen.getAllByLabelText(regExp(messages.costModelsTagRateTableValue))[4], 'something random')
// Todo: Was [4] prior to PatternFly v6
user.type(screen.getAllByLabelText(regExp(messages.costModelsTagRateTableValue))[5], 'something random')
);
await user.type(screen.getAllByLabelText(regExp(messages.rate))[4], '1.01');
// Todo: Was [4] prior to PatternFly v6
await user.type(screen.getAllByLabelText(regExp(messages.rate))[5], '1.01');

expect(saveButton.getAttribute('disabled')).toBeNull();
await user.click(screen.getAllByLabelText(regExp(messages.costModelsRemoveTagLabel))[4]);
expect(saveButton.getAttribute('disabled')).not.toBeNull();
Expand All @@ -397,17 +406,19 @@ describe('update-rate', () => {
options = await screen.findAllByRole('option');
await user.click(options[1]);

await user.click(screen.getByLabelText(regExp(messages.costModelsEnterTagRate)));
// Todo: The following did not return multiple label text prior to PatternFly v6
await user.click(screen.getAllByLabelText(regExp(messages.costModelsEnterTagRate))[1]);
await act(async () =>
user.type(screen.getByLabelText(regExp(messages.costModelsFilterTagKey)), 'openshift-region-1')
user.type(screen.getAllByLabelText(regExp(messages.costModelsFilterTagKey))[1], 'openshift-region-1')
);
expect(screen.getByText(regExp(messages.priceListDuplicate))).not.toBeNull();
});

test('duplicate tag key from tag rate', async () => {
const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
render(<RenderFormDataUI index={2} />);
const filterTagInput = screen.getByLabelText(regExp(messages.costModelsFilterTagKey));
// Todo: The following did not return multiple label text prior to PatternFly v6
const filterTagInput = screen.getAllByLabelText(regExp(messages.costModelsFilterTagKey))[1];
await user.clear(filterTagInput);
await user.type(filterTagInput, 'openshift-region-1');
expect(screen.getByText(regExp(messages.priceListDuplicate))).not.toBeNull();
Expand Down

0 comments on commit 5c76f0f

Please sign in to comment.