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

Add unit tests for common sidebar functionality #10619

Merged
merged 45 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
f61d54b
Add skeleton unit test
tgolen Aug 27, 2022
ab12338
Switch test rendering lib
tgolen Aug 27, 2022
9aa11a1
Get component to render inside a test
tgolen Aug 27, 2022
596d17a
Struggle rendering icon
tgolen Aug 27, 2022
278605d
Fix errors for rendering an SVG
tgolen Aug 28, 2022
0234575
Get the tests passing
tgolen Aug 28, 2022
c0259be
Add comments to the tests
tgolen Aug 28, 2022
40c2cad
Cleanup tests and clear onyx after each test
tgolen Aug 28, 2022
f5aabd3
Remove unnecessary onyx key for preferred locale
tgolen Aug 28, 2022
3fdd8a0
Test that one report is showing in the list
tgolen Aug 28, 2022
aca004b
Have test verify no items were rendered
tgolen Aug 28, 2022
cfd7e37
Remove unused import
tgolen Aug 28, 2022
0173c33
Add a way to supprest proptype warnings
tgolen Aug 28, 2022
0e3e13d
Switch to a better method for checking array length
tgolen Aug 28, 2022
4779610
Add a test for the order of reports
tgolen Aug 28, 2022
ece7808
Remove nested promises
tgolen Aug 28, 2022
0b914d6
Change participant names to identify the reports
tgolen Aug 28, 2022
c618fed
Add a test for draft comments on the active report
tgolen Aug 28, 2022
e58c132
Merge branch 'main' into tgolen-test-sidebarlinks
tgolen Aug 29, 2022
6590435
WIP trying to get context providers to work
tgolen Aug 29, 2022
33b19e0
WIP trying to get context providers to work
tgolen Aug 29, 2022
4ed2bff
Get the context provider working
tgolen Aug 29, 2022
9d59462
Pass a string for reportID instead of a number
tgolen Aug 29, 2022
07c5cfd
Add a test for the pencil icon
tgolen Aug 29, 2022
720b875
Get the tests working for reports with drafts
tgolen Aug 29, 2022
115854c
Split up the tests so they are smaller
tgolen Aug 29, 2022
2a7f583
Add a test for new comments added to active report
tgolen Aug 30, 2022
2815b5a
Add a test for switching chats while a report has a draft
tgolen Aug 30, 2022
e37356d
Add a test for switching chats while a report has a draft
tgolen Aug 30, 2022
dd447ea
Add a test for the removal of the pencil icon
tgolen Aug 30, 2022
6a5c8e2
Add a test for keeping draft reports on top
tgolen Aug 30, 2022
7e525cd
Add a test for page refresh
tgolen Aug 30, 2022
3f7ee72
Fix broken test
tgolen Aug 30, 2022
545991d
Merge branch 'main' into tgolen-test-sidebarlinks
tgolen Aug 30, 2022
ac12528
Refactor tests for removing of draft onyx key
tgolen Aug 30, 2022
9b81d5a
Fix a bad merge conflict
tgolen Aug 30, 2022
14ee46d
Fix some proptype warnings
tgolen Aug 30, 2022
19b2e43
Simplify the hasDraftComment property
tgolen Aug 30, 2022
21a1c6a
WIP to fix broken test
tgolen Aug 30, 2022
e6e9a18
Add a comment about why the test doesn't work
tgolen Aug 30, 2022
b97e5b1
Merge branch 'main' into tgolen-test-sidebarlinks
tgolen Aug 30, 2022
38f8541
Move accessability hint onto the icon component
tgolen Aug 30, 2022
394f30d
Fix lint errors
tgolen Aug 30, 2022
e92e258
Update src/pages/home/sidebar/SidebarLinks.js
tgolen Aug 31, 2022
e464e8e
Remove unnecessary disable of automocking
tgolen Aug 31, 2022
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 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ const CONST = {
TYPE: {
FREE: 'free',
PERSONAL: 'personal',
CORPORATE: 'corporate',
},
ROLE: {
ADMIN: 'admin',
Expand Down
1 change: 0 additions & 1 deletion src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export default {
REPORT_USER_IS_TYPING: 'reportUserIsTyping_',
REPORT_IOUS: 'reportIOUs_',
POLICY: 'policy_',
REPORTS_WITH_DRAFT: 'reportWithDraft_',
REPORT_IS_COMPOSER_FULL_SIZE: 'reportIsComposerFullSize_',
POLICY_MEMBER_LIST: 'policyMemberList_',
},
Expand Down
24 changes: 13 additions & 11 deletions src/components/Icon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,29 @@ class Icon extends PureComponent {
render() {
const width = this.props.small ? variables.iconSizeSmall : this.props.width;
const height = this.props.small ? variables.iconSizeSmall : this.props.height;
const IconToRender = this.props.src;

const icon = (
<IconToRender
width={width}
height={height}
fill={this.props.fill}
/>
);

if (this.props.inline) {
return (
<View style={[StyleUtils.getWidthAndHeightStyle(width, height), styles.bgTransparent, styles.overflowVisible]}>
<View
accessibilityHint={`${this.props.src.name} Icon`}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This small refactoring done in this file was to add this prop, which allowed the Icon to be targetted by the unit tests. The rest of the changes in this file are just some cleaning up.

style={[StyleUtils.getWidthAndHeightStyle(width, height), styles.bgTransparent, styles.overflowVisible]}
>
<View style={[StyleUtils.getWidthAndHeightStyle(width, height), IconWrapperStyles, styles.pAbsolute]}>
{icon}
</View>
</View>
);
}

return icon;
return (
<View accessibilityHint={`${this.props.src.name} Icon`}>
<this.props.src
width={width}
height={height}
fill={this.props.fill}
/>
</View>
);
}
}

Expand Down
15 changes: 2 additions & 13 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,6 @@ function getSearchText(report, reportName, personalDetailList, isChatRoomOrPolic
return _.unique(searchTerms).join(' ');
}

/**
* Determines whether a report has a draft comment.
*
* @param {Object} report
* @return {Boolean}
*/
function hasReportDraftComment(report) {
return lodashGet(report, 'hasDraft', false);
}

/**
* If the report or the report actions have errors, return
* CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR, otherwise an empty string.
Expand Down Expand Up @@ -234,7 +224,6 @@ function createOption(logins, personalDetails, report, reportActions = {}, {
const isArchivedRoom = ReportUtils.isArchivedRoom(report);
const hasMultipleParticipants = personalDetailList.length > 1 || isChatRoom || isPolicyExpenseChat;
const personalDetail = personalDetailList[0];
const hasDraftComment = hasReportDraftComment(report);
const hasOutstandingIOU = lodashGet(report, 'hasOutstandingIOU', false);
const iouReport = hasOutstandingIOU
? lodashGet(iouReports, `${ONYXKEYS.COLLECTION.REPORT_IOUS}${report.iouReportID}`, {})
Expand Down Expand Up @@ -287,7 +276,7 @@ function createOption(logins, personalDetails, report, reportActions = {}, {
phoneNumber: !hasMultipleParticipants ? personalDetail.phoneNumber : null,
payPalMeAddress: !hasMultipleParticipants ? personalDetail.payPalMeAddress : null,
isUnread: report ? report.unreadActionCount > 0 : null,
hasDraftComment,
hasDraftComment: lodashGet(report, 'hasDraft', false),
keyForList: report ? String(report.reportID) : personalDetail.login,
searchText: getSearchText(report, reportName, personalDetailList, isChatRoom || isPolicyExpenseChat),
isPinned: lodashGet(report, 'isPinned', false),
Expand Down Expand Up @@ -424,7 +413,7 @@ function getOptions(reports, personalDetails, activeReportID, {
return;
}

const hasDraftComment = hasReportDraftComment(report);
const hasDraftComment = lodashGet(report, 'hasDraft', false);
const iouReportOwner = lodashGet(report, 'hasOutstandingIOU', false)
? lodashGet(iouReports, [`${ONYXKEYS.COLLECTION.REPORT_IOUS}${report.iouReportID}`, 'ownerEmail'], '')
: '';
Expand Down
3 changes: 2 additions & 1 deletion src/pages/home/report/ReportActionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const propTypes = {
mostRecentIOUReportSequenceNumber: PropTypes.number,

/** Are we loading more report actions? */
isLoadingMoreReportActions: PropTypes.bool.isRequired,
isLoadingMoreReportActions: PropTypes.bool,

/** Callback executed on list layout */
onLayout: PropTypes.func.isRequired,
Expand All @@ -68,6 +68,7 @@ const propTypes = {
const defaultProps = {
personalDetails: {},
mostRecentIOUReportSequenceNumber: undefined,
isLoadingMoreReportActions: false,
};

class ReportActionsList extends React.Component {
Expand Down
5 changes: 4 additions & 1 deletion src/pages/home/sidebar/SidebarLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const propTypes = {

/** Number of unread actions on the report */
unreadActionCount: PropTypes.number,

/** Whether or not the report has a draft comment */
tgolen marked this conversation as resolved.
Show resolved Hide resolved
hasDraft: PropTypes.bool,
})),

/** List of users' personal details */
Expand Down Expand Up @@ -219,7 +222,7 @@ class SidebarLinks extends React.Component {

// Because we are using map, we have to filter out any undefined reports. This happens if recentReports
// does not have all the conversations in prevState.orderedReports
.filter(orderedReport => orderedReport !== undefined)
.compact()
.value();

return {
Expand Down
Loading