mirror of
https://github.com/ceph/ceph
synced 2024-12-28 06:23:08 +00:00
Merge pull request #34965 from Devp00l/wip-45433
mgr/dashboard: Always use fast angular unit tests Reviewed-by: Alfonso Martínez <almartin@redhat.com> Reviewed-by: Tiago Melo <tmelo@suse.com>
This commit is contained in:
commit
ac0737555a
@ -315,10 +315,6 @@ to be visible in the rendered template.
|
||||
Running Unit Tests
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Create ``unit-test-configuration.ts`` file based on
|
||||
``unit-test-configuration.ts.sample`` in directory
|
||||
``src/pybind/mgr/dashboard/frontend/src``.
|
||||
|
||||
Run ``npm run test`` to execute the unit tests via `Jest
|
||||
<https://facebook.github.io/jest/>`_.
|
||||
|
||||
|
1
src/pybind/mgr/dashboard/frontend/.gitignore
vendored
1
src/pybind/mgr/dashboard/frontend/.gitignore
vendored
@ -31,7 +31,6 @@
|
||||
npm-debug.log
|
||||
testem.log
|
||||
/typings
|
||||
/src/unit-test-configuration.ts
|
||||
|
||||
# e2e
|
||||
/cypress/screenshots
|
||||
|
@ -18,15 +18,14 @@
|
||||
"i18n:pull": "npx i18ntool pull -c i18n.config.json",
|
||||
"i18n:merge": "npx i18ntool merge -c i18n.config.json",
|
||||
"i18n:token": "npx i18ntool config token",
|
||||
"test": "npm run test:config && jest --watch",
|
||||
"test:ci": "npm run test:config && JEST_SILENT_REPORTER_DOTS=true jest --coverage --reporters jest-silent-reporter",
|
||||
"test:config": "if [ ! -e 'src/unit-test-configuration.ts' ]; then cp 'src/unit-test-configuration.ts.sample' 'src/unit-test-configuration.ts'; fi",
|
||||
"test": "jest --watch",
|
||||
"test:ci": "JEST_SILENT_REPORTER_DOTS=true jest --coverage --reporters jest-silent-reporter",
|
||||
"e2e": "start-test 4200 'cypress open'",
|
||||
"e2e:ci": "start-test 4200 'cypress run -b chrome --headless'",
|
||||
"lint:tslint": "ng lint",
|
||||
"lint:prettier": "prettier --list-different \"{src,cypress}/**/*.{ts,scss}\"",
|
||||
"lint:html": "htmllint src/app/**/*.html && html-linter --config html-linter.config.json",
|
||||
"lint:tsc": "npm run test:config && tsc -p src/tsconfig.app.json --noEmit && tsc -p tsconfig.spec.json --noEmit && tsc -p cypress/tsconfig.json --noEmit",
|
||||
"lint:tsc": "tsc -p src/tsconfig.app.json --noEmit && tsc -p tsconfig.spec.json --noEmit && tsc -p cypress/tsconfig.json --noEmit",
|
||||
"lint": "npm run lint:tsc && npm run lint:tslint && npm run lint:prettier && npm run lint:html",
|
||||
"fix:prettier": "prettier --write \"{src,cypress}/**/*.{ts,scss}\"",
|
||||
"fix:tslint": "npm run lint:tslint -- --fix",
|
||||
|
@ -141,26 +141,23 @@ describe('IscsiTargetFormComponent', () => {
|
||||
}
|
||||
];
|
||||
|
||||
configureTestBed(
|
||||
{
|
||||
declarations: [IscsiTargetFormComponent],
|
||||
imports: [
|
||||
SharedModule,
|
||||
ReactiveFormsModule,
|
||||
HttpClientTestingModule,
|
||||
RouterTestingModule,
|
||||
ToastrModule.forRoot()
|
||||
],
|
||||
providers: [
|
||||
i18nProviders,
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: new ActivatedRouteStub({ target_iqn: undefined })
|
||||
}
|
||||
]
|
||||
},
|
||||
true
|
||||
);
|
||||
configureTestBed({
|
||||
declarations: [IscsiTargetFormComponent],
|
||||
imports: [
|
||||
SharedModule,
|
||||
ReactiveFormsModule,
|
||||
HttpClientTestingModule,
|
||||
RouterTestingModule,
|
||||
ToastrModule.forRoot()
|
||||
],
|
||||
providers: [
|
||||
i18nProviders,
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: new ActivatedRouteStub({ target_iqn: undefined })
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(IscsiTargetFormComponent);
|
||||
|
@ -47,20 +47,17 @@ describe('TelemetryComponent', () => {
|
||||
'url'
|
||||
];
|
||||
|
||||
configureTestBed(
|
||||
{
|
||||
declarations: [TelemetryComponent],
|
||||
imports: [
|
||||
HttpClientTestingModule,
|
||||
ReactiveFormsModule,
|
||||
RouterTestingModule,
|
||||
SharedModule,
|
||||
ToastrModule.forRoot()
|
||||
],
|
||||
providers: i18nProviders
|
||||
},
|
||||
true
|
||||
);
|
||||
configureTestBed({
|
||||
declarations: [TelemetryComponent],
|
||||
imports: [
|
||||
HttpClientTestingModule,
|
||||
ReactiveFormsModule,
|
||||
RouterTestingModule,
|
||||
SharedModule,
|
||||
ToastrModule.forRoot()
|
||||
],
|
||||
providers: i18nProviders
|
||||
});
|
||||
|
||||
describe('configForm', () => {
|
||||
beforeEach(() => {
|
||||
|
@ -21,29 +21,26 @@ describe('NfsFormComponent', () => {
|
||||
let httpTesting: HttpTestingController;
|
||||
let activatedRoute: ActivatedRouteStub;
|
||||
|
||||
configureTestBed(
|
||||
{
|
||||
declarations: [NfsFormComponent, NfsFormClientComponent],
|
||||
imports: [
|
||||
HttpClientTestingModule,
|
||||
ReactiveFormsModule,
|
||||
RouterTestingModule,
|
||||
SharedModule,
|
||||
ToastrModule.forRoot(),
|
||||
TypeaheadModule.forRoot()
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: new ActivatedRouteStub({ cluster_id: undefined, export_id: undefined })
|
||||
},
|
||||
i18nProviders,
|
||||
SummaryService,
|
||||
CephReleaseNamePipe
|
||||
]
|
||||
},
|
||||
true
|
||||
);
|
||||
configureTestBed({
|
||||
declarations: [NfsFormComponent, NfsFormClientComponent],
|
||||
imports: [
|
||||
HttpClientTestingModule,
|
||||
ReactiveFormsModule,
|
||||
RouterTestingModule,
|
||||
SharedModule,
|
||||
ToastrModule.forRoot(),
|
||||
TypeaheadModule.forRoot()
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: new ActivatedRouteStub({ cluster_id: undefined, export_id: undefined })
|
||||
},
|
||||
i18nProviders,
|
||||
SummaryService,
|
||||
CephReleaseNamePipe
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
const summaryService = TestBed.get(SummaryService);
|
||||
|
@ -33,21 +33,18 @@ describe('NfsListComponent', () => {
|
||||
summaryService['summaryDataSource'].next(data);
|
||||
};
|
||||
|
||||
configureTestBed(
|
||||
{
|
||||
declarations: [NfsListComponent, NfsDetailsComponent],
|
||||
imports: [
|
||||
BrowserAnimationsModule,
|
||||
HttpClientTestingModule,
|
||||
RouterTestingModule,
|
||||
SharedModule,
|
||||
ToastrModule.forRoot(),
|
||||
TabsModule.forRoot()
|
||||
],
|
||||
providers: [TaskListService, i18nProviders]
|
||||
},
|
||||
true
|
||||
);
|
||||
configureTestBed({
|
||||
declarations: [NfsListComponent, NfsDetailsComponent],
|
||||
imports: [
|
||||
BrowserAnimationsModule,
|
||||
HttpClientTestingModule,
|
||||
RouterTestingModule,
|
||||
SharedModule,
|
||||
ToastrModule.forRoot(),
|
||||
TabsModule.forRoot()
|
||||
],
|
||||
providers: [TaskListService, i18nProviders]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(NfsListComponent);
|
||||
|
@ -24,21 +24,18 @@ describe('LoginPasswordFormComponent', () => {
|
||||
let authStorageService: AuthStorageService;
|
||||
let authService: AuthService;
|
||||
|
||||
configureTestBed(
|
||||
{
|
||||
imports: [
|
||||
HttpClientTestingModule,
|
||||
RouterTestingModule,
|
||||
ReactiveFormsModule,
|
||||
ComponentsModule,
|
||||
ToastrModule.forRoot(),
|
||||
SharedModule
|
||||
],
|
||||
declarations: [LoginPasswordFormComponent],
|
||||
providers: i18nProviders
|
||||
},
|
||||
true
|
||||
);
|
||||
configureTestBed({
|
||||
imports: [
|
||||
HttpClientTestingModule,
|
||||
RouterTestingModule,
|
||||
ReactiveFormsModule,
|
||||
ComponentsModule,
|
||||
ToastrModule.forRoot(),
|
||||
SharedModule
|
||||
],
|
||||
declarations: [LoginPasswordFormComponent],
|
||||
providers: i18nProviders
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(LoginPasswordFormComponent);
|
||||
|
@ -31,20 +31,17 @@ describe('RoleFormComponent', () => {
|
||||
|
||||
const routes: Routes = [{ path: 'roles', component: FakeComponent }];
|
||||
|
||||
configureTestBed(
|
||||
{
|
||||
imports: [
|
||||
RouterTestingModule.withRoutes(routes),
|
||||
HttpClientTestingModule,
|
||||
ReactiveFormsModule,
|
||||
ToastrModule.forRoot(),
|
||||
SharedModule
|
||||
],
|
||||
declarations: [RoleFormComponent, FakeComponent],
|
||||
providers: i18nProviders
|
||||
},
|
||||
true
|
||||
);
|
||||
configureTestBed({
|
||||
imports: [
|
||||
RouterTestingModule.withRoutes(routes),
|
||||
HttpClientTestingModule,
|
||||
ReactiveFormsModule,
|
||||
ToastrModule.forRoot(),
|
||||
SharedModule
|
||||
],
|
||||
declarations: [RoleFormComponent, FakeComponent],
|
||||
providers: i18nProviders
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(RoleFormComponent);
|
||||
|
@ -44,23 +44,20 @@ describe('UserFormComponent', () => {
|
||||
{ path: 'users', component: FakeComponent }
|
||||
];
|
||||
|
||||
configureTestBed(
|
||||
{
|
||||
imports: [
|
||||
RouterTestingModule.withRoutes(routes),
|
||||
HttpClientTestingModule,
|
||||
ReactiveFormsModule,
|
||||
ComponentsModule,
|
||||
ToastrModule.forRoot(),
|
||||
SharedModule,
|
||||
ButtonsModule.forRoot(),
|
||||
BsDatepickerModule.forRoot()
|
||||
],
|
||||
declarations: [UserFormComponent, FakeComponent],
|
||||
providers: i18nProviders
|
||||
},
|
||||
true
|
||||
);
|
||||
configureTestBed({
|
||||
imports: [
|
||||
RouterTestingModule.withRoutes(routes),
|
||||
HttpClientTestingModule,
|
||||
ReactiveFormsModule,
|
||||
ComponentsModule,
|
||||
ToastrModule.forRoot(),
|
||||
SharedModule,
|
||||
ButtonsModule.forRoot(),
|
||||
BsDatepickerModule.forRoot()
|
||||
],
|
||||
declarations: [UserFormComponent, FakeComponent],
|
||||
providers: i18nProviders
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(TestBed.get(PasswordPolicyService), 'getHelpText').and.callFake(() => of(''));
|
||||
|
@ -22,21 +22,18 @@ describe('UserPasswordFormComponent', () => {
|
||||
let router: Router;
|
||||
let authStorageService: AuthStorageService;
|
||||
|
||||
configureTestBed(
|
||||
{
|
||||
imports: [
|
||||
HttpClientTestingModule,
|
||||
RouterTestingModule,
|
||||
ReactiveFormsModule,
|
||||
ComponentsModule,
|
||||
ToastrModule.forRoot(),
|
||||
SharedModule
|
||||
],
|
||||
declarations: [UserPasswordFormComponent],
|
||||
providers: i18nProviders
|
||||
},
|
||||
true
|
||||
);
|
||||
configureTestBed({
|
||||
imports: [
|
||||
HttpClientTestingModule,
|
||||
RouterTestingModule,
|
||||
ReactiveFormsModule,
|
||||
ComponentsModule,
|
||||
ToastrModule.forRoot(),
|
||||
SharedModule
|
||||
],
|
||||
declarations: [UserPasswordFormComponent],
|
||||
providers: i18nProviders
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(UserPasswordFormComponent);
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
import { configureTestSuite } from 'ng-bullet';
|
||||
import { MockModule } from 'ng-mocks';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
import { configureTestBed } from '../../../../testing/unit-test-helper';
|
||||
import { Permission, Permissions } from '../../../shared/models/permissions';
|
||||
import { AuthStorageService } from '../../../shared/services/auth-storage.service';
|
||||
import {
|
||||
@ -49,23 +49,21 @@ describe('NavigationComponent', () => {
|
||||
let component: NavigationComponent;
|
||||
let fixture: ComponentFixture<NavigationComponent>;
|
||||
|
||||
configureTestSuite(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [NavigationComponent],
|
||||
imports: [MockModule(NavigationModule)],
|
||||
providers: [
|
||||
{
|
||||
provide: AuthStorageService,
|
||||
useValue: {
|
||||
getPermissions: jest.fn(),
|
||||
isPwdDisplayed$: { subscribe: jest.fn() }
|
||||
}
|
||||
},
|
||||
{ provide: SummaryService, useValue: { subscribe: jest.fn() } },
|
||||
{ provide: FeatureTogglesService, useValue: { get: jest.fn() } },
|
||||
{ provide: PrometheusAlertService, useValue: { alerts: [] } }
|
||||
]
|
||||
});
|
||||
configureTestBed({
|
||||
declarations: [NavigationComponent],
|
||||
imports: [MockModule(NavigationModule)],
|
||||
providers: [
|
||||
{
|
||||
provide: AuthStorageService,
|
||||
useValue: {
|
||||
getPermissions: jest.fn(),
|
||||
isPwdDisplayed$: { subscribe: jest.fn() }
|
||||
}
|
||||
},
|
||||
{ provide: SummaryService, useValue: { subscribe: jest.fn() } },
|
||||
{ provide: FeatureTogglesService, useValue: { get: jest.fn() } },
|
||||
{ provide: PrometheusAlertService, useValue: { alerts: [] } }
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -27,13 +27,10 @@ describe('RbdMirroringService', () => {
|
||||
executing_tasks: [{}]
|
||||
};
|
||||
|
||||
configureTestBed(
|
||||
{
|
||||
providers: [RbdMirroringService],
|
||||
imports: [HttpClientTestingModule]
|
||||
},
|
||||
true
|
||||
);
|
||||
configureTestBed({
|
||||
providers: [RbdMirroringService],
|
||||
imports: [HttpClientTestingModule]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
service = TestBed.get(RbdMirroringService);
|
||||
|
@ -11,13 +11,10 @@ describe('SettingsService', () => {
|
||||
const exampleUrl = 'api/settings/something';
|
||||
const exampleValue = 'http://localhost:3000';
|
||||
|
||||
configureTestBed(
|
||||
{
|
||||
providers: [SettingsService],
|
||||
imports: [HttpClientTestingModule]
|
||||
},
|
||||
true
|
||||
);
|
||||
configureTestBed({
|
||||
providers: [SettingsService],
|
||||
imports: [HttpClientTestingModule]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
service = TestBed.get(SettingsService);
|
||||
|
@ -39,14 +39,11 @@ describe('ModuleStatusGuardService', () => {
|
||||
expect(router.url).toBe(urlResult);
|
||||
};
|
||||
|
||||
configureTestBed(
|
||||
{
|
||||
imports: [RouterTestingModule.withRoutes(routes)],
|
||||
providers: [ModuleStatusGuardService, { provide: HttpClient, useValue: fakeService }],
|
||||
declarations: [FooComponent]
|
||||
},
|
||||
true
|
||||
);
|
||||
configureTestBed({
|
||||
imports: [RouterTestingModule.withRoutes(routes)],
|
||||
providers: [ModuleStatusGuardService, { provide: HttpClient, useValue: fakeService }],
|
||||
declarations: [FooComponent]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
service = TestBed.get(ModuleStatusGuardService);
|
||||
|
@ -35,12 +35,9 @@ describe('TaskManagerService', () => {
|
||||
let summaryService: any;
|
||||
let called: boolean;
|
||||
|
||||
configureTestBed(
|
||||
{
|
||||
providers: [TaskManagerService, { provide: SummaryService, useClass: SummaryServiceMock }]
|
||||
},
|
||||
true
|
||||
);
|
||||
configureTestBed({
|
||||
providers: [TaskManagerService, { provide: SummaryService, useClass: SummaryServiceMock }]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
taskManagerService = TestBed.get(TaskManagerService);
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { LOCALE_ID, TRANSLATIONS, TRANSLATIONS_FORMAT, Type } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { AbstractControl } from '@angular/forms';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
import { I18n } from '@ngx-translate/i18n-polyfill';
|
||||
import { configureTestSuite } from 'ng-bullet';
|
||||
import { BsModalRef } from 'ngx-bootstrap/modal';
|
||||
|
||||
import { TableActionsComponent } from '../app/shared/datatable/table-actions/table-actions.component';
|
||||
@ -18,29 +19,9 @@ import {
|
||||
AlertmanagerNotificationAlert,
|
||||
PrometheusRule
|
||||
} from '../app/shared/models/prometheus-alerts';
|
||||
import { _DEV_ } from '../unit-test-configuration';
|
||||
|
||||
export function configureTestBed(configuration: any, useOldMethod?: boolean) {
|
||||
if (_DEV_ && !useOldMethod) {
|
||||
const resetTestingModule = TestBed.resetTestingModule;
|
||||
beforeAll((done) =>
|
||||
(async () => {
|
||||
TestBed.resetTestingModule();
|
||||
TestBed.configureTestingModule(configuration);
|
||||
// prevent Angular from resetting testing module
|
||||
TestBed.resetTestingModule = () => TestBed;
|
||||
})()
|
||||
.then(done)
|
||||
.catch(done.fail)
|
||||
);
|
||||
afterAll(() => {
|
||||
TestBed.resetTestingModule = resetTestingModule;
|
||||
});
|
||||
} else {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule(configuration);
|
||||
}));
|
||||
}
|
||||
export function configureTestBed(configuration: any) {
|
||||
configureTestSuite(() => TestBed.configureTestingModule(configuration));
|
||||
}
|
||||
|
||||
export class PermissionHelper {
|
||||
|
@ -1 +0,0 @@
|
||||
export const _DEV_ = false;
|
@ -14,19 +14,8 @@ fi
|
||||
npm run build -- --prod --progress=false || failed=true
|
||||
|
||||
# Unit Tests
|
||||
config='src/unit-test-configuration.ts'
|
||||
if [ -e $config ]; then
|
||||
mv $config ${config}_old
|
||||
fi
|
||||
cp ${config}.sample $config
|
||||
|
||||
npm run test:ci || failed=true
|
||||
|
||||
rm $config
|
||||
if [ -e ${config}_old ]; then
|
||||
mv ${config}_old $config
|
||||
fi
|
||||
|
||||
# Linting
|
||||
npm run lint --silent
|
||||
if [ $? -gt 0 ]; then
|
||||
|
Loading…
Reference in New Issue
Block a user