Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ const GlossaryHeader = ({
Operation.EditAll,
ResourceEntity.GLOSSARY_TERM,
globalPermissions
),
[globalPermissions]
) ||
permissions.EditAll,
[globalPermissions, permissions]
);

// To fetch the latest glossary data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,22 @@ jest.mock('../../Customization/GenericProvider/GenericProvider', () => ({
}));

describe('GlossaryHeader component', () => {
beforeEach(() => {
// Reset shared mocks to avoid state leakage between tests
mockContext.type = EntityType.GLOSSARY;
mockContext.permissions = DEFAULT_ENTITY_PERMISSION;
Object.assign(mockGlossaryTermPermission, {
All: true,
Create: true,
Delete: true,
ViewAll: true,
EditAll: true,
EditDescription: true,
EditDisplayName: true,
EditCustomFields: true,
});
});

it('should render name of Glossary', () => {
render(
<GlossaryHeader
Expand Down Expand Up @@ -229,6 +245,30 @@ describe('GlossaryHeader component', () => {
expect(screen.queryByTestId('manage-button')).not.toBeInTheDocument();
});

it('should render import and export when entity-level EditAll is true despite no global permission', async () => {
// Simulate a role with conditional EditAll (e.g. isOwner())
// Global permissions do not grant All/EditAll
mockGlossaryTermPermission.All = false;
mockGlossaryTermPermission.EditAll = false;
// Entity-level permissions evaluate conditions and grant EditAll
mockContext.permissions = { ...DEFAULT_ENTITY_PERMISSION, EditAll: true };
mockContext.type = EntityType.GLOSSARY;
render(
Comment on lines +248 to +256
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new test mutates shared module-level mocks (mockGlossaryTermPermission and mockContext) without resetting them afterwards. Since other tests in this file also rely on the same shared objects (and don’t use a beforeEach reset), the suite becomes order-dependent and can be flaky when tests are re-ordered or run in isolation. Suggest resetting mockGlossaryTermPermission/mockContext to defaults in a beforeEach, or cloning fresh objects per test to avoid cross-test state leakage.

Copilot uses AI. Check for mistakes.
<GlossaryHeader
updateVote={mockOnUpdateVote}
onAddGlossaryTerm={mockOnDelete}
onDelete={mockOnDelete}
/>
);

await act(async () => {
fireEvent.click(screen.getByTestId('manage-button'));
});

expect(screen.queryByText('label.import')).toBeInTheDocument();
expect(screen.queryByText('label.export')).toBeInTheDocument();
});

it('should render changeParentHierarchy and style dropdown menu items only for glossaryTerm', async () => {
mockContext.type = EntityType.GLOSSARY_TERM;
mockContext.permissions = { ...DEFAULT_ENTITY_PERMISSION, EditAll: true };
Expand Down
Loading