Skip to content

Commit 861da92

Browse files
committed
add unit tests
1 parent 9231f54 commit 861da92

2 files changed

Lines changed: 164 additions & 5 deletions

File tree

packages/eui/src/components/flyout/manager/flyout_managed.test.tsx

Lines changed: 114 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ jest.mock('./hooks', () => ({
6868

6969
// Mock validation helpers to be deterministic
7070
jest.mock('./validation', () => ({
71-
validateManagedFlyoutSize: () => undefined,
72-
validateSizeCombination: () => undefined,
73-
validateFlyoutTitle: () => undefined,
74-
createValidationErrorMessage: (e: any) => String(e),
75-
isNamedSize: () => true,
71+
validateManagedFlyoutSize: jest.fn(() => undefined),
72+
validateSizeCombination: jest.fn(() => undefined),
73+
validateFlyoutTitle: jest.fn(() => undefined),
74+
createValidationErrorMessage: jest.fn((e: any) => String(e)),
75+
isNamedSize: jest.fn(() => true),
7676
}));
7777

7878
// Mock resize observer hook to return a fixed width
@@ -123,4 +123,113 @@ describe('EuiManagedFlyout', () => {
123123
LEVEL_CHILD
124124
);
125125
});
126+
127+
describe('flyoutMenuProps integration', () => {
128+
it('passes flyoutMenuProps to the underlying flyout component', () => {
129+
const flyoutMenuProps = {
130+
title: 'Test Menu',
131+
hideCloseButton: true,
132+
customActions: [
133+
{
134+
iconType: 'gear',
135+
onClick: jest.fn(),
136+
'aria-label': 'Settings',
137+
},
138+
],
139+
};
140+
141+
const { getByTestSubject } = renderInProvider(
142+
<EuiManagedFlyout
143+
id="test-flyout"
144+
level={LEVEL_MAIN}
145+
onClose={() => {}}
146+
flyoutMenuProps={flyoutMenuProps}
147+
/>
148+
);
149+
150+
const el = getByTestSubject('managed-flyout');
151+
expect(el).toHaveAttribute('data-test-subj', 'managed-flyout');
152+
});
153+
154+
it('merges flyoutMenuProps with extracted title from flyoutMenuProps.title', () => {
155+
const flyoutMenuProps = {
156+
title: 'Original Title',
157+
hideCloseButton: false,
158+
};
159+
160+
const { getByTestSubject } = renderInProvider(
161+
<EuiManagedFlyout
162+
id="test-flyout"
163+
level={LEVEL_MAIN}
164+
onClose={() => {}}
165+
flyoutMenuProps={flyoutMenuProps}
166+
/>
167+
);
168+
169+
const el = getByTestSubject('managed-flyout');
170+
expect(el).toHaveAttribute('data-test-subj', 'managed-flyout');
171+
});
172+
173+
it('merges flyoutMenuProps with extracted title from aria-label', () => {
174+
const flyoutMenuProps = {
175+
hideCloseButton: true,
176+
customActions: [],
177+
};
178+
179+
const { getByTestSubject } = renderInProvider(
180+
<EuiManagedFlyout
181+
id="test-flyout"
182+
level={LEVEL_MAIN}
183+
onClose={() => {}}
184+
aria-label="Aria Label Title"
185+
flyoutMenuProps={flyoutMenuProps}
186+
/>
187+
);
188+
189+
const el = getByTestSubject('managed-flyout');
190+
expect(el).toHaveAttribute('data-test-subj', 'managed-flyout');
191+
});
192+
});
193+
194+
describe('title handling', () => {
195+
it('renders successfully when title is provided via flyoutMenuProps', () => {
196+
const flyoutMenuProps = { title: 'Test Title' };
197+
198+
const { getByTestSubject } = renderInProvider(
199+
<EuiManagedFlyout
200+
id="test-flyout"
201+
level={LEVEL_MAIN}
202+
onClose={() => {}}
203+
flyoutMenuProps={flyoutMenuProps}
204+
/>
205+
);
206+
207+
expect(getByTestSubject('managed-flyout')).toBeInTheDocument();
208+
});
209+
210+
it('renders successfully when title is provided via aria-label', () => {
211+
const { getByTestSubject } = renderInProvider(
212+
<EuiManagedFlyout
213+
id="test-flyout"
214+
level={LEVEL_MAIN}
215+
onClose={() => {}}
216+
aria-label="Aria Label Title"
217+
/>
218+
);
219+
220+
expect(getByTestSubject('managed-flyout')).toBeInTheDocument();
221+
});
222+
223+
it('renders successfully for child flyouts without title', () => {
224+
const { getByTestSubject } = renderInProvider(
225+
<EuiManagedFlyout
226+
id="child-flyout"
227+
level={LEVEL_CHILD}
228+
onClose={() => {}}
229+
/>
230+
);
231+
232+
expect(getByTestSubject('managed-flyout')).toBeInTheDocument();
233+
});
234+
});
126235
});

packages/eui/src/components/flyout/manager/validation.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
validateFlyoutSize,
1414
createValidationErrorMessage,
1515
FlyoutValidationError,
16+
validateFlyoutTitle,
1617
} from './validation';
1718

1819
describe('Flyout Size Validation', () => {
@@ -52,6 +53,26 @@ describe('Flyout Size Validation', () => {
5253
});
5354
});
5455

56+
describe('validateFlyoutTitle', () => {
57+
it('should return null for child flyouts without title', () => {
58+
expect(validateFlyoutTitle(undefined, 'child-id', 'child')).toBeNull();
59+
});
60+
61+
it('should return null for main flyouts with valid title', () => {
62+
expect(validateFlyoutTitle('Main Title', 'main-id', 'main')).toBeNull();
63+
});
64+
65+
it('should return error for empty string title', () => {
66+
const error = validateFlyoutTitle('', 'test-id', 'main');
67+
expect(error).toEqual({
68+
type: 'INVALID_FLYOUT_MENU_TITLE',
69+
message: `Managed flyouts require either a 'flyoutMenuProps' a 'title' property, or an 'aria-label' to provide the title.`,
70+
flyoutId: 'test-id',
71+
level: 'main',
72+
});
73+
});
74+
});
75+
5576
describe('validateSizeCombination', () => {
5677
it('should return null for valid combinations', () => {
5778
expect(validateSizeCombination('s', 'm')).toBeNull();
@@ -173,5 +194,34 @@ describe('Flyout Size Validation', () => {
173194
'EuiFlyout validation error: Parent and child flyouts cannot both be size "fill"'
174195
);
175196
});
197+
198+
it('should create error message for invalid flyout menu title', () => {
199+
const error: FlyoutValidationError = {
200+
type: 'INVALID_FLYOUT_MENU_TITLE',
201+
message:
202+
"Managed flyouts require either a 'flyoutMenuProps' a 'title' property, or an 'aria-label' to provide the title.",
203+
flyoutId: 'test-id',
204+
level: 'main',
205+
};
206+
207+
const message = createValidationErrorMessage(error);
208+
expect(message).toBe(
209+
"EuiFlyout validation error: Managed flyouts require either a 'flyoutMenuProps' a 'title' property, or an 'aria-label' to provide the title."
210+
);
211+
});
212+
213+
it('should handle unknown error types', () => {
214+
const error: FlyoutValidationError = {
215+
type: 'UNKNOWN_ERROR' as any,
216+
message: 'Some unknown error',
217+
flyoutId: 'test-id',
218+
level: 'main',
219+
};
220+
221+
const message = createValidationErrorMessage(error);
222+
expect(message).toBe(
223+
'EuiFlyout validation error: Unknown validation error'
224+
);
225+
});
176226
});
177227
});

0 commit comments

Comments
 (0)