Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test for mobile draft #8363

Open
wants to merge 113 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
63b313f
refactor: started with draft, done until new tabs for draft
Rajat-Dabade Sep 14, 2024
11e758e
refactor: change the query and added the screen for draft
Rajat-Dabade Sep 16, 2024
d72a19f
added condition for fetching draft for channel delete or not
Rajat-Dabade Sep 17, 2024
572d65b
refactor: added draft screen
Rajat-Dabade Sep 20, 2024
d5389b8
linter fixes
Rajat-Dabade Sep 22, 2024
ae55bde
Added draft post component
Rajat-Dabade Sep 24, 2024
afbe59d
added avatar and header display name for the draft post list
Rajat-Dabade Sep 25, 2024
6c99a7c
added channel info component
Rajat-Dabade Oct 2, 2024
9fcbf84
channel info completed
Rajat-Dabade Oct 7, 2024
d688908
proper naming
Rajat-Dabade Oct 7, 2024
324aa16
added image file markdown acknowledgement support
Rajat-Dabade Oct 7, 2024
65b6edd
draft actions
Rajat-Dabade Oct 9, 2024
272c468
Fix the draft receiver in drafts
Rajat-Dabade Oct 14, 2024
1fa189a
separated send message handler
Rajat-Dabade Oct 14, 2024
ba3ee8d
Done with send drafts
Rajat-Dabade Oct 14, 2024
554123f
done with delete drafts
Rajat-Dabade Oct 15, 2024
e629247
change save to send draft
Rajat-Dabade Oct 15, 2024
f8bcead
handle lengthy message with show more button
Rajat-Dabade Oct 15, 2024
6577c6e
done with persistent message edit, send and delete drafts
Rajat-Dabade Oct 17, 2024
d331d46
added alert for sending message
Rajat-Dabade Oct 17, 2024
62d0bbb
added update at time for the drafts
Rajat-Dabade Oct 17, 2024
5308824
en.json extract fix
Rajat-Dabade Oct 22, 2024
611cff0
Updated dependencies for useCallback
Rajat-Dabade Oct 23, 2024
aac1f38
refactor: added drafts list to animated list
Rajat-Dabade Oct 24, 2024
8c153d6
added swipeable component and delete conformation for drafts
Rajat-Dabade Oct 26, 2024
112048a
done with rendering of images in markdown for drafts
Rajat-Dabade Oct 30, 2024
2589127
en.json issue fixed
Rajat-Dabade Nov 5, 2024
a70b165
fix en.json issue
Rajat-Dabade Nov 5, 2024
6f56a41
refactor: en.json fix
Rajat-Dabade Nov 5, 2024
e140826
addressed review comments
Rajat-Dabade Nov 12, 2024
a85a1a4
updated image metadata handling code
Rajat-Dabade Nov 12, 2024
c72c14d
linter fixes
Rajat-Dabade Nov 13, 2024
f5b884a
added the empty draft screen
Rajat-Dabade Nov 18, 2024
cffb22b
linter fix
Rajat-Dabade Nov 18, 2024
b9c48d5
style fix
Rajat-Dabade Nov 18, 2024
424c773
back button an android takes to the channel list page
Rajat-Dabade Nov 18, 2024
6f054ae
en.json fix
Rajat-Dabade Nov 18, 2024
15e6bc3
draft actions theme compatible
Rajat-Dabade Nov 26, 2024
faabf4e
CSS fix for draft channel_info and avatar component
Rajat-Dabade Nov 26, 2024
9b130b6
removed the badge icon and change font style drafts
Rajat-Dabade Nov 26, 2024
c595c3d
fix send alert sender name for GMs
Rajat-Dabade Nov 26, 2024
b167354
updated snapshot
Rajat-Dabade Nov 26, 2024
eee6c26
added testId to the drafts components
Rajat-Dabade Nov 26, 2024
47ac4fe
updated send draft test id
Rajat-Dabade Nov 26, 2024
a842910
clicking on draft takes to the channel
Rajat-Dabade Dec 2, 2024
b26aa59
Added toptip for draft tours
Rajat-Dabade Dec 4, 2024
3d16827
intl extract
Rajat-Dabade Dec 4, 2024
5d7bc78
Rebase to main and reverted local testing changes
Rajat-Dabade Dec 5, 2024
e667dd7
Added tooltip for drafts
Rajat-Dabade Dec 5, 2024
f152788
addressed review comments
Rajat-Dabade Dec 5, 2024
aa1ad72
reset navigation when click on a draft in draft tabs
Rajat-Dabade Dec 10, 2024
f2e2e47
Merge branch 'main' into mobile-drafts
mattermost-build Dec 11, 2024
cd93248
fix the theme issue and navigation issue
Rajat-Dabade Dec 11, 2024
8965394
reverted back the draft click navigation changes
Rajat-Dabade Dec 11, 2024
8c8e6f6
observing draft when hitting back button
Rajat-Dabade Dec 11, 2024
be07659
removed the unwanted animiation
Rajat-Dabade Dec 12, 2024
ab7ce3a
updated regex for parsing markdown
Rajat-Dabade Dec 16, 2024
2b5a671
removed unnecessary checks and change folder name
Rajat-Dabade Dec 16, 2024
22f1528
removed react memo and merge unwanted observes function
Rajat-Dabade Dec 16, 2024
a542590
removed unnecessary comments
Rajat-Dabade Dec 16, 2024
ea131a8
changed the name for observing and querying draft function
Rajat-Dabade Dec 16, 2024
1ca7ddb
removed memo from component level
Rajat-Dabade Dec 16, 2024
8a1952e
Text to FormattedText component
Rajat-Dabade Dec 16, 2024
2941ab1
Text to formatted text, change image name
Rajat-Dabade Dec 16, 2024
07ec62c
added confirmation modal for deleting draft from bottomsheet
Rajat-Dabade Dec 16, 2024
80681bd
using common send_handler for both draft and post
Rajat-Dabade Dec 16, 2024
9ea0914
removed magic number for tooltip and bottomsheet
Rajat-Dabade Dec 17, 2024
ba7fb70
renamed channel_info to draft_post_header
Rajat-Dabade Dec 17, 2024
8d427db
text to formattedText for Edit drafts
Rajat-Dabade Dec 17, 2024
2954843
removed unnecessary changes
Rajat-Dabade Dec 17, 2024
d4c988b
minor fixes
Rajat-Dabade Dec 17, 2024
2fca19c
mounting draft only when there is draft
Rajat-Dabade Dec 31, 2024
1d7b0be
map to reduce
Rajat-Dabade Jan 6, 2025
1261a4b
renamed SwipeableDraft to DraftSwipeAction
Rajat-Dabade Jan 6, 2025
507cdeb
name fixes
Rajat-Dabade Jan 6, 2025
0a303e1
isValidUrl to isParsableUrl and added test
Rajat-Dabade Jan 6, 2025
3d426c0
added test and addressed minor review comments
Rajat-Dabade Jan 8, 2025
83d4c21
added inline component for the duplicate code
Rajat-Dabade Jan 8, 2025
f0dd52d
inlt fixes
Rajat-Dabade Jan 8, 2025
c75c9af
clearDraft is not optional
Rajat-Dabade Jan 9, 2025
4f7c2cb
optimised categories_list.tsx component
Rajat-Dabade Jan 9, 2025
da2cbdf
Swipeable to ReanimatedSwipeable, TouchableWithoutFeedback to Pressab…
Rajat-Dabade Jan 9, 2025
a5e683d
Added comment and disabled eslint rule for showing warning
Rajat-Dabade Jan 9, 2025
b2960c5
fixed component file name
Rajat-Dabade Jan 9, 2025
949089f
minor'
Rajat-Dabade Jan 9, 2025
9abea9f
Removed deprecated Animated createAnimatedComponent flatlist
Rajat-Dabade Jan 9, 2025
74d815d
added test for missing protocol check
Rajat-Dabade Jan 9, 2025
abc7f4c
import change for SwipeableMethod
Rajat-Dabade Jan 10, 2025
4cfef6b
active tab for tablet view
Rajat-Dabade Jan 13, 2025
fd0d5ff
addressed review comments
Rajat-Dabade Nov 12, 2024
89b6c3c
linter fixes
Rajat-Dabade Nov 13, 2024
3556a0e
added test for app/actions/local/draft.ts
Rajat-Dabade Nov 18, 2024
2ebbf2a
added test for app/components/channel_info/avatar/index.tsx
Rajat-Dabade Nov 18, 2024
1c4661b
added test for app/components/channel_info/channel_info.tsx
Rajat-Dabade Nov 19, 2024
b23bd9e
added unit test for app/components/draft/draft.tsx
Rajat-Dabade Nov 22, 2024
10b54b3
added test for app/components/draft/draft_post/draft_message/index.tsx
Rajat-Dabade Nov 26, 2024
976c9eb
added comparing snapshot for previously added test
Rajat-Dabade Nov 26, 2024
c6478c3
Added unit test for app/components/draft/draft_post/index.tsx
Rajat-Dabade Nov 26, 2024
0ee8296
Added jest unit test from app/components/drafts_buttton/drafts_button…
Rajat-Dabade Nov 26, 2024
a45371e
added test for app/screens/draft_options/delete_draft/index.tsx
Rajat-Dabade Nov 26, 2024
6a4ad10
added test case from edit_draft and send_draft
Rajat-Dabade Nov 26, 2024
34a142e
added test from app/screens/draft_options/index.tsx
Rajat-Dabade Nov 26, 2024
10ec08b
Added unit test for app/screens/global_drafts/components/draft_empty_…
Rajat-Dabade Nov 26, 2024
96be469
updated snapshot
Rajat-Dabade Nov 26, 2024
76c6b31
udpated snapshot
Rajat-Dabade Nov 26, 2024
37284c7
fix test and updated snapshot
Rajat-Dabade Jan 10, 2025
3f3928b
remove a from drafts_button for checking to render is draft count is 0
Rajat-Dabade Jan 10, 2025
b3b17b4
snapshot updates
Rajat-Dabade Jan 10, 2025
b42ce63
intl fixes
Rajat-Dabade Jan 10, 2025
83fda81
reverted unneccessary changes
Rajat-Dabade Jan 13, 2025
95c1549
Updated test
Rajat-Dabade Jan 13, 2025
42811c9
Merge branch 'main' into mobile-draft-test
Rajat-Dabade Jan 14, 2025
6ddf0d1
updated snapshot
Rajat-Dabade Jan 14, 2025
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
1,102 changes: 1,102 additions & 0 deletions app/components/draft/__snapshots__/draft.test.tsx.snap

Large diffs are not rendered by default.

190 changes: 190 additions & 0 deletions app/components/draft/draft.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import React from 'react';

import CompassIcon from '@components/compass_icon';
import FormattedText from '@components/formatted_text';
import {General} from '@constants';
import {renderWithEverything} from '@test/intl-test-helper';
import TestHelper from '@test/test_helper';

import Draft from './draft';

import type {Database} from '@nozbe/watermelondb';
import type ChannelModel from '@typings/database/models/servers/channel';
import type DraftModel from '@typings/database/models/servers/draft';

jest.mock('@components/formatted_text', () => jest.fn(() => null));
jest.mock('@components/formatted_time', () => jest.fn(() => null));
jest.mock('@components/compass_icon', () => jest.fn(() => null));
Comment on lines +18 to +20
Copy link
Contributor

Choose a reason for hiding this comment

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

Any strong reason to mock these three components?


describe('Draft', () => {
let database: Database;

beforeAll(async () => {
const server = await TestHelper.setupServerDatabase();
database = server.database;
});
it('should render the draft with channel info and draft message', () => {
const props = {
channel: {type: General.OPEN_CHANNEL, displayName: 'Direct Message Channel'} as ChannelModel,
location: 'channel',
draft: {
updateAt: 1633024800000,
message: 'Hello, World!',
channelId: 'channel_id',
rootId: '',
files: [],
metadata: {},
} as unknown as DraftModel,
layoutWidth: 100,
isPostPriorityEnabled: false,
};
const wrapper = renderWithEverything(
<Draft
channel={props.channel}
location={props.location}
draft={props.draft}
layoutWidth={props.layoutWidth}
isPostPriorityEnabled={props.isPostPriorityEnabled}
/>
, {database},
);

const {getByText} = wrapper;

expect(FormattedText).toHaveBeenCalledWith(
expect.objectContaining({
id: 'channel_info.draft_in_channel',
defaultMessage: 'In:',
}),
expect.anything(),
);
expect(CompassIcon).toHaveBeenCalledWith(
expect.objectContaining({
name: 'globe',
}),
expect.anything(),
);
expect(getByText('Hello, World!')).toBeTruthy();
expect(wrapper.toJSON()).toMatchSnapshot();
});

it('should match the file count', () => {
const props = {
channel: {type: General.OPEN_CHANNEL, displayName: 'Direct Message Channel'} as ChannelModel,
location: 'channel',
draft: {
updateAt: 1633024800000,
message: 'Hello, World!',
channelId: 'channel_id',
rootId: '',
files: [{
has_preview_image: false,
height: 0,
name: 'file1.txt',
extension: 'txt',
size: 64,
}, {
has_preview_image: false,
height: 0,
name: 'file2.pdf',
extension: 'txt',
size: 64,
}],
metadata: {},
} as unknown as DraftModel,
layoutWidth: 100,
isPostPriorityEnabled: false,
};
const wrapper = renderWithEverything(
<Draft
channel={props.channel}
location={props.location}
draft={props.draft}
layoutWidth={props.layoutWidth}
isPostPriorityEnabled={props.isPostPriorityEnabled}
/>
, {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', () => {
const props = {
channel: {type: General.OPEN_CHANNEL, displayName: 'Direct Message Channel'} as ChannelModel,
location: 'thread',
draft: {
updateAt: 1633024800000,
message: 'Hello, World!',
channelId: 'channel_id',
rootId: 'root_id',
files: [],
metadata: {},
} as unknown as DraftModel,
layoutWidth: 100,
isPostPriorityEnabled: false,
};
const wrapper = renderWithEverything(
<Draft
channel={props.channel}
location={props.location}
draft={props.draft}
layoutWidth={props.layoutWidth}
isPostPriorityEnabled={props.isPostPriorityEnabled}
/>
, {database},
);

const {getByText} = wrapper;
expect(FormattedText).toHaveBeenCalledWith(
expect.objectContaining({
id: 'channel_info.thread_in',
defaultMessage: 'Thread in:',
}),
expect.anything(),
);

expect(CompassIcon).toHaveBeenCalledWith(
expect.objectContaining({
name: 'globe',
}),
expect.anything(),
);
expect(getByText('Hello, World!')).toBeTruthy();
expect(wrapper.toJSON()).toMatchSnapshot();
});

it('should render the draft with post priority', () => {
const props = {
channel: {type: General.OPEN_CHANNEL, displayName: 'Direct Message Channel'} as ChannelModel,
location: 'thread',
draft: {
updateAt: 1633024800000,
message: 'Hello, World!',
channelId: 'channel_id',
rootId: 'root_id',
files: [],
metadata: {priority: {priority: 'important', requested_ack: false}},
} as unknown as DraftModel,
layoutWidth: 100,
isPostPriorityEnabled: true,
};
const wrapper = renderWithEverything(
<Draft
channel={props.channel}
location={props.location}
draft={props.draft}
layoutWidth={props.layoutWidth}
isPostPriorityEnabled={props.isPostPriorityEnabled}
/>
, {database},
);
const {getByText} = wrapper;
expect(getByText('IMPORTANT')).toBeTruthy();
expect(wrapper.toJSON()).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Draft Message should match snapshot 1`] = `
<View
style={
{
"maxHeight": 721,
}
}
testID="draft_message"
>
<RCTScrollView
keyboardShouldPersistTaps="always"
scrollEnabled={false}
showsHorizontalScrollIndicator={false}
showsVerticalScrollIndicator={false}
>
<View>
<View
onLayout={[Function]}
style={
[
{
"width": "100%",
},
]
}
>
<View
style={
[
{
"alignItems": "flex-start",
"flexDirection": "row",
"flexWrap": "wrap",
},
]
}
testID="markdown_paragraph"
>
<Text>
<Text
selectable={false}
style={
{
"color": "#3f4350",
"fontFamily": "OpenSans",
"fontSize": 16,
"fontWeight": "400",
"lineHeight": 24,
}
}
testID="markdown_text"
>
Hello, World!
</Text>
</Text>
</View>
</View>
</View>
</RCTScrollView>
</View>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Draft Post should match the snapshot 1`] = `
<View
style={
{
"marginTop": 12,
}
}
testID="draft_post_with_message_and_file"
>
<View
style={
{
"maxHeight": 721,
}
}
testID="draft_message"
>
<RCTScrollView
keyboardShouldPersistTaps="always"
scrollEnabled={false}
showsHorizontalScrollIndicator={false}
showsVerticalScrollIndicator={false}
>
<View>
<View
onLayout={[Function]}
style={
[
{
"width": "100%",
},
]
}
>
<View
style={
[
{
"alignItems": "flex-start",
"flexDirection": "row",
"flexWrap": "wrap",
},
]
}
testID="markdown_paragraph"
>
<Text>
<Text
selectable={false}
style={
{
"color": "#3f4350",
"fontFamily": "OpenSans",
"fontSize": 16,
"fontWeight": "400",
"lineHeight": 24,
}
}
testID="markdown_text"
>
Hello, World!
</Text>
</Text>
</View>
</View>
</View>
</RCTScrollView>
</View>
</View>
`;
59 changes: 59 additions & 0 deletions app/components/draft/draft_post/draft_message.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import React from 'react';

import {renderWithEverything} from '@test/intl-test-helper';
import TestHelper from '@test/test_helper';

import DraftMessage from './draft_message';

import type {Database} from '@nozbe/watermelondb';
import type DraftModel from '@typings/database/models/servers/draft';

describe('Draft Message', () => {
let database: Database;

beforeAll(async () => {
const server = await TestHelper.setupServerDatabase();
database = server.database;
});
it('should render the message', () => {
const props = {
draft: {
updateAt: 1633024800000,
message: 'Hello, World!',
channelId: 'channel_id',
rootId: '',
files: [],
metadata: {},
} as unknown as DraftModel,
layoutWidth: 100,
location: 'draft',
};
const {getByText} = renderWithEverything(
<DraftMessage {...props}/>, {database},
);
expect(getByText('Hello, World!')).toBeTruthy();
});

it('should match snapshot', () => {
const props = {
draft: {
updateAt: 1633024800000,
message: 'Hello, World!',
channelId: 'channel_id',
rootId: '',
files: [],
metadata: {},
} as unknown as DraftModel,
layoutWidth: 100,
location: 'draft',
};
const wrapper = renderWithEverything(
<DraftMessage {...props}/>, {database},
);

expect(wrapper.toJSON()).toMatchSnapshot();
});
});
Loading
Loading