Skip to content

Commit

Permalink
Test button using getByRole
Browse files Browse the repository at this point in the history
  • Loading branch information
dlabrecq committed Sep 17, 2024
1 parent 9e76b64 commit 3be30d4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ describe('add-a-new-rate', () => {
expect(screen.queryByText(regExp(messages.priceListNumberRate))).toBeNull();

// making sure button is enabled
const createButton = screen.getByText(regExp(messages.createRate));
const createButton = screen.getByRole('button', { name: regExp(messages.createRate)} );
expect(createButton.getAttribute('aria-disabled')).toBe('false');
await user.click(createButton);
expect(submit).toHaveBeenCalled();
Expand Down Expand Up @@ -240,7 +240,7 @@ describe('add-a-new-rate', () => {
expect(screen.getByText(regExp(messages.priceListPosNumberRate))).not.toBeNull();

// setting a valid rate - now form is valid and can be submitted
const createButton = screen.getByText(regExp(messages.createRate));
const createButton = screen.getByRole('button', { name: regExp(messages.createRate)} );
expect(createButton.getAttribute('aria-disabled')).toBe('true');
await user.clear(tagRateInput);

Expand Down
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,7 +327,7 @@ describe('update-rate', () => {
test('regular', async () => {
const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
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(/infrastructure/i));
expect(saveButton.getAttribute('disabled')).toBeNull();
Expand All @@ -351,7 +351,7 @@ describe('update-rate', () => {
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ test('delete dialog open', async () => {
},
};
renderUI(state);
expect(screen.queryAllByText(regExp(messages.costModelsDelete))).toHaveLength(2);
expect(screen.getAllByRole('button', { name: regExp(messages.costModelsDelete)})).toHaveLength(1);
expect(screen.queryAllByText(/This action will delete/i)).toHaveLength(1);
expect(screen.queryAllByText(/The following sources are assigned to/i)).toHaveLength(0);
await act(async () => user.click(screen.getAllByText(regExp(messages.costModelsDelete))[1]));
expect(screen.getAllByText(regExp(messages.costModelsDelete))[1].getAttribute('disabled')).not.toBeNull();
expect(screen.queryAllByText(/The following integrations are assigned to/i)).toHaveLength(0);
await act(async () => user.click(screen.getAllByRole('button', { name: regExp(messages.costModelsDelete)})[0]));
expect(screen.getAllByRole('button', { name: regExp(messages.costModelsDelete)})[0].getAttribute('disabled')).not.toBeNull();
});

test('delete dialog error', async () => {
Expand Down

0 comments on commit 3be30d4

Please sign in to comment.