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(TimezoneSelector): simplify override logics and tests #19090

Merged
merged 1 commit into from
Mar 11, 2022

Conversation

ktmud
Copy link
Member

@ktmud ktmud commented Mar 10, 2022

SUMMARY

Encountered a broken unit test in TimezoneSelector after making changes in #19085 , found some room for improvements so I refactored this component a little: simplified the timezone overriding logics and made the unit tests more complete. See comments for details.

As the changes are quite significant and the component itself is small, it may be easier to review the diff in split view.

Xnip2022-03-09_17-32-11

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

No visual changes

TESTING INSTRUCTIONS

Test places where timezone selector is used. The functionality should not change.

ADDITIONAL INFORMATION

@ktmud ktmud requested a review from eschutho March 10, 2022 01:30
@ktmud ktmud force-pushed the refactor-timezone-selector branch 2 times, most recently from 0987b3a to a2095c8 Compare March 10, 2022 01:36
Copy link
Member Author

@ktmud ktmud left a comment

Choose a reason for hiding this comment

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

@eschutho could you confirm whether the updated code still produces the desired behavior for TimezoneSelector?

moment.tz(currentDate, a.timezoneName).utcOffset() -
moment.tz(currentDate, b.timezoneName).utcOffset();

TIMEZONE_OPTIONS.sort(TIMEZONE_OPTIONS_SORT_COMPARATOR);
Copy link
Member Author

Choose a reason for hiding this comment

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

#19085 requires select options to be pre-sorted.

// others are ranked by offset
expect(options[1]).toHaveTextContent('GMT -11:00 (Pacific/Pago_Pago)');
expect(options[2]).toHaveTextContent('GMT -10:00 (Hawaii Standard Time)');
expect(options[3]).toHaveTextContent('GMT -10:00 (America/Adak)');
Copy link
Member Author

Choose a reason for hiding this comment

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

New tests for option ordering.

expect(selectOption).toBeInTheDocument();
userEvent.click(selectOption);
expect(onTimezoneChange).toHaveBeenCalledTimes(1);
expect(onTimezoneChange).toHaveBeenLastCalledWith('America/Cambridge_Bay');
Copy link
Member Author

Choose a reason for hiding this comment

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

Test the updated timezone value after selecting an option


return (
<Select
ariaLabel={t('Timezone selector')}
css={{ minWidth: MIN_SELECT_WIDTH }} // smallest size for current values
onChange={onTimezoneChange}
value={timezone || DEFAULT_TIMEZONE.value}
Copy link
Member Author

Choose a reason for hiding this comment

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

Make sure value is a valid timezone. timezone may be different than updatedTz.

[onTimezoneChange],
const validTimezone = useMemo(
() => matchTimezoneToOptions(timezone || moment.tz.guess()),
[timezone],
Copy link
Member Author

Choose a reason for hiding this comment

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

Changed from useRef to simply triggering a setState in useEffect.

@ktmud ktmud force-pushed the refactor-timezone-selector branch from a2095c8 to 4f7a93c Compare March 10, 2022 02:09
@codecov
Copy link

codecov bot commented Mar 10, 2022

Codecov Report

Merging #19090 (4f7a93c) into master (0e0bece) will decrease coverage by 0.00%.
The diff coverage is 90.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #19090      +/-   ##
==========================================
- Coverage   66.48%   66.48%   -0.01%     
==========================================
  Files        1644     1644              
  Lines       63492    63491       -1     
  Branches     6459     6457       -2     
==========================================
- Hits        42212    42211       -1     
  Misses      19610    19610              
  Partials     1670     1670              
Flag Coverage Δ
javascript 51.23% <90.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...frontend/src/components/TimezoneSelector/index.tsx 96.96% <90.00%> (-0.09%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0e0bece...4f7a93c. Read the comment docs.

@eschutho
Copy link
Member

/testenv up

@github-actions
Copy link
Contributor

@eschutho Ephemeral environment spinning up at http://35.86.91.68:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@eschutho
Copy link
Member

/testenv up FEATURE_ALERT_REPORTS=True

@github-actions
Copy link
Contributor

@eschutho Ephemeral environment spinning up at http://35.163.121.68:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

Copy link
Member

@eschutho eschutho left a comment

Choose a reason for hiding this comment

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

Tested and it all works.

@ktmud ktmud merged commit 3a78165 into apache:master Mar 11, 2022
@github-actions
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

villebro pushed a commit that referenced this pull request Apr 3, 2022
@john-bodley john-bodley deleted the refactor-timezone-selector branch June 8, 2022 05:34
@mistercrunch mistercrunch added 🍒 1.5.0 🍒 1.5.1 🍒 1.5.2 🍒 1.5.3 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.0.0 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels lts-v1 size/L 🍒 1.5.0 🍒 1.5.1 🍒 1.5.2 🍒 1.5.3 🚢 2.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants