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 e9f66a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 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 @@ -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 e9f66a7

Please sign in to comment.