-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Rajat-Dabade
wants to merge
113
commits into
main
Choose a base branch
from
mobile-draft-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 11e758e
refactor: change the query and added the screen for draft
Rajat-Dabade d72a19f
added condition for fetching draft for channel delete or not
Rajat-Dabade 572d65b
refactor: added draft screen
Rajat-Dabade d5389b8
linter fixes
Rajat-Dabade ae55bde
Added draft post component
Rajat-Dabade afbe59d
added avatar and header display name for the draft post list
Rajat-Dabade 6c99a7c
added channel info component
Rajat-Dabade 9fcbf84
channel info completed
Rajat-Dabade d688908
proper naming
Rajat-Dabade 324aa16
added image file markdown acknowledgement support
Rajat-Dabade 65b6edd
draft actions
Rajat-Dabade 272c468
Fix the draft receiver in drafts
Rajat-Dabade 1fa189a
separated send message handler
Rajat-Dabade ba3ee8d
Done with send drafts
Rajat-Dabade 554123f
done with delete drafts
Rajat-Dabade e629247
change save to send draft
Rajat-Dabade f8bcead
handle lengthy message with show more button
Rajat-Dabade 6577c6e
done with persistent message edit, send and delete drafts
Rajat-Dabade d331d46
added alert for sending message
Rajat-Dabade 62d0bbb
added update at time for the drafts
Rajat-Dabade 5308824
en.json extract fix
Rajat-Dabade 611cff0
Updated dependencies for useCallback
Rajat-Dabade aac1f38
refactor: added drafts list to animated list
Rajat-Dabade 8c153d6
added swipeable component and delete conformation for drafts
Rajat-Dabade 112048a
done with rendering of images in markdown for drafts
Rajat-Dabade 2589127
en.json issue fixed
Rajat-Dabade a70b165
fix en.json issue
Rajat-Dabade 6f56a41
refactor: en.json fix
Rajat-Dabade e140826
addressed review comments
Rajat-Dabade a85a1a4
updated image metadata handling code
Rajat-Dabade c72c14d
linter fixes
Rajat-Dabade f5b884a
added the empty draft screen
Rajat-Dabade cffb22b
linter fix
Rajat-Dabade b9c48d5
style fix
Rajat-Dabade 424c773
back button an android takes to the channel list page
Rajat-Dabade 6f054ae
en.json fix
Rajat-Dabade 15e6bc3
draft actions theme compatible
Rajat-Dabade faabf4e
CSS fix for draft channel_info and avatar component
Rajat-Dabade 9b130b6
removed the badge icon and change font style drafts
Rajat-Dabade c595c3d
fix send alert sender name for GMs
Rajat-Dabade b167354
updated snapshot
Rajat-Dabade eee6c26
added testId to the drafts components
Rajat-Dabade 47ac4fe
updated send draft test id
Rajat-Dabade a842910
clicking on draft takes to the channel
Rajat-Dabade b26aa59
Added toptip for draft tours
Rajat-Dabade 3d16827
intl extract
Rajat-Dabade 5d7bc78
Rebase to main and reverted local testing changes
Rajat-Dabade e667dd7
Added tooltip for drafts
Rajat-Dabade f152788
addressed review comments
Rajat-Dabade aa1ad72
reset navigation when click on a draft in draft tabs
Rajat-Dabade f2e2e47
Merge branch 'main' into mobile-drafts
mattermost-build cd93248
fix the theme issue and navigation issue
Rajat-Dabade 8965394
reverted back the draft click navigation changes
Rajat-Dabade 8c8e6f6
observing draft when hitting back button
Rajat-Dabade be07659
removed the unwanted animiation
Rajat-Dabade ab7ce3a
updated regex for parsing markdown
Rajat-Dabade 2b5a671
removed unnecessary checks and change folder name
Rajat-Dabade 22f1528
removed react memo and merge unwanted observes function
Rajat-Dabade a542590
removed unnecessary comments
Rajat-Dabade ea131a8
changed the name for observing and querying draft function
Rajat-Dabade 1ca7ddb
removed memo from component level
Rajat-Dabade 8a1952e
Text to FormattedText component
Rajat-Dabade 2941ab1
Text to formatted text, change image name
Rajat-Dabade 07ec62c
added confirmation modal for deleting draft from bottomsheet
Rajat-Dabade 80681bd
using common send_handler for both draft and post
Rajat-Dabade 9ea0914
removed magic number for tooltip and bottomsheet
Rajat-Dabade ba7fb70
renamed channel_info to draft_post_header
Rajat-Dabade 8d427db
text to formattedText for Edit drafts
Rajat-Dabade 2954843
removed unnecessary changes
Rajat-Dabade d4c988b
minor fixes
Rajat-Dabade 2fca19c
mounting draft only when there is draft
Rajat-Dabade 1d7b0be
map to reduce
Rajat-Dabade 1261a4b
renamed SwipeableDraft to DraftSwipeAction
Rajat-Dabade 507cdeb
name fixes
Rajat-Dabade 0a303e1
isValidUrl to isParsableUrl and added test
Rajat-Dabade 3d426c0
added test and addressed minor review comments
Rajat-Dabade 83d4c21
added inline component for the duplicate code
Rajat-Dabade f0dd52d
inlt fixes
Rajat-Dabade c75c9af
clearDraft is not optional
Rajat-Dabade 4f7c2cb
optimised categories_list.tsx component
Rajat-Dabade da2cbdf
Swipeable to ReanimatedSwipeable, TouchableWithoutFeedback to Pressab…
Rajat-Dabade a5e683d
Added comment and disabled eslint rule for showing warning
Rajat-Dabade b2960c5
fixed component file name
Rajat-Dabade 949089f
minor'
Rajat-Dabade 9abea9f
Removed deprecated Animated createAnimatedComponent flatlist
Rajat-Dabade 74d815d
added test for missing protocol check
Rajat-Dabade abc7f4c
import change for SwipeableMethod
Rajat-Dabade 4cfef6b
active tab for tablet view
Rajat-Dabade fd0d5ff
addressed review comments
Rajat-Dabade 89b6c3c
linter fixes
Rajat-Dabade 3556a0e
added test for app/actions/local/draft.ts
Rajat-Dabade 2ebbf2a
added test for app/components/channel_info/avatar/index.tsx
Rajat-Dabade 1c4661b
added test for app/components/channel_info/channel_info.tsx
Rajat-Dabade b23bd9e
added unit test for app/components/draft/draft.tsx
Rajat-Dabade 10b54b3
added test for app/components/draft/draft_post/draft_message/index.tsx
Rajat-Dabade 976c9eb
added comparing snapshot for previously added test
Rajat-Dabade c6478c3
Added unit test for app/components/draft/draft_post/index.tsx
Rajat-Dabade 0ee8296
Added jest unit test from app/components/drafts_buttton/drafts_button…
Rajat-Dabade a45371e
added test for app/screens/draft_options/delete_draft/index.tsx
Rajat-Dabade 6a4ad10
added test case from edit_draft and send_draft
Rajat-Dabade 34a142e
added test from app/screens/draft_options/index.tsx
Rajat-Dabade 10ec08b
Added unit test for app/screens/global_drafts/components/draft_empty_…
Rajat-Dabade 96be469
updated snapshot
Rajat-Dabade 76c6b31
udpated snapshot
Rajat-Dabade 37284c7
fix test and updated snapshot
Rajat-Dabade 3f3928b
remove a from drafts_button for checking to render is draft count is 0
Rajat-Dabade b3b17b4
snapshot updates
Rajat-Dabade b42ce63
intl fixes
Rajat-Dabade 83fda81
reverted unneccessary changes
Rajat-Dabade 95c1549
Updated test
Rajat-Dabade 42811c9
Merge branch 'main' into mobile-draft-test
Rajat-Dabade 6ddf0d1
updated snapshot
Rajat-Dabade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1,102 changes: 1,102 additions & 0 deletions
1,102
app/components/draft/__snapshots__/draft.test.tsx.snap
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
|
||
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(); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
app/components/draft/draft_post/__snapshots__/draft_message.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
`; |
72 changes: 72 additions & 0 deletions
72
app/components/draft/draft_post/__snapshots__/draft_post.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?