docs: add message on click of hero in toh-4 (#34496)
First we used a messages array to display messages toh-4 but it dsplayed only one message added additional messages on click of a hero Fixes #28739 PR Close #34496
This commit is contained in:

committed by
Matias Niemelä

parent
e7cf37d99f
commit
61ad50d40a
@ -83,9 +83,13 @@ function selectHeroTests() {
|
||||
|
||||
it('shows selected hero details', async () => {
|
||||
let page = getPageElts();
|
||||
let message = getMessage();
|
||||
let hero = await Hero.fromDetail(page.heroDetail);
|
||||
expect(hero.id).toEqual(targetHero.id);
|
||||
expect(hero.name).toEqual(targetHero.name.toUpperCase());
|
||||
// Message text contain id number matches the hero.id number
|
||||
expect(message.getText()).toContain(hero.id);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@ -131,3 +135,9 @@ function getPageElts() {
|
||||
heroDetail: element(by.css('app-root > div, app-root > app-heroes > app-hero-detail > div'))
|
||||
};
|
||||
}
|
||||
|
||||
function getMessage() {
|
||||
let hero = element(by.cssContainingText('li span.badge', targetHero.id.toString()));
|
||||
hero.click();
|
||||
return element.all(by.css('app-root > app-messages > div > div')).get(1);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import { Component, OnInit } from '@angular/core';
|
||||
import { Hero } from '../hero';
|
||||
// #docregion hero-service-import
|
||||
import { HeroService } from '../hero.service';
|
||||
import { MessageService } from '../message.service';
|
||||
// #enddocregion hero-service-import
|
||||
|
||||
@Component({
|
||||
@ -21,7 +22,7 @@ export class HeroesComponent implements OnInit {
|
||||
// #enddocregion heroes
|
||||
|
||||
// #docregion ctor
|
||||
constructor(private heroService: HeroService) { }
|
||||
constructor(private heroService: HeroService, private messageService: MessageService) { }
|
||||
// #enddocregion ctor
|
||||
|
||||
// #docregion ng-on-init
|
||||
@ -32,6 +33,7 @@ export class HeroesComponent implements OnInit {
|
||||
|
||||
onSelect(hero: Hero): void {
|
||||
this.selectedHero = hero;
|
||||
this.messageService.add(`HeroService: Selected hero id=${hero.id}`);
|
||||
}
|
||||
|
||||
// #docregion getHeroes
|
||||
|
Reference in New Issue
Block a user