refactor: Adapt foundations for class-object adapters
…ass-object adapters for material-experimental components
This is to resolve test failures (and anticipated breaking changes) with the move to class-based adapters.
Changes:
- adapter is now copied as a field (to resolve undefined adapters failing tests)
- adapters are not optional and are expected to implement the full interface, because they are now class objects
...For the following components:
- mdc-checkbox
- mdc-chips/chip-set
- mdc-chips/chip
- mdc-chips/trailingaction
- mdc-form-field
- mdc-radio
- mdc-slider
- mdc-switch
- mdc-tab-bar
- mdc-tab-indicator
Additionally,
- mdc-circular-progress
- mdc-data-table
- mdc-dialog
- mdc-drawer/dismissible
- mdc-floating-label
- mdc-icon-button
- mdc-line-ripple
- mdc-linear-progress
- mdc-list
- mdc-menu-surface
- mdc-menu
- mdc-notched-outline
- mdc-ripple
- mdc-segmented-button/segment
- mdc-segmented-button/segmented-button
- mdc-select
- mdc-select/helper-text
- mdc-select/icon
- mdc-snackbar
Now the base foundation constructor in the following format:
constructor(readonly adapter: MDCAdapter) {...}
The constructor for individual components have been removed, as a call to super() is sufficient to most. For the components that have initialize additional values in the constructor, the new overridden constructor is in the format:
constructor(adapter: MDCAdapter) {
super(adapter);
...
}
Importing this PR internally.
@abhiomkar In case you haven't seen my message, it's ready!
Re-running global tests.
Commenting to Rebase internal CL.
Unit tests are failing internally for most of the MDC foundation code with following error:
"MDCCheckboxFoundation defaultAdapter returns a complete adapter implementation"
Unexpected $[0] = 'addClass' in array.
Unexpected $[1] = 'forceLayout' in array.
Unexpected $[2] = 'hasNativeControl' in array.
Unexpected $[3] = 'isAttachedToDOM' in array.
Unexpected $[4] = 'isChecked' in array.
Unexpected $[5] = 'isIndeterminate' in array.
Unexpected $[6] = 'removeClass' in array.
Unexpected $[7] = 'removeNativeControlAttr' in array.
Unexpected $[8] = 'setNativeControlAttr' in array.
Unexpected $[9] = 'setNativeControlDisabled' in array.
Error: Expected $.length = 10 to equal 0.
Unexpected $[0] = 'addClass' in array.
Unexpected $[1] = 'forceLayout' in array.
Unexpected $[2] = 'hasNativeControl' in array.
Unexpected $[3] = 'isAttachedToDOM' in array.
Unexpected $[4] = 'isChecked' in array.
Unexpected $[5] = 'isIndeterminate' in array.
Unexpected $[6] = 'removeClass' in array.
Unexpected $[7] = 'removeNativeControlAttr' in array.
Unexpected $[8] = 'setNativeControlAttr' in array.
Unexpected $[9] = 'setNativeControlDisabled' in array.
at Object.verifyDefaultAdapter
You'll need to remove defaultAdapter test case from all foundation unit tests of MDC.
Weird that unit tests are passing externally.
Please let me know when this CL is ready for re-review. Thanks!
@abhiomkar Should be ready! Sorry for the delay, experiencing a power outage this week
Thanks Scott! No problem..
Can you resolve merge conflicts and rebase with base branch?
Hi Scott! Seems like segmented button unit tests are failing. Can you please take a look?
Thanks!
@abhiomkar I've made fixes for that, but it looks like the unit tests are failing with a bunch of errors. My guess is that it's on the components side. Could you re-run the tests on your end?
Verified unit tests locally. I see many unit tests are failing with following errors:
Chrome 84.0.4147 (Mac OS X 10.15.6) MDCSwitchFoundation #handleChange removes mdc-switch--checked from the switch when it is an unchecked state FAILED
createSpyObj requires a non-empty array or object of method names to create spies for thrown
Unit tests do not run on forked repositories you'll have to manually run npm run test:unit to verify.
@abhiomkar Here's an update: the tests pass for me locally, but fail on github. I'm certain that my local repo and GitHub are running the same code.
One thing that is suspect was a single failure with announce.test.ts that I somehow suppressed by changing around the order of static fields, although it's not mentioned on GitHub.
@abhiomkar should be ready!
If this is merged, we should reopen the work in https://github.com/angular/components/pull/19982