From 48d35951a73a2fbd455663637236ce32de6efc3c Mon Sep 17 00:00:00 2001 From: Rajat Dabade Date: Tue, 26 Nov 2024 16:51:44 +0530 Subject: [PATCH] added comparing snapshot for previously added test --- .../__snapshots__/channel_info.test.tsx.snap | 324 +++++ .../avatar/__snapshots__/index.test.tsx.snap | 102 ++ .../channel_info/avatar/index.test.tsx | 14 +- .../channel_info/channel_info.test.tsx | 17 +- .../draft/__snapshots__/draft.test.tsx.snap | 1090 +++++++++++++++++ app/components/draft/draft.test.tsx | 17 +- 6 files changed, 1549 insertions(+), 15 deletions(-) create mode 100644 app/components/channel_info/__snapshots__/channel_info.test.tsx.snap create mode 100644 app/components/channel_info/avatar/__snapshots__/index.test.tsx.snap create mode 100644 app/components/draft/__snapshots__/draft.test.tsx.snap diff --git a/app/components/channel_info/__snapshots__/channel_info.test.tsx.snap b/app/components/channel_info/__snapshots__/channel_info.test.tsx.snap new file mode 100644 index 00000000000..d4854e14eb7 --- /dev/null +++ b/app/components/channel_info/__snapshots__/channel_info.test.tsx.snap @@ -0,0 +1,324 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ChannelInfo Component renders CompassIcon when draftReceiverUser is not provided 1`] = ` + + + + + + + + + Direct Message Channel + + + +`; + +exports[`ChannelInfo Component renders correctly for a DM channel 1`] = ` + + + + + + + + + Direct Message Channel + + + +`; + +exports[`ChannelInfo Component renders correctly for a public channel 1`] = ` + + + + + + + + + Public Channel + + + +`; + +exports[`ChannelInfo Component renders correctly for a thread 1`] = ` + + + + + + + + + Direct Message Channel + + + +`; + +exports[`ChannelInfo Component renders the Avatar when draftReceiverUser is provided 1`] = ` + + + + + + + Direct Message Channel + + + +`; diff --git a/app/components/channel_info/avatar/__snapshots__/index.test.tsx.snap b/app/components/channel_info/avatar/__snapshots__/index.test.tsx.snap new file mode 100644 index 00000000000..9f3b0100261 --- /dev/null +++ b/app/components/channel_info/avatar/__snapshots__/index.test.tsx.snap @@ -0,0 +1,102 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Avatar Component renders the avatar image when URI is available 1`] = ` + + + +`; + +exports[`Avatar Component renders the fallback icon when URI is not available 1`] = ` + + + +`; + +exports[`Avatar Component renders the fallback icon when author is not provided 1`] = ` + + + +`; diff --git a/app/components/channel_info/avatar/index.test.tsx b/app/components/channel_info/avatar/index.test.tsx index 0e0a8aec0c1..e54695247f4 100644 --- a/app/components/channel_info/avatar/index.test.tsx +++ b/app/components/channel_info/avatar/index.test.tsx @@ -39,12 +39,14 @@ describe('Avatar Component', () => { }); mockBuildAbsoluteUrl.mockImplementation((serverUrl: string, uri: string) => `${serverUrl}${uri}`); - const {queryByTestId} = render(); + const wrapper = render(); + const {queryByTestId} = wrapper; expect(mockBuildProfileImageUrlFromUser).toHaveBeenCalledWith(mockServerUrl, mockAuthor); expect(mockBuildAbsoluteUrl).toHaveBeenCalledWith(mockServerUrl, mockUri); expect(queryByTestId('avatar-icon')).toBeNull(); + expect(wrapper.toJSON()).toMatchSnapshot(); }); it('renders the fallback icon when URI is not available', () => { @@ -54,8 +56,8 @@ describe('Avatar Component', () => { mockUseServerUrl.mockReturnValue(mockServerUrl); mockBuildProfileImageUrlFromUser.mockReturnValue(''); mockBuildAbsoluteUrl.mockReturnValue(''); - - const {getByTestId, queryByTestId} = render(); + const wrapper = render(); + const {getByTestId, queryByTestId} = wrapper; expect(mockBuildProfileImageUrlFromUser).toHaveBeenCalledWith(mockServerUrl, mockAuthor); expect(mockBuildAbsoluteUrl).not.toHaveBeenCalled(); @@ -63,14 +65,15 @@ describe('Avatar Component', () => { const icon = getByTestId('avatar-icon'); expect(icon.props.name).toBe('account-outline'); expect(queryByTestId('avatar-image')).toBeNull(); + expect(wrapper.toJSON()).toMatchSnapshot(); }); it('renders the fallback icon when author is not provided', () => { const mockServerUrl = 'base.url.com'; mockUseServerUrl.mockReturnValue(mockServerUrl); - - const {getByTestId, queryByTestId} = render(); + const wrapper = render(); + const {getByTestId, queryByTestId} = wrapper; expect(mockBuildProfileImageUrlFromUser).not.toHaveBeenCalled(); expect(mockBuildAbsoluteUrl).not.toHaveBeenCalled(); @@ -78,5 +81,6 @@ describe('Avatar Component', () => { const icon = getByTestId('avatar-icon'); expect(icon.props.name).toBe('account-outline'); expect(queryByTestId('avatar-image')).toBeNull(); + expect(wrapper.toJSON()).toMatchSnapshot(); }); }); diff --git a/app/components/channel_info/channel_info.test.tsx b/app/components/channel_info/channel_info.test.tsx index d636ded65d8..5b5479607df 100644 --- a/app/components/channel_info/channel_info.test.tsx +++ b/app/components/channel_info/channel_info.test.tsx @@ -51,7 +51,7 @@ describe('ChannelInfo Component', () => { isMilitaryTime: true, }; - render(); + const wrapper = render(); expect(CompassIcon).toHaveBeenCalledWith( expect.objectContaining({ name: 'globe', @@ -66,6 +66,7 @@ describe('ChannelInfo Component', () => { }), expect.anything(), ); + expect(wrapper.toJSON()).toMatchSnapshot(); }); it('renders correctly for a public channel', () => { @@ -78,7 +79,7 @@ describe('ChannelInfo Component', () => { currentUser: {timezone: 'UTC'} as unknown as UserModel, isMilitaryTime: true, }; - render(); + const wrapper = render(); expect(FormattedText).toHaveBeenCalledWith( expect.objectContaining({ id: 'channel_info.draft_in_channel', @@ -92,6 +93,7 @@ describe('ChannelInfo Component', () => { }), expect.anything(), ); + expect(wrapper.toJSON()).toMatchSnapshot(); }); it('renders correctly for a thread', () => { @@ -104,7 +106,8 @@ describe('ChannelInfo Component', () => { currentUser: {timezone: 'UTC'} as unknown as UserModel, isMilitaryTime: true, }; - const {getByTestId} = render(); + const wrapper = render(); + const {getByTestId} = wrapper; expect(useTheme).toHaveBeenCalled(); expect(getByTestId('channel-info')).toBeTruthy(); @@ -115,6 +118,7 @@ describe('ChannelInfo Component', () => { }), expect.anything(), ); + expect(wrapper.toJSON()).toMatchSnapshot(); }); it('renders the Avatar when draftReceiverUser is provided', () => { @@ -127,7 +131,7 @@ describe('ChannelInfo Component', () => { currentUser: {timezone: 'UTC'} as unknown as UserModel, isMilitaryTime: true, }; - render(); + const wrapper = render(); expect(Avatar).toHaveBeenCalledWith( expect.objectContaining({ @@ -135,6 +139,7 @@ describe('ChannelInfo Component', () => { }), expect.anything(), ); + expect(wrapper.toJSON()).toMatchSnapshot(); }); it('renders CompassIcon when draftReceiverUser is not provided', () => { @@ -147,13 +152,13 @@ describe('ChannelInfo Component', () => { currentUser: {timezone: 'UTC'} as unknown as UserModel, isMilitaryTime: true, }; - render(); - + const wrapper = render(); expect(CompassIcon).toHaveBeenCalledWith( expect.objectContaining({ name: 'globe', }), expect.anything(), ); + expect(wrapper.toJSON()).toMatchSnapshot(); }); }); diff --git a/app/components/draft/__snapshots__/draft.test.tsx.snap b/app/components/draft/__snapshots__/draft.test.tsx.snap new file mode 100644 index 00000000000..9f92e76848c --- /dev/null +++ b/app/components/draft/__snapshots__/draft.test.tsx.snap @@ -0,0 +1,1090 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Draft should match the file count 1`] = ` + + + + + + + + + + + Direct Message Channel + + + + + + + + + + + + Hello, World! + + + + + + + + + + + + + + + + + + + file1.txt + + + + + 64 B + + + + + + + + + + + + + + + + + + file2.pdf + + + + + 64 B + + + + + + + + + + + +`; + +exports[`Draft should render the draft with channel info and draft message 1`] = ` + + + + + + + + + + + Direct Message Channel + + + + + + + + + + + + Hello, World! + + + + + + + + + + +`; + +exports[`Draft should render the draft with channel info and draft message for a thread 1`] = ` + + + + + + + + + + + Direct Message Channel + + + + + + + + + + + + Hello, World! + + + + + + + + + + +`; + +exports[`Draft should render the draft with post priority 1`] = ` + + + + + + + + + + + Direct Message Channel + + + + + + + + IMPORTANT + + + + + + + + + + + + + Hello, World! + + + + + + + + + + +`; diff --git a/app/components/draft/draft.test.tsx b/app/components/draft/draft.test.tsx index 93599108d46..42b579d8838 100644 --- a/app/components/draft/draft.test.tsx +++ b/app/components/draft/draft.test.tsx @@ -41,7 +41,7 @@ describe('Draft', () => { layoutWidth: 100, isPostPriorityEnabled: false, }; - const {getByText} = renderWithEverything( + const wrapper = renderWithEverything( { , {database}, ); + const {getByText} = wrapper; + expect(FormattedText).toHaveBeenCalledWith( expect.objectContaining({ id: 'channel_info.draft_in_channel', @@ -66,6 +68,7 @@ describe('Draft', () => { expect.anything(), ); expect(getByText('Hello, World!')).toBeTruthy(); + expect(wrapper.toJSON()).toMatchSnapshot(); }); it('should match the file count', () => { @@ -95,7 +98,7 @@ describe('Draft', () => { layoutWidth: 100, isPostPriorityEnabled: false, }; - const {getAllByTestId} = renderWithEverything( + const wrapper = renderWithEverything( { /> , {database}, ); + const {getAllByTestId} = wrapper; expect(getAllByTestId('file_attachment')).toHaveLength(2); + expect(wrapper.toJSON()).toMatchSnapshot(); }); it('should render the draft with channel info and draft message for a thread', () => { @@ -123,7 +128,7 @@ describe('Draft', () => { layoutWidth: 100, isPostPriorityEnabled: false, }; - const {getByText} = renderWithEverything( + const wrapper = renderWithEverything( { , {database}, ); + const {getByText} = wrapper; expect(FormattedText).toHaveBeenCalledWith( expect.objectContaining({ id: 'channel_info.thread_in', @@ -149,6 +155,7 @@ describe('Draft', () => { expect.anything(), ); expect(getByText('Hello, World!')).toBeTruthy(); + expect(wrapper.toJSON()).toMatchSnapshot(); }); it('should render the draft with post priority', () => { @@ -166,7 +173,7 @@ describe('Draft', () => { layoutWidth: 100, isPostPriorityEnabled: true, }; - const {getByText} = renderWithEverything( + const wrapper = renderWithEverything( { /> , {database}, ); + const {getByText} = wrapper; expect(getByText('IMPORTANT')).toBeTruthy(); + expect(wrapper.toJSON()).toMatchSnapshot(); }); });