Browse Source

SONAR-21692 Improve GlobalMessageContainer-it, Login-it

tags/10.5.0.89998
stanislavh 2 months ago
parent
commit
2a0de2fa06

+ 7
- 5
server/sonar-web/src/main/js/app/components/__tests__/GlobalMessagesContainer-it.tsx View File

@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { act, screen, waitFor } from '@testing-library/react';
import { act, screen } from '@testing-library/react';
import React from 'react';
import { addGlobalErrorMessage, addGlobalSuccessMessage } from '../../../helpers/globalMessages';
import { renderApp } from '../../../helpers/testReactTestingUtils';
@@ -32,19 +32,21 @@ it('should display messages', async () => {
// we render anything, the GlobalMessageContainer is rendered independently from routing
renderApp('sonarqube', <NullComponent />);

await waitFor(() => {
act(() => {
addGlobalErrorMessage('This is an error');
addGlobalSuccessMessage('This was a triumph!');
});
expect(await screen.findByRole('alert')).toHaveTextContent('This is an error');

expect(screen.getByRole('alert')).toHaveTextContent('This is an error');
expect(screen.getByRole('status')).toHaveTextContent('This was a triumph!');

// No duplicate message
await waitFor(() => {
act(() => {
addGlobalErrorMessage('This is an error');
});

expect(screen.getByRole('alert')).toHaveTextContent(/^This is an error$/);
await waitFor(() => {
act(() => {
addGlobalSuccessMessage('This was a triumph!');
});
expect(await screen.findByRole('status')).toHaveTextContent(

+ 3
- 0
server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectManagementApp-it.tsx View File

@@ -183,6 +183,9 @@ it('should filter projects', async () => {
const user = userEvent.setup();
renderProjectManagementApp();
await waitFor(() => expect(ui.row.getAll()).toHaveLength(5));
// Should return Promise: (and same for all similar cases below)
// await waitFor(() => selectEvent.select(ui.visibilityFilter.get(), ‘visibility.public’));
// Can be fixed by migrating ProjectManagementApp to functional component
await waitFor(() => {
selectEvent.select(ui.visibilityFilter.get(), 'visibility.public');
});

+ 5
- 3
server/sonar-web/src/main/js/apps/sessions/components/__tests__/Login-it.tsx View File

@@ -101,11 +101,13 @@ it('should behave correctly', async () => {
// Incorrect login.
await user.type(loginField, 'janedoe');
await user.type(passwordField, 'invalid');

// We are not waiting for async handler to be done, as we assert that button is disabled immediately after
user.click(submitButton);
await waitFor(() => {
// Don't use userEvent.click() here. This allows us to more easily see the loading state changes.
submitButton.click();
expect(submitButton).toBeDisabled(); // Loading
expect(submitButton).toBeDisabled();
});

await waitFor(() => {
expect(addGlobalErrorMessage).toHaveBeenCalledWith('login.authentication_failed');
});

Loading…
Cancel
Save