[ADF-5422] remove deprecated "async()" from unit tests (#7109)

* remove angualar async from content services

* upgrade more tests

* upgrade core tests

* upgrade tests

* fix deprecated constant

* fix tests

* fix after rebase
This commit is contained in:
Denys Vuika
2021-06-15 16:16:15 +01:00
committed by GitHub
parent ba03c60adb
commit 3079aa48c3
121 changed files with 5316 additions and 4780 deletions

View File

@@ -16,7 +16,7 @@
*/
import { Component } from '@angular/core';
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { setupTestBed } from '@alfresco/adf-core';
import { TranslateService, TranslateModule } from '@ngx-translate/core';
@@ -58,16 +58,16 @@ describe('EmptyContentComponent', () => {
translateService = TestBed.inject(TranslateService);
});
it('should render custom title', async(() => {
it('should render custom title', async () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
const title = fixture.debugElement.query(By.css('.adf-empty-content__title'));
expect(title).toBeDefined('title element not found');
expect(title.nativeElement.textContent).toContain('CUSTOM_TITLE', 'incorrect title value');
});
}));
await fixture.whenStable();
it('should translate title and subtitle', async(() => {
const title = fixture.debugElement.query(By.css('.adf-empty-content__title'));
expect(title).toBeDefined('title element not found');
expect(title.nativeElement.textContent).toContain('CUSTOM_TITLE', 'incorrect title value');
});
it('should translate title and subtitle', async () => {
spyOn(translateService, 'get').and.callFake((key: string) => {
switch (key) {
case 'CUSTOM_TITLE':
@@ -80,17 +80,17 @@ describe('EmptyContentComponent', () => {
});
fixture.detectChanges();
fixture.whenStable().then(() => {
const title = fixture.debugElement.query(By.css('.adf-empty-content__title'));
const subtitle = fixture.debugElement.query(By.css('.adf-empty-content__subtitle'));
await fixture.whenStable();
expect(title).toBeDefined('title element not found');
expect(title.nativeElement.textContent).toContain('ENG_CUSTOM_TITLE', 'incorrect title value');
const title = fixture.debugElement.query(By.css('.adf-empty-content__title'));
const subtitle = fixture.debugElement.query(By.css('.adf-empty-content__subtitle'));
expect(subtitle).toBeDefined('subtitle element not found');
expect(subtitle.nativeElement.textContent).toContain('ENG_CUSTOM_SUBTITLE', 'incorrect subtitle value');
});
}));
expect(title).toBeDefined('title element not found');
expect(title.nativeElement.textContent).toContain('ENG_CUSTOM_TITLE', 'incorrect title value');
expect(subtitle).toBeDefined('subtitle element not found');
expect(subtitle.nativeElement.textContent).toContain('ENG_CUSTOM_SUBTITLE', 'incorrect subtitle value');
});
it('should render multiple subtitle elements', () => {
const subTitles = fixture.debugElement.queryAll(By.css('.adf-empty-content__text'));

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { TestBed, async, ComponentFixture } from '@angular/core/testing';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { CoreTestingModule } from '../../testing/core.testing.module';
import { ErrorContentComponent } from './error-content.component';
import { TranslationService } from '../../services/translation.service';
@@ -40,7 +40,6 @@ describe('ErrorContentComponent', () => {
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
describe(' with an undefined error', () => {
@@ -55,56 +54,57 @@ describe('ErrorContentComponent', () => {
]
});
it('should create error component', async(() => {
it('should render error code', async () => {
fixture.detectChanges();
expect(errorContentComponent).toBeTruthy();
}));
await fixture.whenStable();
it('should render error code', async(() => {
fixture.detectChanges();
const errorContentElement = element.querySelector('.adf-error-content-code');
expect(errorContentElement).not.toBeNull();
expect(errorContentElement).toBeDefined();
}));
});
it('should render error title', async(() => {
it('should render error title', async () => {
fixture.detectChanges();
await fixture.whenStable();
const errorContentElement = element.querySelector('.adf-error-content-title');
expect(errorContentElement).not.toBeNull();
expect(errorContentElement).toBeDefined();
}));
});
it('should render error description', async(() => {
it('should render error description', async () => {
fixture.detectChanges();
await fixture.whenStable();
const errorContentElement = element.querySelector('.adf-error-content-description');
expect(errorContentElement).not.toBeNull();
expect(errorContentElement).toBeDefined();
}));
});
it('should render error description', async(() => {
it('should render error description', async () => {
fixture.detectChanges();
await fixture.whenStable();
const errorContentElement = element.querySelector('.adf-error-content-description');
expect(errorContentElement).not.toBeNull();
expect(errorContentElement).toBeDefined();
}));
});
it('should hide secondary button if this one has no value', async(() => {
spyOn(translateService, 'instant').and.callFake(() => {
return '';
});
it('should hide secondary button if this one has no value', async () => {
spyOn(translateService, 'instant').and.returnValue('');
fixture.detectChanges();
fixture.whenStable().then(() => {
const errorContentElement = element.querySelector('.adf-error-content-description-link');
expect(errorContentElement).toBeNull();
});
}));
await fixture.whenStable();
it('should navigate to the default error UNKNOWN if it does not find the error', async(() => {
const errorContentElement = element.querySelector('.adf-error-content-description-link');
expect(errorContentElement).toBeNull();
});
it('should navigate to the default error UNKNOWN if it does not find the error', async () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(errorContentComponent.errorCode).toBe('UNKNOWN');
});
}));
await fixture.whenStable();
expect(errorContentComponent.errorCode).toBe('UNKNOWN');
});
});
describe(' with a specific error', () => {
@@ -119,12 +119,12 @@ describe('ErrorContentComponent', () => {
]
});
it('should navigate to an error given by the route params', async(() => {
it('should navigate to an error given by the route params', async () => {
spyOn(translateService, 'instant').and.returnValue(of('404'));
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(errorContentComponent.errorCodeTranslated).toBe('404');
});
}));
await fixture.whenStable();
expect(errorContentComponent.errorCodeTranslated).toBe('404');
});
});
});