test(docs-infra): fix the dependency-injection-in-action
e2e tests (#39818)
Previously, the tests made no meaningful assertions. It seems that the intention was to ensure that some elements were present on the page, but all the assertions did was verify that the corresponding `ElementFinder`s were defined. The `ElementFinder`s would always be defined, even if there were no corresponding elements on the page. In fact, some of the `ElementFinder` selectors were incorrect, so they did not match any actual elements. This commit fixes the tests by fixing the `ElementFinder` selectors and asserting that the elements are actually present on the page. PR Close #39818
This commit is contained in:
parent
c7605ccf05
commit
4dba9fa530
@ -6,54 +6,47 @@ describe('Dependency Injection Cookbook', () => {
|
|||||||
browser.get('');
|
browser.get('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render Logged in User example', () => {
|
it('should render Logged in User example', async () => {
|
||||||
const loggedInUser = element.all(by.xpath('//h3[text()="Logged in user"]')).get(0);
|
const loggedInUser = element(by.cssContainingText('h3', 'Logged in user'));
|
||||||
expect(loggedInUser).toBeDefined();
|
expect(await loggedInUser.isPresent()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('"Bombasto" should be the logged in user', () => {
|
it('"Bombasto" should be the logged in user', async () => {
|
||||||
const loggedInUser = element.all(by.xpath('//div[text()="Name: Bombasto"]')).get(0);
|
const loggedInUser = element(by.cssContainingText('div', 'Name: Bombasto'));
|
||||||
expect(loggedInUser).toBeDefined();
|
expect(await loggedInUser.isPresent()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render sorted heroes', () => {
|
it('should render sorted heroes', async () => {
|
||||||
const sortedHeroes = element.all(by.xpath('//h3[text()="Sorted Heroes" and position()=1]')).get(0);
|
const sortedHeroes = element(by.cssContainingText('h3', 'Sorted Heroes'));
|
||||||
expect(sortedHeroes).toBeDefined();
|
expect(await sortedHeroes.isPresent()).toBe(true);
|
||||||
|
|
||||||
|
const sortedHeroElems = element.all(by.css('app-sorted-heroes div'));
|
||||||
|
const sortedHeroNames = await sortedHeroElems.map(elem => elem.getText());
|
||||||
|
expect(sortedHeroNames).toEqual(['Dr Nice', 'Magma', 'RubberMan']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Dr Nice should be in sorted heroes', () => {
|
it('should render Hero of the Month', async () => {
|
||||||
const sortedHero = element.all(by.xpath('//sorted-heroes/[text()="Dr Nice" and position()=2]')).get(0);
|
const heroOfTheMonth = element(by.cssContainingText('h3', 'Hero of the Month'));
|
||||||
expect(sortedHero).toBeDefined();
|
expect(await heroOfTheMonth.isPresent()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('RubberMan should be in sorted heroes', () => {
|
it('should render Hero Bios', async () => {
|
||||||
const sortedHero = element.all(by.xpath('//sorted-heroes/[text()="RubberMan" and position()=3]')).get(0);
|
const heroBios = element(by.cssContainingText('h3', 'Hero Bios'));
|
||||||
expect(sortedHero).toBeDefined();
|
expect(await heroBios.isPresent()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Magma should be in sorted heroes', () => {
|
it('should render Magma\'s description in Hero Bios', async () => {
|
||||||
const sortedHero = element.all(by.xpath('//sorted-heroes/[text()="Magma"]')).get(0);
|
const magmaBioElem = element.all(by.css('app-hero-bio')).get(1);
|
||||||
expect(sortedHero).toBeDefined();
|
const magmaNameElem = magmaBioElem.element(by.css('h4'));
|
||||||
|
const magmaDescElem = magmaBioElem.element(by.css('textarea'));
|
||||||
|
|
||||||
|
expect(await magmaNameElem.getText()).toBe('Magma');
|
||||||
|
expect(await magmaDescElem.getAttribute('value')).toBe('Hero of all trades');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render Hero of the Month', () => {
|
it('should render Magma\'s phone in Hero Bios and Contacts', async () => {
|
||||||
const heroOfTheMonth = element.all(by.xpath('//h3[text()="Hero of the month"]')).get(0);
|
const magmaPhone = element(by.cssContainingText('div', 'Phone #: 555-555-5555'));
|
||||||
expect(heroOfTheMonth).toBeDefined();
|
expect(await magmaPhone.isPresent()).toBe(true);
|
||||||
});
|
|
||||||
|
|
||||||
it('should render Hero Bios', () => {
|
|
||||||
const heroBios = element.all(by.xpath('//h3[text()="Hero Bios"]')).get(0);
|
|
||||||
expect(heroBios).toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should render Magma\'s description in Hero Bios', () => {
|
|
||||||
const magmaText = element.all(by.xpath('//textarea[text()="Hero of all trades"]')).get(0);
|
|
||||||
expect(magmaText).toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should render Magma\'s phone in Hero Bios and Contacts', () => {
|
|
||||||
const magmaPhone = element.all(by.xpath('//div[text()="Phone #: 555-555-5555"]')).get(0);
|
|
||||||
expect(magmaPhone).toBeDefined();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render Hero-of-the-Month runner-ups', () => {
|
it('should render Hero-of-the-Month runner-ups', () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user