Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eokoneyo committed Nov 14, 2024
1 parent 36b982b commit d3c59a5
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { EuiThemeProvider } from '@elastic/eui';
import { render, screen, waitFor, within } from '@testing-library/react';
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import crypto from 'crypto';
import React from 'react';
Expand Down Expand Up @@ -179,6 +179,23 @@ describe('PrivilegesRolesForm', () => {
expect(screen.getByTestId('space-assign-role-create-roles-privilege-button')).toBeDisabled();
});

it('makes a request to refetch available roles if page transitions back from a user interaction page visibility change', () => {
getRolesSpy.mockResolvedValue([]);
getAllKibanaPrivilegeSpy.mockResolvedValue(createRawKibanaPrivileges(kibanaFeatures));

renderPrivilegeRolesForm();

expect(getRolesSpy).toHaveBeenCalledTimes(1);

// trigger click on manage roles link, which is perquisite for page visibility handler to trigger role refetch
fireEvent.click(screen.getByText(/manage roles/i));

// trigger page visibility change
fireEvent(document, new Event('visibilitychange'));

expect(getRolesSpy).toHaveBeenCalledTimes(2);
});

it('renders with the assign roles button disabled when no base privileges or feature privileges are selected', async () => {
getRolesSpy.mockResolvedValue([]);
getAllKibanaPrivilegeSpy.mockResolvedValue(createRawKibanaPrivileges(kibanaFeatures));
Expand Down

0 comments on commit d3c59a5

Please sign in to comment.