Skip to content

feat(datepicker/testing): add test harnesses for the datepicker module #20219

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

Merged
merged 1 commit into from
Aug 13, 2020

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Aug 6, 2020

  • Sets up test harnesses for the components in the datepicker module. Includes datepicker input, datepicker toggle, calendar, calendar cell, date range input, date range input start/end sub-inputs.
  • Fixes an issue in mat-calendar that showed up while adding unit tests for the harnesses. The standalone calendar wasn't picking up changes to the comparison range after init.
  • Expands the dialog backdropClass signature to allow string[]. This was necessary for the harness so that we can tie a harness to a particular backdrop.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Aug 6, 2020
import {MatCalendarHarness} from './calendar-harness';

/** Interface for a test harness that can open and close a calendar. */
export interface DatepickerTrigger {
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not super happy with how this one turned out, but this is the best way I found to implement it. The problem is that these harnesses all have 2 base classes: an input and a datepicker trigger. The input is extended by MatDatepickerInput, MatStartDate and MatEndDate, whereas the trigger needs to be extended by MatDatepickerInput, MatDateRangeInput and MatDatepickerToggle. Initially I had the input base class extend the trigger, but the trigger behavior doesn't make sense on MatStartDate and MatEndDate. I tried to use a mixin so that MatDatepickerInput can extend both base classes, but TS kept complaining about the mixin class having the protected methods coming from ComponentHarness.

I ended up with this which has an interface that enforces that MatDatepickerInput and the classes extending the trigger base class are all consistent while having the trickier shared logic in functions.

Copy link
Member

Choose a reason for hiding this comment

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

I think that's totally reasonable

@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: minor This PR is targeted for the next minor release labels Aug 6, 2020
@crisbeto crisbeto marked this pull request as ready for review August 6, 2020 15:55
@crisbeto crisbeto requested review from jelbourn, mmalerba and a team as code owners August 6, 2020 15:55
import {MatCalendarHarness} from './calendar-harness';

/** Interface for a test harness that can open and close a calendar. */
export interface DatepickerTrigger {
Copy link
Member

Choose a reason for hiding this comment

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

I think that's totally reasonable

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@mmalerba should also take a look

Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

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

LGTM

* Sets up test harnesses for the components in the datepicker module. Includes datepicker input, datepicker toggle, calendar, calendar cell, date range input, date range input start/end sub-inputs.
* Fixes an issue in `mat-calendar` that showed up while adding unit tests for the harnesses. The standalone calendar wasn't picking up changes to the comparison range after init.
* Expands the dialog `backdropClass` signature to allow `string[]`. This was necessary for the harness so that we can tie a harness to a particular backdrop.
@crisbeto crisbeto force-pushed the datepicker-harness branch from ea98d03 to 70872b9 Compare August 11, 2020 12:08
@mmalerba mmalerba added action: merge The PR is ready for merge by the caretaker P2 The issue is important to a large percentage of users, with a workaround and removed P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Aug 11, 2020
@andrewseguin andrewseguin merged commit 90d6b70 into angular:master Aug 13, 2020
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P2 The issue is important to a large percentage of users, with a workaround target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants