From d5e48539246c41481a617c59473010f9cb5ddecc Mon Sep 17 00:00:00 2001 From: tygao Date: Thu, 29 Aug 2024 17:24:55 +0800 Subject: [PATCH] test: add mock for test cases Signed-off-by: tygao --- .../__snapshots__/header.test.tsx.snap | 255 ++++++++++++++++++ .../object_view/components/header.test.tsx | 30 ++- 2 files changed, 284 insertions(+), 1 deletion(-) diff --git a/src/plugins/saved_objects_management/public/management_section/object_view/components/__snapshots__/header.test.tsx.snap b/src/plugins/saved_objects_management/public/management_section/object_view/components/__snapshots__/header.test.tsx.snap index 323031ad6547..84d7c8a6c078 100644 --- a/src/plugins/saved_objects_management/public/management_section/object_view/components/__snapshots__/header.test.tsx.snap +++ b/src/plugins/saved_objects_management/public/management_section/object_view/components/__snapshots__/header.test.tsx.snap @@ -273,3 +273,258 @@ exports[`Intro component renders correctly 1`] = ` `; + +exports[`Intro component renders correctly when use new UX 1`] = ` +
+ + Delete search + +
+`; + +exports[`Intro component renders correctly when use new UX and canDelete is true 1`] = ` +
+ + Delete search + +
+`; + +exports[`Intro component renders correctly when use new UX and canViewInApp is true 1`] = ` +
+ + Delete search + +
+`; diff --git a/src/plugins/saved_objects_management/public/management_section/object_view/components/header.test.tsx b/src/plugins/saved_objects_management/public/management_section/object_view/components/header.test.tsx index a69d68637956..eb38642b631a 100644 --- a/src/plugins/saved_objects_management/public/management_section/object_view/components/header.test.tsx +++ b/src/plugins/saved_objects_management/public/management_section/object_view/components/header.test.tsx @@ -63,7 +63,9 @@ describe('Intro component', () => { onDeleteClick: () => undefined, useUpdatedUX: false, navigationUI: ({ - HeaderControl: () => null, + HeaderControl: ({ controls }) => { + return controls?.[0].ariaLabel ?? controls?.[0].label ?? null; + }, } as unknown) as NavigationPublicPluginStart['ui'], application: coreMock.createStart().application, }; @@ -144,4 +146,30 @@ describe('Intro component', () => { }); expect(mounted.exists(`a[data-test-subj='savedObjectEditViewInApp']`)).toBe(false); }); + + it('renders correctly when use new UX', () => { + const mounted = mountHeader({ + ...defaultProps, + useUpdatedUX: true, + }); + expect(mounted).toMatchSnapshot(); + }); + + it('renders correctly when use new UX and canViewInApp is true', () => { + const mounted = mountHeader({ + ...defaultProps, + useUpdatedUX: true, + canViewInApp: true, + }); + expect(mounted).toMatchSnapshot(); + }); + + it('renders correctly when use new UX and canDelete is true', () => { + const mounted = mountHeader({ + ...defaultProps, + useUpdatedUX: true, + canDelete: true, + }); + expect(mounted).toMatchSnapshot(); + }); });