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

fixed completion date error msg for falsy start date #565

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 9 additions & 3 deletions src/components/member-profile/active-task/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ import { percentageofDaysRemaining } from '@helper-functions/taskProgress';
import { estimatedDays } from '@helper-functions/estimated-days';
import { progressIndicator } from '@helper-functions/progressIndicator';

const ActiveTask = ({ taskDetails }) => {
const ActiveTask = ({ taskDetails, devUser }) => {
const { title, purpose, startedOn, endsOn, percentCompleted } = taskDetails;
const completedDate = timeWas(startedOn * 1000, false, endsOn * 1000);
const completedDate = timeWas(
startedOn * 1000,
false,
endsOn * 1000,
devUser
);
const percentOfTaskLeft = 100 - percentCompleted;
const percentageOfDaysRemaining = percentageofDaysRemaining(
startedOn,
endsOn,
completedDate
completedDate,
devUser
);
const showEstimatedDay = estimatedDays(
percentageOfDaysRemaining,
Expand Down
2 changes: 1 addition & 1 deletion src/components/member-profile/contribution-type/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
if (devUser) {
if (tasks?.length > 0) {
return tasks.map((task, index) => {
return <ActiveTask key={index} taskDetails={task} />;
return <ActiveTask key={index} taskDetails={task} devUser={devUser} />;
});
}
return (
Expand All @@ -78,7 +78,7 @@
return;
}
setShowMoreContent(tasks.length > 0);
}, [tasks.length, contributions.length]);

Check warning on line 81 in src/components/member-profile/contribution-type/index.js

View workflow job for this annotation

GitHub Actions / build (16.x)

React Hook useEffect has a missing dependency: 'isContribution'. Either include it or remove the dependency array

const showMoreContentHandler = () => {
if (devUser) {
Expand Down
12 changes: 6 additions & 6 deletions src/components/member-profile/contribution/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,22 @@ const ContributionCard = ({
if (isTitleAvailable) {
if (status !== 'VERIFIED') {
completedText = <span>Estimated Completion: </span>;
completedDate = timeWas(startedOn * 1000, false, endsOn * 1000);
completedDate = timeWas(startedOn * 1000, false, endsOn * 1000, devUser);
} else {
completedDate = timeWas(startedOn * 1000, false, endsOn * 1000);
completedDate = timeWas(startedOn * 1000, false, endsOn * 1000, devUser);
completedText = <span>Completed in: </span>;
featureLiveDate = timeWas(endsOn * 1000, true);
featureLiveDate = timeWas(endsOn * 1000, true, Date.now(), devUser);
featureLiveOnText = featureLiveDate;
}
} else {
const createdAt = +new Date(prList[0].createdAt);
const updatedAt = +new Date(prList[0].updatedAt);
if (prList[0].state === 'closed') {
completedDate = timeWas(createdAt, false, updatedAt);
completedDate = timeWas(createdAt, false, updatedAt, devUser);
completedText = (
<span className={classNames.completedText}>Completed in </span>
);
featureLiveDate = timeWas(updatedAt, true);
featureLiveDate = timeWas(updatedAt, true, Date.now(), devUser);
featureLiveOnText = featureLiveDate;
}
}
Expand Down Expand Up @@ -202,7 +202,7 @@ ContributionCard.propTypes = {
imageLink: PropTypes.string.isRequired,
devUser: PropTypes.bool.isRequired,
url: PropTypes.string.isRequired,
urlObj: PropTypes.instanceOf(Object).isRequired,
urlObj: PropTypes.instanceOf(URL).isRequired,
};

export default Contribution;
1 change: 1 addition & 0 deletions src/constants/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export const emptyContributionsError =
'No Contributions have been received yet.';
export const emptyNoteworthyContributionsError =
'It would be wonderful to see some noteworthy contributions made.';
export const notAvailableError = 'N/A';
11 changes: 8 additions & 3 deletions src/helper-functions/taskProgress.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { timeWas } from '@helper-functions/time-was';

const percentageofDaysRemaining = (startedOn, endsOn, completedDate) => {
const startDate = timeWas(startedOn * 1000, true, endsOn * 1000);
const endDate = timeWas(endsOn * 1000, true, startDate * 1000);
const percentageofDaysRemaining = (
startedOn,
endsOn,
completedDate,
devUser
) => {
const startDate = timeWas(startedOn * 1000, true, endsOn * 1000, devUser);
const endDate = timeWas(endsOn * 1000, true, startDate * 1000, devUser);
const date1 = new Date(startDate);
const date2 = new Date(endDate);
const diffTime = Math.abs(date2 - date1);
Expand Down
12 changes: 11 additions & 1 deletion src/helper-functions/time-was.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { notAvailableError } from '@constants/error-messages';

const calc = (interval, cycle) => Math.floor(cycle / interval);

function timeWas(timestamp, completeDate = false, differentNow = Date.now()) {
function timeWas(
timestamp,
completeDate = false,
differentNow = Date.now(),
devUser
) {
if (devUser && (!timestamp || timestamp === 0)) {
return notAvailableError;
}
const timeInSec = Math.floor(differentNow - timestamp) / 1000;

/**
Expand Down
87 changes: 87 additions & 0 deletions src/test/unit/components/member-profile/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
emptyActiveTasksError,
emptyContributionsError,
emptyNoteworthyContributionsError,
notAvailableError,
} from '@constants/error-messages';

const notaMember = {
Expand Down Expand Up @@ -128,6 +129,92 @@ describe('Members Profile', () => {
);
expect(emptyNoteworthyContributionsErrorElement).toBeInTheDocument();
});
it('Should render notAvailable error message in completion date, if start date is falsy inside task/contrbution object', () => {
const tasksWithEmptyStartDateAsFalsy = [
{
id: 'eHjZi3jzyqep43GvK2Rf',
percentCompleted: 50,
endsOn: '1698085740',
github: {
issue: {
html_url: 'https://github.com/Real-Dev-Squad/mobile-app/issues/263',
id: '1914069956',
assignee: 'harshitadatra',
status: 'open',
},
},
createdBy: 'amitprakash',
assignee: 'prakash',
title: 'Animation enhancement in Goals page',
type: 'feature',
priority: 'TBD',
startedOn: null,
status: 'IN_PROGRESS',
featureUrl:
'https://github.com/Real-Dev-Squad/website-members/issues/562',
assigneeId: 'YzEVZ50DHr37oL1mqqbO',
},
];

const contributionsWithStartDateAsFalsy = {
all: [
{
task: {
id: 'CdsWvmW2c9h5D08bHsYa',
title: 'Dummy Title',
endsOn: '1697155200',
startedOn: '0',
status: 'COMPLETED',
featureUrl:
'https://github.com/Real-Dev-Squad/website-members/issues/562',
participants: [],
},
prList: [],
},
],
noteworthy: [
{
task: {
id: 'CdsWvmW2c9h5D08bHsYa',
title: 'Dummy Title',
endsOn: '1697155200',
startedOn: undefined,
featureUrl:
'https://github.com/Real-Dev-Squad/website-members/issues/562',
status: 'COMPLETED',
participants: [],
},
prList: [],
},
],
};
render(
<KeyboardProvider
initialValue={{
isOptionKeyPressed: true,
setIsOptionKeyPressed: jest.fn(),
}}
>
<UserContextProvider value={initialUserContext}>
<TaskContextProvider>
<Profile
membersData={isaMember}
devUser
tasks={tasksWithEmptyStartDateAsFalsy}
contributions={contributionsWithStartDateAsFalsy}
/>
</TaskContextProvider>
</UserContextProvider>
</KeyboardProvider>
);
const notAvailableCompletetionDateElements =
screen.queryAllByText(notAvailableError);
notAvailableCompletetionDateElements.forEach((element) => {
expect(element).toHaveTextContent(notAvailableError);
});

expect(notAvailableCompletetionDateElements).toHaveLength(3);
});

it('Should render the info icon correctly', () => {
render(
Expand Down
Loading