Skip to content

Commit

Permalink
Remove tenant name showing up in account-nav-button even when disabled
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Ho <[email protected]>
  • Loading branch information
derek-ho committed Feb 5, 2024
1 parent 5a13f92 commit 372d4b2
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 10 deletions.
20 changes: 11 additions & 9 deletions public/apps/account/account-nav-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,17 @@ export function AccountNavButton(props: {
}
/>
</EuiListGroup>
<EuiListGroupItem
color="subdued"
key="tenant"
label={
<EuiText size="xs" id="tenantName">
{resolveTenantName(props.tenant || '', username)}
</EuiText>
}
/>
{isMultiTenancyEnabled && props.config.multitenancy.enabled && (
<EuiListGroupItem
color="subdued"
key="tenant"
label={
<EuiText size="xs" id="tenantName">
{resolveTenantName(props.tenant || '', username)}
</EuiText>
}
/>
)}
</EuiFlexItem>
</EuiFlexGroup>

Expand Down
79 changes: 78 additions & 1 deletion public/apps/account/test/account-nav-button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
import { shallow } from 'enzyme';
import React from 'react';
import { AccountNavButton, reloadAfterTenantSwitch } from '../account-nav-button';
import { getShouldShowTenantPopup, setShouldShowTenantPopup } from '../../../utils/storage-utils';
import { getShouldShowTenantPopup } from '../../../utils/storage-utils';
import { getDashboardsInfo } from '../../../utils/dashboards-info-utils';
import { render, fireEvent } from '@testing-library/react';

jest.mock('../../../utils/storage-utils', () => ({
getShouldShowTenantPopup: jest.fn(),
Expand Down Expand Up @@ -81,6 +82,10 @@ describe('Account navigation button', () => {
jest.clearAllMocks();
});

afterAll(() => {
useStateSpy.mockRestore();
})

Check failure on line 87 in public/apps/account/test/account-nav-button.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Insert `;`

Check failure on line 87 in public/apps/account/test/account-nav-button.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Insert `;`

Check failure on line 87 in public/apps/account/test/account-nav-button.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (macos-latest)

Insert `;`

it('renders', () => {
(getDashboardsInfo as jest.Mock).mockImplementationOnce(() => {
return mockDashboardsInfo;
Expand Down Expand Up @@ -149,6 +154,10 @@ describe('Account navigation button, multitenancy disabled', () => {
useStateSpy.mockImplementation((init) => [init, setState]);
});

afterAll(() => {
useStateSpy.mockRestore();
})

Check failure on line 159 in public/apps/account/test/account-nav-button.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Insert `;`

Check failure on line 159 in public/apps/account/test/account-nav-button.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Insert `;`

Check failure on line 159 in public/apps/account/test/account-nav-button.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (macos-latest)

Insert `;`

afterEach(() => {
jest.clearAllMocks();
});
Expand All @@ -168,6 +177,74 @@ describe('Account navigation button, multitenancy disabled', () => {
});
});

describe('AccountNavButton', () => {
test('Renders "switch-tenants" and "tenant-name" when multi-tenancy is enabled', () => {
const props = {
coreStart: {},
isInternalUser: true,
username: 'example_user',
tenant: 'example_tenant',
config: {
multitenancy: { enabled: true },
auth: {
type: 'dummy',
},
},
};

// Render the component
const { container, queryByText } = render(<AccountNavButton {...props} />);

// Find the popover component by data-test-subj
const popoverElement = container.querySelector('[data-test-subj="account-popover"]');

// Assert that the popover component is rendered
expect(popoverElement).toBeDefined();

// Now, simulate a click event on the button to open the popover
fireEvent.click(popoverElement!);

const tenantName = queryByText('example_tenant');
expect(tenantName).not.toBeNull();

const tenantSwitch = queryByText('Switch tenants');
expect(tenantSwitch).not.toBeNull();
});

test('Does not render "switch-tenants" and "tenant-name" when multi-tenancy is disabled', () => {
const props = {
coreStart: {},
isInternalUser: true,
username: 'example_user',
tenant: 'example_tenant',
config: {
multitenancy: { enabled: false },
auth: {
type: 'dummy',
},
},
};

// Render the component
const { container, queryByText } = render(<AccountNavButton {...props} />);

// Find the popover component by data-test-subj
const popoverElement = container.querySelector('[data-test-subj="account-popover"]');

// Assert that the popover component is rendered
expect(popoverElement).toBeDefined();

// Now, simulate a click event on the button to open the popover
fireEvent.click(popoverElement!);

const tenantName = queryByText('example_tenant');
expect(tenantName).toBeNull();

const tenantSwitch = queryByText('Switch tenants');
expect(tenantSwitch).toBeNull();
});
});

describe('Reload window after tenant switch', () => {
const originalLocation = window.location;
const mockSetWindowHref = jest.fn();
Expand Down

0 comments on commit 372d4b2

Please sign in to comment.