forked from openedx/frontend-app-admin-console
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.test.tsx
More file actions
87 lines (70 loc) · 2.72 KB
/
index.test.tsx
File metadata and controls
87 lines (70 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { fireEvent, screen } from '@testing-library/react';
import { renderWrapper } from '@src/setupTest';
import RoleCard from '.';
jest.mock('@openedx/paragon/icons', () => ({
Delete: () => <svg data-testid="delete-icon" />,
Person: () => <svg data-testid="person-icon" />,
}));
jest.mock('./constants', () => ({
actionsDictionary: {
view: () => <svg data-testid="view-icon" />,
manage: () => <svg data-testid="manage-icon" />,
},
}));
describe('RoleCard', () => {
const defaultProps = {
title: 'Admin',
objectName: 'Test Library',
description: 'Can manage everything',
showDelete: true,
userCounter: 2,
permissions: [
{
key: 'library',
label: 'Library Resource',
actions: [
{ key: 'view', label: 'View' },
{ key: 'manage', label: 'Manage', disabled: true },
],
},
],
};
it('renders all role card sections correctly', () => {
renderWrapper(<RoleCard {...defaultProps} />);
// Title
expect(screen.getByText('Admin')).toBeInTheDocument();
// User counter with icon
expect(screen.getByText('2')).toBeInTheDocument();
expect(screen.getByTestId('person-icon')).toBeInTheDocument();
// Subtitle (object name)
expect(screen.getByText('Test Library')).toBeInTheDocument();
// Description
expect(screen.getByText('Can manage everything')).toBeInTheDocument();
// Delete button
expect(screen.getByRole('button', { name: /delete role action/i })).toBeInTheDocument();
// Collapsible title
expect(screen.getByText('Permissions')).toBeInTheDocument();
fireEvent.click(screen.getByText('Permissions'));
// Resource label
expect(screen.getByText('Library Resource')).toBeInTheDocument();
// Action chips
expect(screen.getByText('View')).toBeInTheDocument();
expect(screen.getByText('Manage')).toBeInTheDocument();
// Action icons
expect(screen.getByTestId('view-icon')).toBeInTheDocument();
expect(screen.getByTestId('manage-icon')).toBeInTheDocument();
});
it('does not show delete button when showDelete is false', () => {
renderWrapper(<RoleCard {...defaultProps} showDelete={false} />);
expect(screen.queryByRole('button', { name: /delete role action/i })).not.toBeInTheDocument();
});
it('handles no userCounter gracefully', () => {
renderWrapper(<RoleCard {...defaultProps} userCounter={null} />);
expect(screen.queryByTestId('person-icon')).not.toBeInTheDocument();
expect(screen.queryByText('2')).not.toBeInTheDocument();
});
it('handles empty permissions gracefully', () => {
renderWrapper(<RoleCard {...defaultProps} permissions={[]} />);
expect(screen.queryByText('Library Resource')).not.toBeInTheDocument();
});
});