From 8924ec14746da21cba6583bb5042feb9220f2e65 Mon Sep 17 00:00:00 2001 From: Ajit Singh Date: Tue, 16 Jun 2020 22:25:10 +0530 Subject: [PATCH] test(docs-infra): add end to end tests for api reference (#37612) Api search functionality only had unit tests @gkalpak suggested we should have some e2e tests too. Added some end to end tests. Fixes #35170 PR Close #37612 --- aio/tests/e2e/src/api-list.e2e-spec.ts | 52 +++++++++++++++++++ ...{api.e2e-spec.ts => api-pages.e2e-spec.ts} | 0 aio/tests/e2e/src/app.po.ts | 12 +++++ 3 files changed, 64 insertions(+) create mode 100644 aio/tests/e2e/src/api-list.e2e-spec.ts rename aio/tests/e2e/src/{api.e2e-spec.ts => api-pages.e2e-spec.ts} (100%) diff --git a/aio/tests/e2e/src/api-list.e2e-spec.ts b/aio/tests/e2e/src/api-list.e2e-spec.ts new file mode 100644 index 0000000000..d5d3f2d7db --- /dev/null +++ b/aio/tests/e2e/src/api-list.e2e-spec.ts @@ -0,0 +1,52 @@ +import { by, element } from 'protractor'; +import { SitePage } from './app.po'; + +describe('api-list', () => { + const apiSearchInput = element(by.css('aio-api-list .form-search input')); + const apiStatusDropdown = element(by.css('aio-api-list aio-select[label="Status:"]')); + const apiTypeDropdown = element(by.css('aio-api-list aio-select[label="Type:"]')); + let page: SitePage; + + beforeEach(() => { + page = new SitePage(); + page.navigateTo('api'); + }); + + it('should find AnimationSequenceMetadata when searching by partial word anima', () => { + expect(page.getApiSearchResults()).toContain('HttpEventType'); + + apiSearchInput.clear(); + apiSearchInput.sendKeys('anima'); + + expect(page.getApiSearchResults()).not.toContain('HttpEventType'); + expect(page.getApiSearchResults()).toContain('AnimationSequenceMetadata'); + }); + + it('should find getLocaleDateTimeFormat when searching by partial word date', () => { + expect(page.getApiSearchResults()).toContain('formatCurrency'); + + apiSearchInput.clear(); + apiSearchInput.sendKeys('date'); + + expect(page.getApiSearchResults()).not.toContain('formatCurrency'); + expect(page.getApiSearchResults()).toContain('getLocaleDateTimeFormat'); + }); + + it('should find LowerCasePipe when searching for type pipe', () => { + expect(page.getApiSearchResults()).toContain('getLocaleDateTimeFormat'); + + page.clickDropdownItem(apiTypeDropdown, 'Pipe'); + + expect(page.getApiSearchResults()).not.toContain('getLocaleDateTimeFormat'); + expect(page.getApiSearchResults()).toContain('LowerCasePipe'); + }); + + it('should find ElementRef when searching for status Security Risk', () => { + expect(page.getApiSearchResults()).toContain('getLocaleDateTimeFormat'); + + page.clickDropdownItem(apiStatusDropdown, 'Security Risk'); + + expect(page.getApiSearchResults()).not.toContain('getLocaleDateTimeFormat'); + expect(page.getApiSearchResults()).toContain('ElementRef'); + }); +}); diff --git a/aio/tests/e2e/src/api.e2e-spec.ts b/aio/tests/e2e/src/api-pages.e2e-spec.ts similarity index 100% rename from aio/tests/e2e/src/api.e2e-spec.ts rename to aio/tests/e2e/src/api-pages.e2e-spec.ts diff --git a/aio/tests/e2e/src/app.po.ts b/aio/tests/e2e/src/app.po.ts index 95bca28562..76a7725d63 100644 --- a/aio/tests/e2e/src/app.po.ts +++ b/aio/tests/e2e/src/app.po.ts @@ -83,4 +83,16 @@ export class SitePage { browser.wait(ExpectedConditions.presenceOf(results.first()), 8000); return results.map(link => link && link.getText()); } + + getApiSearchResults() { + const results = element.all(by.css('aio-api-list .api-item')); + browser.wait(ExpectedConditions.presenceOf(results.first()), 2000); + return results.map(elem => elem && elem.getText()); + } + + clickDropdownItem(dropdown: ElementFinder, itemName: string){ + dropdown.element(by.css('.form-select-button')).click(); + const menuItem = dropdown.element(by.cssContainingText('.form-select-dropdown li', itemName)); + menuItem.click(); + } }