Skip to content
This repository was archived by the owner on Jul 13, 2022. It is now read-only.

Fixed JS crash between 11pm and 11:59pm when no time values are available#31

Merged
jimleroyer merged 4 commits into
masterfrom
fix/11pm-crash
Apr 7, 2021
Merged

Fixed JS crash between 11pm and 11:59pm when no time values are available#31
jimleroyer merged 4 commits into
masterfrom
fix/11pm-crash

Conversation

@jimleroyer

@jimleroyer jimleroyer commented Apr 7, 2021

Copy link
Copy Markdown
Member

Summary | Résumé

  • TRELLO: Fix the scheduler bug that triggers a Javascript error past 23h00 until 23h59 included.
  • Fix month not switching on last month date and smaller availability period of less than a month.

Show case of these two bugs are demonstrated in this other draft PR/branch:
#33

Test instructions | Instructions pour tester la modification

  1. Set the local computer clock to 23h00.
  2. Start the calendar via npm run start.

Previously, the scheduler would not properly load past 23h00 due to a Javascript error. This should now load fine and display all available hourly time slots for the next day.

Help requested | Aide requise

There is one test that fails with a timeout on a calendar month change. This might be due to different Reactjs state.

Reviewer checklist | Liste de vérification du réviseur

This is a suggested checklist of questions reviewers might ask during their
review | Voici une suggestion de liste de vérification comprenant des questions
que les réviseurs pourraient poser pendant leur examen :

  • Does this meet a user need? | Est-ce que ça répond à un besoin utilisateur?
  • Is it accessible? | Est-ce que c’est accessible?
  • Is it translated between both offical languages? | Est-ce dans les deux
    langues officielles?
  • Is the code maintainable? | Est-ce que le code peut être maintenu?
  • Have you tested it? | L’avez-vous testé?
  • Are there automated tests? | Y a-t-il des tests automatisés?
  • Does this cause automated test coverage to drop? | Est-ce que ça entraîne
    une baisse de la quantité de code couvert par les tests automatisés?
  • Does this break existing functionality? | Est-ce que ça brise une
    fonctionnalité existante?
  • Should this be split into smaller PRs to decrease change risk? | Est-ce
    que ça devrait être divisé en de plus petites demandes de tirage (« pull
    requests ») afin de réduire le risque lié aux modifications?
  • Does this change the privacy policy? | Est-ce que ça entraîne une
    modification de la politique de confidentialité?
  • Does this introduce any security concerns? | Est-ce que ça introduit des
    préoccupations liées à la sécurité?
  • Does this significantly alter performance? | Est-ce que ça modifie de
    façon importante la performance?
  • What is the risk level of using added dependencies? | Quel est le degré de
    risque d’utiliser des dépendances ajoutées?
  • Should any documentation be updated as a result of this? (i.e. README
    setup, etc.) | Faudra-t-il mettre à jour la documentation à la suite de ce
    changement (fichier README, etc.)?

@jimleroyer jimleroyer requested a review from timarney April 7, 2021 14:42
expect(culled_time_values).not.toHaveLength(6);
const now = dayjs().hour(13).minute(59).toString();
const culled_time_values = timeValuesToday(now, constructedToday, state.time_values);
expect(culled_time_values).toHaveLength(3);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

By adding a new parameter representing the current time to the timeValuesToday function, we decouple our reliance on current moving time when the test is running. We can hence test a more edgy scenario where we need to discard 3 hours and keep 3 hours. This should get rid of the previous failure too happening between midnight and 1 AM, as we have a pure function now with no time reading side effect.

if (Number(state.focusedDayNum) === Number(state.lastDay)) {
const newMonth = dayjs(state.date)
.add(1, "month")
.add(1, "day")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The logic verifies if the last day of the month is the currently selected date. If yes, we either increment the month or not, depending if the last available date was reached.

The logic adds 1 month though to make that check, not merely adding 1 day to get to the next month, i.e. 29 feb will be 29 march, instead of 1st march.

It might worked before though because the last available date setup in the store during initialization was set to 1 month. I set it to 96 hours inadvertently with a copy/paste because this is what is used in Notify. Hence this trigger this bug discovery.

By adding 1 day instead, this should increment to the next month and be within the available time period if it applies.

expect(label).toEqual("Unavailable, Friday February 28 2020");
});

test("Handles key nav events", async () => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is a new test that should trigger the fail scenario we encountered in Notify, i.e. get past 11 pm, the calendar will produce a Javascript error when trying to read inexistent values of available culled time.

@timarney

timarney commented Apr 7, 2021

Copy link
Copy Markdown
Member

Thanks for adding specific tests for this.

Key to note as mentioned above

By adding 1 day instead, this should increment to the next month and be within the available time period if it applies.

@jimleroyer jimleroyer merged commit 96dc760 into master Apr 7, 2021
@jimleroyer jimleroyer deleted the fix/11pm-crash branch April 7, 2021 22:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants