diff options
Diffstat (limited to 'polygerrit-ui/app/elements/documentation/gr-documentation-search/gr-documentation-search_test.ts')
-rw-r--r-- | polygerrit-ui/app/elements/documentation/gr-documentation-search/gr-documentation-search_test.ts | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/polygerrit-ui/app/elements/documentation/gr-documentation-search/gr-documentation-search_test.ts b/polygerrit-ui/app/elements/documentation/gr-documentation-search/gr-documentation-search_test.ts index bf6a0d5524..4bba9cd338 100644 --- a/polygerrit-ui/app/elements/documentation/gr-documentation-search/gr-documentation-search_test.ts +++ b/polygerrit-ui/app/elements/documentation/gr-documentation-search/gr-documentation-search_test.ts @@ -19,50 +19,53 @@ import '../../../test/common-test-setup-karma'; import './gr-documentation-search'; import {GrDocumentationSearch} from './gr-documentation-search'; import {page} from '../../../utils/page-wrapper-utils'; -import 'lodash/lodash'; -import {stubRestApi} from '../../../test/test-utils'; +import {queryAndAssert, stubRestApi} from '../../../test/test-utils'; import {DocResult} from '../../../types/common'; -import {ListViewParams} from '../../gr-app-types'; const basicFixture = fixtureFromElement('gr-documentation-search'); -let counter: number; -const documentationGenerator = () => { +function documentationGenerator(counter: number) { return { - title: `Gerrit Code Review - REST API Developers Notes${++counter}`, + title: `Gerrit Code Review - REST API Developers Notes${counter}`, url: 'Documentation/dev-rest-api.html', }; -}; +} + +function createDocumentationList(n: number) { + const list = []; + for (let i = 0; i < n; ++i) { + list.push(documentationGenerator(i)); + } + return list; +} suite('gr-documentation-search tests', () => { let element: GrDocumentationSearch; let documentationSearches: DocResult[]; - let value: ListViewParams; - - setup(() => { + setup(async () => { sinon.stub(page, 'show'); element = basicFixture.instantiate(); - counter = 0; + await element.updateComplete; }); suite('list with searches for documentation', () => { setup(async () => { - documentationSearches = _.times(26, documentationGenerator); + documentationSearches = createDocumentationList(26); stubRestApi('getDocumentationSearches').returns( Promise.resolve(documentationSearches) ); - await element._paramsChanged(value); - await flush(); + await element.paramsChanged(); + await element.updateComplete; }); test('test for test repo in the list', async () => { assert.equal( - element._documentationSearches![0].title, + element.documentationSearches![1].title, 'Gerrit Code Review - REST API Developers Notes1' ); assert.equal( - element._documentationSearches![0].url, + element.documentationSearches![1].url, 'Documentation/dev-rest-api.html' ); }); @@ -70,30 +73,34 @@ suite('gr-documentation-search tests', () => { suite('filter', () => { setup(() => { - documentationSearches = _.times(25, documentationGenerator); + documentationSearches = createDocumentationList(25); }); - test('_paramsChanged', async () => { + test('paramsChanged', async () => { const stub = stubRestApi('getDocumentationSearches').returns( Promise.resolve(documentationSearches) ); - const value = {filter: 'test'}; - await element._paramsChanged(value); + element.params = {filter: 'test'}; + await element.paramsChanged(); assert.isTrue(stub.lastCall.calledWithExactly('test')); }); }); suite('loading', () => { test('correct contents are displayed', async () => { - assert.isTrue(element._loading); - assert.equal(element.computeLoadingClass(element._loading), 'loading'); - assert.equal(getComputedStyle(element.$.loading).display, 'block'); + assert.isTrue(element.loading); + assert.equal( + getComputedStyle(queryAndAssert(element, '#loading')).display, + 'block' + ); - element._loading = false; + element.loading = false; - await flush(); - assert.equal(element.computeLoadingClass(element._loading), ''); - assert.equal(getComputedStyle(element.$.loading).display, 'none'); + await element.updateComplete; + assert.equal( + getComputedStyle(queryAndAssert(element, '#loading')).display, + 'none' + ); }); }); }); |