docs(animations): use our heroes

This commit is contained in:
Foxandxss 2016-06-16 18:55:17 +02:00
parent 30609c8f9c
commit 3b4b79aeeb
10 changed files with 68 additions and 28 deletions

View File

@ -29,7 +29,7 @@ describe('Animation Tests', () => {
}); });
it('animates between active and inactive', () => { it('animates between active and inactive', () => {
addHero(); addInactiveHero();
let li = host.element(by.css('li')); let li = host.element(by.css('li'));
@ -58,7 +58,7 @@ describe('Animation Tests', () => {
}); });
it('are not kept after animation', () => { it('are not kept after animation', () => {
addHero(); addInactiveHero();
let li = host.element(by.css('li')); let li = host.element(by.css('li'));
@ -79,7 +79,7 @@ describe('Animation Tests', () => {
}); });
it('animates between active and inactive', () => { it('animates between active and inactive', () => {
addHero(); addInactiveHero();
let li = host.element(by.css('li')); let li = host.element(by.css('li'));
@ -108,7 +108,7 @@ describe('Animation Tests', () => {
}); });
it('animates between active and inactive', () => { it('animates between active and inactive', () => {
addHero(); addInactiveHero();
let li = host.element(by.css('li')); let li = host.element(by.css('li'));
@ -137,7 +137,7 @@ describe('Animation Tests', () => {
}); });
it('adds and removes element', () => { it('adds and removes element', () => {
addHero(); addInactiveHero();
let li = host.element(by.css('li')); let li = host.element(by.css('li'));
expect(li.getCssValue('transform')).toMatch(NO_TRANSFORM_MATRIX_REGEX); expect(li.getCssValue('transform')).toMatch(NO_TRANSFORM_MATRIX_REGEX);
@ -157,7 +157,7 @@ describe('Animation Tests', () => {
}); });
it('adds and removes and animates between active and inactive', () => { it('adds and removes and animates between active and inactive', () => {
addHero(); addInactiveHero();
let li = host.element(by.css('li')); let li = host.element(by.css('li'));
@ -186,7 +186,7 @@ describe('Animation Tests', () => {
}); });
it('adds and removes element', () => { it('adds and removes element', () => {
addHero(); addInactiveHero();
let li = host.element(by.css('li')); let li = host.element(by.css('li'));
expect(li.getCssValue('height')).toBe('50px'); expect(li.getCssValue('height')).toBe('50px');
@ -206,7 +206,7 @@ describe('Animation Tests', () => {
}); });
it('adds and removes element', () => { it('adds and removes element', () => {
addHero(); addInactiveHero();
let li = host.element(by.css('li')); let li = host.element(by.css('li'));
expect(li.getCssValue('transform')).toMatch(NO_TRANSFORM_MATRIX_REGEX); expect(li.getCssValue('transform')).toMatch(NO_TRANSFORM_MATRIX_REGEX);
@ -227,7 +227,7 @@ describe('Animation Tests', () => {
}); });
it('adds and removes element', () => { it('adds and removes element', () => {
addHero(); addInactiveHero();
let li = host.element(by.css('li')); let li = host.element(by.css('li'));
expect(li.getCssValue('transform')).toMatch(NO_TRANSFORM_MATRIX_REGEX); expect(li.getCssValue('transform')).toMatch(NO_TRANSFORM_MATRIX_REGEX);
@ -248,7 +248,7 @@ describe('Animation Tests', () => {
}); });
it('adds and removes element', () => { it('adds and removes element', () => {
addHero(); addInactiveHero();
let li = host.element(by.css('li')); let li = host.element(by.css('li'));
expect(li.getCssValue('transform')).toMatch(NO_TRANSFORM_MATRIX_REGEX); expect(li.getCssValue('transform')).toMatch(NO_TRANSFORM_MATRIX_REGEX);
@ -260,8 +260,41 @@ describe('Animation Tests', () => {
}); });
function addHero() { describe('adding active heroes', () => {
element(by.buttonText('Add hero')).click();
let host: protractor.ElementFinder;
beforeEach(() => {
host = element(by.css('hero-list-basic'));
});
it('animates between active and inactive', () => {
addActiveHero();
let li = host.element(by.css('li'));
expect(getScaleX(li)).toBe(1.1);
expect(li.getCssValue('backgroundColor')).toBe(ACTIVE_COLOR);
li.click();
browser.driver.sleep(300);
expect(getScaleX(li)).toBe(1.0);
expect(li.getCssValue('backgroundColor')).toBe(INACTIVE_COLOR);
li.click();
browser.driver.sleep(300);
expect(getScaleX(li)).toBe(1.1);
expect(li.getCssValue('backgroundColor')).toBe(ACTIVE_COLOR);
});
});
function addActiveHero() {
element(by.buttonText('Add active hero')).click();
browser.driver.sleep(500);
}
function addInactiveHero() {
element(by.buttonText('Add inactive hero')).click();
browser.driver.sleep(500); browser.driver.sleep(500);
} }

View File

@ -16,7 +16,8 @@ import { HeroListTimingsComponent } from './hero-list-timings.component';
selector: 'hero-team-builder', selector: 'hero-team-builder',
template: ` template: `
<div class="buttons"> <div class="buttons">
<button [disabled]="!heroes.canAdd()" (click)="heroes.add()">Add hero</button> <button [disabled]="!heroes.canAdd()" (click)="heroes.addInactive()">Add inactive hero</button>
<button [disabled]="!heroes.canAdd()" (click)="heroes.addActive()">Add active hero</button>
<button [disabled]="!heroes.canRemove()" (click)="heroes.remove()">Remove hero</button> <button [disabled]="!heroes.canRemove()" (click)="heroes.remove()">Remove hero</button>
</div> </div>
<div class="columns"> <div class="columns">

View File

@ -11,19 +11,17 @@ class Hero {
} }
let ALL_HEROES = [ let ALL_HEROES = [
'Wolverine', 'Windstorm',
'Magneto', 'RubberMan',
'Emma Frost', 'Bombasto',
'Thing', 'Magneta',
'Kitty Pryde', 'Dynama',
'Nightcrawler', 'Narco',
'Juggernaut', 'Celeritas',
'Beast', 'Dr IQ',
'Captain America', 'Magma',
'Spider-Man', 'Tornado',
'Puck', 'Mr. Nice'
'Alex Wilder',
'Doctor Strange'
].map(name => new Hero(name)); ].map(name => new Hero(name));
@Injectable() @Injectable()
@ -43,8 +41,16 @@ export class Heroes implements Iterable<Hero> {
return this.currentHeroes.length > 0; return this.currentHeroes.length > 0;
} }
add() { addActive() {
this.currentHeroes.push(ALL_HEROES[this.currentHeroes.length]); let hero = ALL_HEROES[this.currentHeroes.length];
hero.state = 'active';
this.currentHeroes.push(hero);
}
addInactive() {
let hero = ALL_HEROES[this.currentHeroes.length];
hero.state = 'inactive';
this.currentHeroes.push(hero);
} }
remove() { remove() {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 224 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 221 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 805 KiB

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 KiB

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 304 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 225 KiB

After

Width:  |  Height:  |  Size: 79 KiB