material-components-web icon indicating copy to clipboard operation
material-components-web copied to clipboard

refactor: Adapt foundations for class-object adapters

Open ngwattcos opened this issue 5 years ago • 14 comments

…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);
  ...
}

ngwattcos avatar Jul 23 '20 19:07 ngwattcos

Importing this PR internally.

abhiomkar avatar Jul 23 '20 20:07 abhiomkar

@abhiomkar In case you haven't seen my message, it's ready!

ngwattcos avatar Jul 28 '20 16:07 ngwattcos

Re-running global tests.

abhiomkar avatar Jul 29 '20 14:07 abhiomkar

Commenting to Rebase internal CL.

abhiomkar avatar Jul 29 '20 18:07 abhiomkar

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.

abhiomkar avatar Jul 30 '20 14:07 abhiomkar

Please let me know when this CL is ready for re-review. Thanks!

abhiomkar avatar Aug 03 '20 18:08 abhiomkar

@abhiomkar Should be ready! Sorry for the delay, experiencing a power outage this week

ngwattcos avatar Aug 06 '20 22:08 ngwattcos

Thanks Scott! No problem..

Can you resolve merge conflicts and rebase with base branch?

abhiomkar avatar Aug 06 '20 23:08 abhiomkar

Hi Scott! Seems like segmented button unit tests are failing. Can you please take a look?

Thanks!

abhiomkar avatar Aug 10 '20 17:08 abhiomkar

@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?

ngwattcos avatar Aug 11 '20 20:08 ngwattcos

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 avatar Aug 11 '20 21:08 abhiomkar

@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.

ngwattcos avatar Aug 20 '20 17:08 ngwattcos

@abhiomkar should be ready!

ngwattcos avatar Aug 20 '20 21:08 ngwattcos

If this is merged, we should reopen the work in https://github.com/angular/components/pull/19982

andrewseguin avatar Mar 29 '22 20:03 andrewseguin