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

feat(stepper): Add unit tests for stepper #6428

Merged
merged 3 commits into from
Aug 15, 2017
Merged

Conversation

g1shin
Copy link

@g1shin g1shin commented Aug 12, 2017

No description provided.

@g1shin g1shin requested review from jelbourn, kara and mmalerba August 12, 2017 01:29
@g1shin g1shin requested a review from devversion as a code owner August 12, 2017 01:29
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Aug 12, 2017
@g1shin g1shin removed the request for review from devversion August 12, 2017 01:30
@shlomiassaf
Copy link
Contributor

shlomiassaf commented Aug 14, 2017

@g1shin @jelbourn Been playing with the stepper branch.

Any particular reason for the label's index not being part of the whole custom label?

Instead of:

<div class="mat-stepper-index">{{i + 1}}</div>
<div class="mat-stepper-label">
  <!-- If there is a label template, use it. -->
  <ng-container *ngIf="step.stepLabel" [ngTemplateOutlet]="step.stepLabel.template"></ng-container>
  <!-- It there is no label template, fall back to the text label. -->
  <div *ngIf="!step.stepLabel">{{step.label}}</div>
</div>

do it like:

<div class="mat-stepper-label">
  <ng-container *ngIf="step.stepLabel" [ngTemplateOutlet]="step.stepLabel.template"></ng-container>
  <!-- It there is no label template, fall back to the text label. -->
  <div *ngIf="!step.stepLabel">
    <div class="mat-stepper-index">
      {{i + 1}}
    </div>
    {{step.label}}
  </div>
</div>

This way if a user opts-in for a custom label he will decide if to include the index or not.

Forcing the index does not allow real customization of the index, for example if I want to do roman numerals or A. B. C

Since the user will do *ngFor anyway, he will have the index...

@shlomiassaf
Copy link
Contributor

shlomiassaf commented Aug 14, 2017

Another thing that pops out is not using ViewEncapsulation.None in the component.

This does not align with other components...

EDIT: Also not using changeDetection: ChangeDetectionStrategy.OnPush

I comment here since opening an issue on something that does not exist on master branch might be confusing.

@mmalerba
Copy link
Contributor

@g1shin needs rebase

@g1shin
Copy link
Author

g1shin commented Aug 14, 2017

Rebase done; ready for review 👍

import {dispatchKeyboardEvent} from '@angular/cdk/testing';
import {ENTER, LEFT_ARROW, RIGHT_ARROW, SPACE} from '@angular/cdk/keycodes';

fdescribe('MdHorizontalStepper', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you left an fdescribe by mistake. Remove?

fdescribe('MdHorizontalStepper', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [MdStepperModule, NoopAnimationsModule, FormsModule, ReactiveFormsModule],
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need FormsModule? It looks like you aren't using any template-driven directives. Same on line 114.

});

it('should change selected index on header click', () => {
let stepHeader = fixture.debugElement.queryAll(By.css('.mat-horizontal-stepper-header'));
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Maybe name this stepHeaders (plural)? To make clear that this grabs headers from all steps. Same on line 142.

fixture.detectChanges();

expect(stepContentEl.getAttribute('aria-expanded')).toBe('false');
stepContentEl = stepContent[1].nativeElement;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: It's a bit hard to follow when you're naming two different step elements with the same name. Maybe create a new let for this - secondStepEl?

expect(stepperEl.getAttribute('role')).toBe('tablist');
});

it('should expand the right content', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: In this case, you mean set aria-expanded correctly, right? I'd mention that in the test name. Same on line 152.


it('should not move to next step if current step is not valid', () => {
expect(testComponent.oneGroup.get('oneCtrl')!.value).toBe('');
expect(testComponent.oneGroup.valid).toBe(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Here I'd expect a test that the control itself is invalid (if you were to add another control, it could cause the parent form to be false for a different reason). Same on 199.

});
});

fdescribe('MdVerticalStepper', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

fdescribe

dispatchKeyboardEvent(stepHeaderEl, 'keydown', RIGHT_ARROW);
fixture.detectChanges();

expect(stepperComponent._focusIndex).toBe(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think fallback messages for these would be helpful to guide us through your thinking.

<md-step [stepControl]="oneGroup">
<form [formGroup]="oneGroup">
<ng-template mdStepLabel>Step one</ng-template>
<md-input-container>
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to use md-form-field on these to be forward-friendly? cc @mmalerba

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 if you're synced up to where md-form-field exists

@kara kara removed their assignment Aug 14, 2017
@g1shin
Copy link
Author

g1shin commented Aug 15, 2017

Changes have been made based on review. Ready for review again 😃

Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

LGTM

@kara
Copy link
Contributor

kara commented Aug 15, 2017

@mmalerba Do you want to take a look before I apply merge labels?

describe('basic horizontal stepper', () => {
let fixture: ComponentFixture<SimpleMdHorizontalStepperApp>;
let stepperComponent: MdHorizontalStepper;
let stepperEl: HTMLElement;
Copy link
Contributor

Choose a reason for hiding this comment

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

since only 1 test uses this you can just declare it in that test

});

function checkSelectionChangeOnHeaderClick(stepperComponent:
MdHorizontalStepper | MdVerticalStepper,
Copy link
Contributor

Choose a reason for hiding this comment

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

just use common base class MdStepper? (here and other functions that take a stepper)

<md-step [stepControl]="oneGroup">
<form [formGroup]="oneGroup">
<ng-template mdStepLabel>Step one</ng-template>
<md-input-container>
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 if you're synced up to where md-form-field exists

@g1shin
Copy link
Author

g1shin commented Aug 15, 2017

Ready for review again

it('should change selected index on header click', () => {
let stepHeaders = fixture.debugElement.queryAll(By.css('.mat-horizontal-stepper-header'));
checkSelectionChangeOnHeaderClick(stepperComponent, fixture, stepHeaders);

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove extra line

@g1shin g1shin merged commit 39a3649 into angular:stepper Aug 15, 2017
g1shin pushed a commit that referenced this pull request Aug 16, 2017
* Add unit tests for stepper

* Changes made based on review

* More changes based on review
g1shin pushed a commit to g1shin/material2 that referenced this pull request Aug 22, 2017
* Add unit tests for stepper

* Changes made based on review

* More changes based on review
g1shin pushed a commit to g1shin/material2 that referenced this pull request Aug 22, 2017
* Add unit tests for stepper

* Changes made based on review

* More changes based on review
g1shin pushed a commit to g1shin/material2 that referenced this pull request Aug 22, 2017
* Add unit tests for stepper

* Changes made based on review

* More changes based on review
g1shin pushed a commit that referenced this pull request Aug 23, 2017
* Add unit tests for stepper

* Changes made based on review

* More changes based on review
mmalerba pushed a commit that referenced this pull request Aug 23, 2017
…tepper branch. (#5742)

* Prototyping

* Further work

* Further prototyping

* Further prototyping

* Further work

* Adding event emitters

* Adding "selectedIndex" attribute to stepper and working on TemplateOulet.

* Prototyping

* Further work

* Further prototyping

* Further prototyping

* Further work

* Adding event emitters

* Template rendering and selectIndex control done.

* Work in progress for accessibility

* Added functionalities based on the tentative API doc.

* Refactor code for cdk-stepper and cdk-step

* Add support for templated label

* Added support for keyboard events and focus changes for accessibility.

* Updated vertical stepper + added comments

* Fix package-lock.json

* Fix indention

* Changes made based on the review

* Changes based on review - event properties, selectors, SPACE support, etc. + demo

* Add select() for step component + refactor to avoid circular dependency + support cycling using arrow keys

* API change based on review

* Minor code clean up based on review.

* Several name changes, etc based on review

* Add to compatibility mode list and refactor to avoid circular dependency

feat(stepper): Create stepper button directives to enable adding buttons to stepper (#5951)

* Create stepper button directives to enable adding buttons to stepper

* Changes made based on review

* Minor changes with click handlers

Build changes

feat(stepper): Add initial styles to stepper based on Material guidelines (#6242)

* Add initial styles to stepper based on Material guidelines

* Fix flex-shrink and min-width

* Changes made based on review

* Fix alignment

* Margin modifications

feat(stepper): Add support for linear stepper (#6116)

* Add form controls and custom error state matcher

* Modify form controls for stepper-demo and add custom validator

* Move custom step validation function so that users can simply import and use

* Implement @input() stepControl for each step

* Add linear attribute to stepper

* Add enabling/disabling linear state of demo

feat(stepper): Add animation to stepper (#6361)

* Add animation

* Implement Angular animation

* Clean up unnecessary code

* Generalize animation so that vertical and horizontal steppers can use the same function

Rebase onto upstream/master

feat(stepper): Add unit tests for stepper (#6428)

* Add unit tests for stepper

* Changes made based on review

* More changes based on review

feat(stepper): Add support for linear stepper #2 - each step as its own form. (#6117)

* Add form control - consider each step as its own form group

* Comment edits

* Add 'valid' to MdStep for form validation

* Add [stepControl] to each step based on merging

* Changes based on review

Fix focus logic and CSS changes (#6507)

feat(stepper): Add documentation for stepper (#6533)

* Documentation for stepper

* Revision based on review + add accessibility section

feat(stepper): Support additional properties for step (#6509)

* Additional properties for step

* Unit tests

* Code changes based on review + test name changes

* Refactor code for shared functionality between vertical and horizontal stepper

* Refactor md-step-header and md-step-content + optional step change

* Simplify code based on review

* Changes to step-header based on review

* Minor changes

Fix host style and demo page (#6592)

Revert package.json and package-lock.json

Changes made along with BUILD changes in google3

Add typography mixin

Changes to address aot compiler failures

fix rtl bugs
g1shin pushed a commit to g1shin/material2 that referenced this pull request Aug 31, 2017
…tepper branch. (angular#5742)

* Prototyping

* Further work

* Further prototyping

* Further prototyping

* Further work

* Adding event emitters

* Adding "selectedIndex" attribute to stepper and working on TemplateOulet.

* Prototyping

* Further work

* Further prototyping

* Further prototyping

* Further work

* Adding event emitters

* Template rendering and selectIndex control done.

* Work in progress for accessibility

* Added functionalities based on the tentative API doc.

* Refactor code for cdk-stepper and cdk-step

* Add support for templated label

* Added support for keyboard events and focus changes for accessibility.

* Updated vertical stepper + added comments

* Fix package-lock.json

* Fix indention

* Changes made based on the review

* Changes based on review - event properties, selectors, SPACE support, etc. + demo

* Add select() for step component + refactor to avoid circular dependency + support cycling using arrow keys

* API change based on review

* Minor code clean up based on review.

* Several name changes, etc based on review

* Add to compatibility mode list and refactor to avoid circular dependency

feat(stepper): Create stepper button directives to enable adding buttons to stepper (angular#5951)

* Create stepper button directives to enable adding buttons to stepper

* Changes made based on review

* Minor changes with click handlers

Build changes

feat(stepper): Add initial styles to stepper based on Material guidelines (angular#6242)

* Add initial styles to stepper based on Material guidelines

* Fix flex-shrink and min-width

* Changes made based on review

* Fix alignment

* Margin modifications

feat(stepper): Add support for linear stepper (angular#6116)

* Add form controls and custom error state matcher

* Modify form controls for stepper-demo and add custom validator

* Move custom step validation function so that users can simply import and use

* Implement @input() stepControl for each step

* Add linear attribute to stepper

* Add enabling/disabling linear state of demo

feat(stepper): Add animation to stepper (angular#6361)

* Add animation

* Implement Angular animation

* Clean up unnecessary code

* Generalize animation so that vertical and horizontal steppers can use the same function

Rebase onto upstream/master

feat(stepper): Add unit tests for stepper (angular#6428)

* Add unit tests for stepper

* Changes made based on review

* More changes based on review

feat(stepper): Add support for linear stepper angular#2 - each step as its own form. (angular#6117)

* Add form control - consider each step as its own form group

* Comment edits

* Add 'valid' to MdStep for form validation

* Add [stepControl] to each step based on merging

* Changes based on review

Fix focus logic and CSS changes (angular#6507)

feat(stepper): Add documentation for stepper (angular#6533)

* Documentation for stepper

* Revision based on review + add accessibility section

feat(stepper): Support additional properties for step (angular#6509)

* Additional properties for step

* Unit tests

* Code changes based on review + test name changes

* Refactor code for shared functionality between vertical and horizontal stepper

* Refactor md-step-header and md-step-content + optional step change

* Simplify code based on review

* Changes to step-header based on review

* Minor changes

Fix host style and demo page (angular#6592)

Revert package.json and package-lock.json

Changes made along with BUILD changes in google3

Add typography mixin

Changes to address aot compiler failures

fix rtl bugs
g1shin pushed a commit to g1shin/material2 that referenced this pull request Aug 31, 2017
…tepper branch. (angular#5742)

* Prototyping

* Further work

* Further prototyping

* Further prototyping

* Further work

* Adding event emitters

* Adding "selectedIndex" attribute to stepper and working on TemplateOulet.

* Prototyping

* Further work

* Further prototyping

* Further prototyping

* Further work

* Adding event emitters

* Template rendering and selectIndex control done.

* Work in progress for accessibility

* Added functionalities based on the tentative API doc.

* Refactor code for cdk-stepper and cdk-step

* Add support for templated label

* Added support for keyboard events and focus changes for accessibility.

* Updated vertical stepper + added comments

* Fix package-lock.json

* Fix indention

* Changes made based on the review

* Changes based on review - event properties, selectors, SPACE support, etc. + demo

* Add select() for step component + refactor to avoid circular dependency + support cycling using arrow keys

* API change based on review

* Minor code clean up based on review.

* Several name changes, etc based on review

* Add to compatibility mode list and refactor to avoid circular dependency

feat(stepper): Create stepper button directives to enable adding buttons to stepper (angular#5951)

* Create stepper button directives to enable adding buttons to stepper

* Changes made based on review

* Minor changes with click handlers

Build changes

feat(stepper): Add initial styles to stepper based on Material guidelines (angular#6242)

* Add initial styles to stepper based on Material guidelines

* Fix flex-shrink and min-width

* Changes made based on review

* Fix alignment

* Margin modifications

feat(stepper): Add support for linear stepper (angular#6116)

* Add form controls and custom error state matcher

* Modify form controls for stepper-demo and add custom validator

* Move custom step validation function so that users can simply import and use

* Implement @input() stepControl for each step

* Add linear attribute to stepper

* Add enabling/disabling linear state of demo

feat(stepper): Add animation to stepper (angular#6361)

* Add animation

* Implement Angular animation

* Clean up unnecessary code

* Generalize animation so that vertical and horizontal steppers can use the same function

Rebase onto upstream/master

feat(stepper): Add unit tests for stepper (angular#6428)

* Add unit tests for stepper

* Changes made based on review

* More changes based on review

feat(stepper): Add support for linear stepper angular#2 - each step as its own form. (angular#6117)

* Add form control - consider each step as its own form group

* Comment edits

* Add 'valid' to MdStep for form validation

* Add [stepControl] to each step based on merging

* Changes based on review

Fix focus logic and CSS changes (angular#6507)

feat(stepper): Add documentation for stepper (angular#6533)

* Documentation for stepper

* Revision based on review + add accessibility section

feat(stepper): Support additional properties for step (angular#6509)

* Additional properties for step

* Unit tests

* Code changes based on review + test name changes

* Refactor code for shared functionality between vertical and horizontal stepper

* Refactor md-step-header and md-step-content + optional step change

* Simplify code based on review

* Changes to step-header based on review

* Minor changes

Fix host style and demo page (angular#6592)

Revert package.json and package-lock.json

Changes made along with BUILD changes in google3

Add typography mixin

Changes to address aot compiler failures

fix rtl bugs
@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 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants