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

Refactor HandleClickInTimeLine to handle edge cases & Add Unit Tests #78

Open
wants to merge 10 commits into
base: merge-optimization
Choose a base branch
from

Conversation

hieudan225
Copy link
Contributor

  1. On writing test for handle click in Timeline feature, I realize the current code can't handle cases where one 30-min div has a small TravelObject in the middle of the div.
    For example:
    image

If user clicks in part A or part B of the div, the current code doesn't know which part is clicked and just return a random one A or B.
Before, we thought that using a function which looks for overlapping between the clicked div and a array of free Timeslot would help, but it only helps in cases like this (meaning overlapping function only helps deal with cases where a 30-min div has only one free timeslot):

image

Thus, this PR:

  1. adds function to calculate the exact timePoint the user clicks into instead. (See OneHourInterval)
  2. removes the getFreeTimeSlot and searchForOverlappingPoint function
  3. adds unit tests to test the handleClickedTimePoint function. (See HandleClickedTimePoint)

(1) and (2) help reduce the time complexity of the handle click in Timeline feature from O(n) to O(logn) (where n is the number of displayItems), since we no longer need to iterate through displayItems to get the free timeslots anymore.

@google-cla google-cla bot added the cla: yes label Jul 31, 2020
@hieudan225 hieudan225 changed the base branch from master to merge-optimization July 31, 2020 14:13
@@ -0,0 +1,666 @@
import "@testing-library/jest-dom";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please checkout this unit test file as well :D

Copy link
Collaborator

Choose a reason for hiding this comment

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

The test looks fine overall but there are some duplicate cases that looks like they could be eliminated. I see that there are a few foundational cases (clicking in between, clicking in, clicking before, clicking after an event, handling overflow events, etc) but it looks like the tests cover these for a different N number of events (2-5 events). If the cases are handled the same way regardless of N then it's probably better to have less tests for the same coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Chris, thank you for your comments! I was just thinking it'll be better to test the binary search algorithm with different array length as well as different search positions. (array in this case is displayItems) Can you tell me about your thoughts? @cthamrun

@@ -21,9 +24,33 @@ export default function OneHourInterval(props) {
}),
});

// Given a id of a div and an mouse click event
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: "Given an id of a div and a mouse click event"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you! Addressed :D

});
});

test("Case 4: One travelobject overflows from the previous day and clickPoint is in the rest of the day", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I'm understanding this correctly, maybe this should be clarified as "clickPoint is in the part of the day after overflow event"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion! I'll rename the test like your suggestion.

});
});

test("Case 5: One travelobject overflows to the next day and clickPoint is in the rest of the day", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I'm understanding this correctly, maybe this should be clarified as "clickPoint is in the part of the day before overflow event"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion! I'll rename the test like your suggestion.

@@ -0,0 +1,666 @@
import "@testing-library/jest-dom";
Copy link
Collaborator

Choose a reason for hiding this comment

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

The test looks fine overall but there are some duplicate cases that looks like they could be eliminated. I see that there are a few foundational cases (clicking in between, clicking in, clicking before, clicking after an event, handling overflow events, etc) but it looks like the tests cover these for a different N number of events (2-5 events). If the cases are handled the same way regardless of N then it's probably better to have less tests for the same coverage.

Copy link
Collaborator

@zirving zirving left a comment

Choose a reason for hiding this comment

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

LGTM

@hieudan225 hieudan225 requested a review from cthamrun August 4, 2020 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants