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: Adapt foundations for class-object adapters #6256

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

ngwattcos
Copy link

@ngwattcos ngwattcos commented Jul 23, 2020

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

…ass-object 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

Now the edited foundation constructors are in the following format:
```
constructor(readonly adapter: MDCAdapter) {...}
```
@abhiomkar
Copy link
Collaborator

Importing this PR internally.

@abhiomkar abhiomkar changed the title refactor(material-experimental-foundations): Adapt foundations for cl… refactor: Adapt foundations for class-object adapters Jul 23, 2020
…ter reference, removed defaultAdapter()

The base class foundation now more strongly types the adapter (in anticipation of the other components moving to class-based adapters) and stores the adapter reference.

Removed defaultAdapter() in the following (since we have class object adapters):
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
…ject adapters

Deletes overridden constructors since the base foundation now expects a fully implemented adapter (except for constructors that initialize other values).

Deletes all defaultAdapter() methods.
Copy link
Collaborator

@abhiomkar abhiomkar left a comment

Choose a reason for hiding this comment

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

Let me know when this PR is ready for re-review.

Thanks!

packages/mdc-floating-label/foundation.ts Outdated Show resolved Hide resolved
packages/mdc-form-field/foundation.ts Outdated Show resolved Hide resolved
packages/mdc-line-ripple/foundation.ts Outdated Show resolved Hide resolved
packages/mdc-ripple/foundation.ts Outdated Show resolved Hide resolved
packages/mdc-select/foundation.ts Outdated Show resolved Hide resolved
packages/mdc-select/icon/foundation.ts Outdated Show resolved Hide resolved
@ngwattcos
Copy link
Author

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

@abhiomkar
Copy link
Collaborator

Re-running global tests.

@abhiomkar
Copy link
Collaborator

Commenting to Rebase internal CL.

@abhiomkar
Copy link
Collaborator

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
Copy link
Collaborator

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

@ngwattcos ngwattcos force-pushed the foundation-use-class-adapter branch from eb642bd to c0ad50f Compare August 6, 2020 20:36
@ngwattcos
Copy link
Author

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

@abhiomkar
Copy link
Collaborator

Thanks Scott! No problem..

Can you resolve merge conflicts and rebase with base branch?

@ngwattcos ngwattcos force-pushed the foundation-use-class-adapter branch 2 times, most recently from 553b8dc to a91c289 Compare August 7, 2020 21:41
Copy link
Collaborator

@abhiomkar abhiomkar left a comment

Choose a reason for hiding this comment

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

Seems like test file updates are reverted?

@ngwattcos ngwattcos force-pushed the foundation-use-class-adapter branch from a91c289 to 89ce243 Compare August 8, 2020 20:18
@abhiomkar
Copy link
Collaborator

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

Thanks!

@ngwattcos
Copy link
Author

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

@abhiomkar
Copy link
Collaborator

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.

@ngwattcos
Copy link
Author

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

packages/mdc-checkbox/foundation.ts Show resolved Hide resolved
packages/mdc-chips/chip-set/test/foundation.test.ts Outdated Show resolved Hide resolved
packages/mdc-chips/chip/foundation.ts Outdated Show resolved Hide resolved
import {setUpFoundationTest} from '../../../testing/helpers/setup';
import {attributes, cssClasses, SortValue, strings} from '../constants';
import {MDCDataTableFoundation} from '../foundation';

describe('MDCDataTableFoundation', () => {
it('default adapter returns a complete adapter implementation', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is removing tests in scope of this PR? Can we remove this tests when we delete default adapters?

This may affect code coverage numbers otherwise.

Copy link
Author

Choose a reason for hiding this comment

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

@abhiomkar Initially, we removed these tests because we assumed defaultAdapter would no longer be used (since now adapters need to implement the full interface).

But another test mocks an adapter using the defaultAdapter, so just to get the tests to pass, @kseamon suggested putting back the defaultAdapter for now (we can delete them in a later PR)

Copy link
Collaborator

Choose a reason for hiding this comment

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

@kseamon Can you please confirm if this is what you intended. http://b/165316767 suggests that unit tests will be cleaned up along with defaultAdapter code.

Copy link

Choose a reason for hiding this comment

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

Sorry - missed this way back when - yes, we need to keep the default adaptors around until the tests are refactored.

The most straightforward thing might be to factor them out into objects that live in the test files.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Got it! Moving objects to live in tests SGTM so that the code coverage numbers will be intact.

Since ngwattcos@ left Google, do you want to take a stab at it? You can directly send a CL to us (Copybara will automatically merge the PR).

Let me know if you've any questions!

@ngwattcos
Copy link
Author

@abhiomkar should be ready!

@andrewseguin
Copy link
Contributor

If this is merged, we should reopen the work in angular/components#19982

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants