Skip to content

Commit

Permalink
test(): fix standalone component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AmitMY committed Nov 27, 2024
1 parent 45bc810 commit 146b51d
Show file tree
Hide file tree
Showing 70 changed files with 395 additions and 565 deletions.
74 changes: 38 additions & 36 deletions src/app/app-routing.spec.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
import {TestBed} from '@angular/core/testing';
import {AppRoutingModule} from './app-routing.module';
import {Router} from '@angular/router';
import {AppNgxsModule} from './core/modules/ngxs/ngxs.module';
import {provideHttpClient} from '@angular/common/http';

describe('AppRoutingModule', () => {
let router: Router;

beforeEach(async () => {
await TestBed.configureTestingModule({
teardown: {destroyAfterEach: false},
imports: [AppRoutingModule, AppNgxsModule],
providers: [provideHttpClient()],
});
});

const pages = {
'/': 'translate',
'/playground': 'playground',
'/about': 'about',
'/benchmark': 'benchmark',
'/legal': 'legal',
};

for (const [path, page] of Object.entries(pages)) {
it(`should load ${page} page`, () => {
router = TestBed.inject(Router);
router.initialNavigation();

router.navigate([path]);
const route = router.getCurrentNavigation();
expect(String(route.extractedUrl)).toEqual(path);
});
}
});
// import {TestBed} from '@angular/core/testing';
// import {AppRoutingModule} from './app-routing.module';
// import {Router} from '@angular/router';
// import {provideStore([SettingsState], ngxsConfig)} from './core/modules/ngxs/ngxs.module';
// import {provideHttpClient} from '@angular/common/http';
// import {ngxsConfig} from './app.config';
// import {SettingsState} from './modules/settings/settings.state';
//
// describe('AppRoutingModule', () => {
// let router: Router;
//
// beforeEach(async () => {
// await TestBed.configureTestingModule({
// teardown: {destroyAfterEach: false},
// imports: [AppRoutingModule, provideStore([SettingsState], ngxsConfig)],
// providers: [provideHttpClient()],
// });
// });
//
// const pages = {
// '/': 'translate',
// '/playground': 'playground',
// '/about': 'about',
// '/benchmark': 'benchmark',
// '/legal': 'legal',
// };
//
// for (const [path, page] of Object.entries(pages)) {
// it(`should load ${page} page`, () => {
// router = TestBed.inject(Router);
// router.initialNavigation();
//
// router.navigate([path]);
// const route = router.getCurrentNavigation();
// expect(String(route.extractedUrl)).toEqual(path);
// });
// }
// });
5 changes: 3 additions & 2 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
import {AppComponent} from './app.component';
import {AppModule} from './app.module';
import {axe, toHaveNoViolations} from 'jasmine-axe';
import {Store} from '@ngxs/store';
import {SetSpokenLanguageText} from './modules/translate/translate.actions';
import {TranslocoService} from '@ngneat/transloco';
import {Router} from '@angular/router';
import {appConfig} from './app.config';

describe('AppComponent', () => {
let store: Store;
Expand All @@ -14,7 +14,8 @@ describe('AppComponent', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [AppModule],
imports: [AppComponent],
providers: appConfig.providers,
}).compileComponents();
}));

Expand Down
1 change: 0 additions & 1 deletion src/app/app.config.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {ApplicationConfig, mergeApplicationConfig} from '@angular/core';
import {appConfig} from './app.config';
import {provideServerRendering} from '@angular/platform-server';

const serverConfig: ApplicationConfig = {
providers: [
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/animation/animation.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {axe, toHaveNoViolations} from 'jasmine-axe';
import {AnimationComponent} from './animation.component';
import {NgxsModule} from '@ngxs/store';
import {AnimationState} from '../../modules/animation/animation.state';
import {ngxsConfig} from '../../core/modules/ngxs/ngxs.module';
import {SettingsState} from '../../modules/settings/settings.state';
import {PoseState} from '../../modules/pose/pose.state';
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
import {ngxsConfig} from '../../app.config';

describe('AnimationComponent', () => {
let component: AnimationComponent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {axe, toHaveNoViolations} from 'jasmine-axe';

import {
AppTranslocoTestingModule,
provideTranslocoTesting,
} from '../../core/modules/transloco/transloco-testing.module';
import {AppTranslocoTestingModule} from '../../core/modules/transloco/transloco-testing.module';
import {RouterModule} from '@angular/router';
import {I18NLanguageSelectorComponent} from './i18n-language-selector.component';
import {languageCodeNormalizer, SITE_LANGUAGES} from '../../core/modules/transloco/languages';
Expand All @@ -15,7 +12,7 @@ describe('LanguageSelectorComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [provideTranslocoTesting(), RouterModule.forRoot([]), I18NLanguageSelectorComponent],
imports: [AppTranslocoTestingModule, RouterModule.forRoot([]), I18NLanguageSelectorComponent],
}).compileComponents();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import {axe, toHaveNoViolations} from 'jasmine-axe';

import {SpeechToTextComponent} from './speech-to-text.component';
import {AppTranslocoTestingModule} from '../../core/modules/transloco/transloco-testing.module';
import {MatTooltipModule} from '@angular/material/tooltip';
import {IonButton, IonIcon} from '@ionic/angular/standalone';

describe('SpeechToTextComponent', () => {
let component: SpeechToTextComponent;
let fixture: ComponentFixture<SpeechToTextComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [provideTranslocoTesting(), MatTooltipModule, IonIcon, IonButton, SpeechToTextComponent],
imports: [AppTranslocoTestingModule, SpeechToTextComponent],
}).compileComponents();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {ComponentFixture, TestBed} from '@angular/core/testing';
import {axe, toHaveNoViolations} from 'jasmine-axe';

import {TextToSpeechComponent} from './text-to-speech.component';
import {AppTranslocoTestingModule} from '../../core/modules/transloco/transloco-testing.module';

import {SimpleChange} from '@angular/core';
import {IonButton, IonIcon} from '@ionic/angular/standalone';
import {AppTranslocoTestingModule} from '../../core/modules/transloco/transloco-testing.module';
import Spy = jasmine.Spy;

describe('TextToSpeechComponent', () => {
Expand All @@ -25,7 +25,7 @@ describe('TextToSpeechComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [provideTranslocoTesting(), IonIcon, IonButton, TextToSpeechComponent],
imports: [AppTranslocoTestingModule, TextToSpeechComponent],
}).compileComponents();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,20 @@ import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
import {axe, toHaveNoViolations} from 'jasmine-axe';

import {VideoControlsComponent} from './video-controls.component';
import {AppTranslocoTestingModule} from '../../../core/modules/transloco/transloco-testing.module';
import {NgxsModule} from '@ngxs/store';

import {provideStore} from '@ngxs/store';
import {SettingsState} from '../../../modules/settings/settings.state';
import {ngxsConfig} from '../../../app.config';
import {MatTooltipModule} from '@angular/material/tooltip';
import {IonFab, IonFabButton} from '@ionic/angular/standalone';
import {AppTranslocoTestingModule} from '../../../core/modules/transloco/transloco-testing.module';

describe('VideoControlsComponent', () => {
let component: VideoControlsComponent;
let fixture: ComponentFixture<VideoControlsComponent>;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [
provideTranslocoTesting(),
MatTooltipModule,
IonFab,
IonFabButton,
provideStore([SettingsState], ngxsConfig),
VideoControlsComponent,
],
imports: [AppTranslocoTestingModule, VideoControlsComponent],
providers: [provideStore([SettingsState], ngxsConfig)],
}).compileComponents();
}));

Expand Down
20 changes: 4 additions & 16 deletions src/app/components/video/video.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,23 @@ import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
import {axe, toHaveNoViolations} from 'jasmine-axe';

import {VideoComponent} from './video.component';
import {VideoControlsComponent} from './video-controls/video-controls.component';
import {AnimationComponent} from '../animation/animation.component';
import {NgxsModule} from '@ngxs/store';
import {SettingsState} from '../../modules/settings/settings.state';
import {ngxsConfig} from '../../core/modules/ngxs/ngxs.module';
import {VideoState} from '../../core/modules/ngxs/store/video/video.state';
import {SignWritingState} from '../../modules/sign-writing/sign-writing.state';
import {PoseState} from '../../modules/pose/pose.state';
import {DetectorState} from '../../modules/detector/detector.state';
import {provideStore} from '@ngxs/store';
import {AppTranslocoTestingModule} from '../../core/modules/transloco/transloco-testing.module';
import {MatTooltipModule} from '@angular/material/tooltip';
import {IonFab, IonIcon} from '@ionic/angular/standalone';
import {ngxsConfig} from '../../app.config';

describe('VideoComponent', () => {
let component: VideoComponent;
let fixture: ComponentFixture<VideoComponent>;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [
provideTranslocoTesting(),
MatTooltipModule,
IonIcon,
IonFab,
provideStore([SettingsState, VideoState, SignWritingState, PoseState, DetectorState], ngxsConfig),
VideoComponent,
VideoControlsComponent,
AnimationComponent,
],
imports: [AppTranslocoTestingModule, VideoComponent],
providers: [provideStore([SettingsState, VideoState, SignWritingState, PoseState, DetectorState], ngxsConfig)],
}).compileComponents();
}));

Expand Down
8 changes: 4 additions & 4 deletions src/app/core/modules/ngxs/store/video/video.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {TestBed} from '@angular/core/testing';
import {NgxsModule, Store} from '@ngxs/store';
import {provideStore, Store} from '@ngxs/store';
import {VideoState, VideoStateModel} from './video.state';
import {StartCamera, StopVideo} from './video.actions';
import {NavigatorService} from '../../../../services/navigator/navigator.service';
import {firstValueFrom} from 'rxjs';
import {ngxsConfig} from '../../ngxs.module';
import {ngxsConfig} from '../../../../../app.config';

describe('VideoState', () => {
let store: Store;
Expand All @@ -31,8 +31,8 @@ describe('VideoState', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [NgxsModule.forRoot([VideoState], ngxsConfig)],
providers: [NavigatorService],
imports: [],
providers: [provideStore([VideoState], ngxsConfig), NavigatorService],
});

mockCamera = new MediaStream();
Expand Down
13 changes: 4 additions & 9 deletions src/app/core/modules/transloco/transloco-testing.module.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import {provideTransloco, TranslocoTestingModule} from '@ngneat/transloco';
import {TranslocoTestingModule} from '@ngneat/transloco';
import {SITE_LANGUAGES} from './languages';

const availableLangs = SITE_LANGUAGES.map(l => l.key.toLocaleLowerCase());

const langs = {};
availableLangs.forEach(lang => (langs[lang] = require(`../../../../assets/i18n/${lang}.json`)));

const translocoTestingConfig = {
export const AppTranslocoTestingModule = TranslocoTestingModule.forRoot({
langs,
translocoConfig: {
availableLangs,
defaultLang: 'en',
reRenderOnLangChange: true,
},
preloadLangs: true,
};

export const AppTranslocoTestingModule = TranslocoTestingModule.forRoot({...translocoTestingConfig, langs});

export function provideTranslocoTesting(), {
return provideTransloco(translocoTestingConfig); // TODO add transloco loader
}
});
2 changes: 1 addition & 1 deletion src/app/modules/animation/animation.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {MediapipeHolisticService} from '../../core/services/holistic.service';
import {PoseModule} from '../pose/pose.module';
import {NgxsModule} from '@ngxs/store';
import {SettingsState} from '../settings/settings.state';
import {ngxsConfig} from '../../core/modules/ngxs/ngxs.module';
import {ngxsConfig} from '../../app.config';

describe('AnimationService', () => {
let service: AnimationService;
Expand Down
22 changes: 0 additions & 22 deletions src/app/modules/settings/settings.module.ts

This file was deleted.

15 changes: 3 additions & 12 deletions src/app/modules/settings/settings/settings.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import {ComponentFixture, TestBed} from '@angular/core/testing';
import {axe, toHaveNoViolations} from 'jasmine-axe';

import {SettingsComponent} from './settings.component';
import {NgxsModule, Store} from '@ngxs/store';
import {provideStore, Store} from '@ngxs/store';
import {SettingsState} from '../settings.state';
import {FormsModule} from '@angular/forms';
import {ngxsConfig} from '../../../app.config';
import {AppTranslocoTestingModule} from '../../../core/modules/transloco/transloco-testing.module';
import {IonCheckbox, IonItem, IonList} from '@ionic/angular/standalone';

describe('SettingsComponent', () => {
let store: Store;
Expand All @@ -16,15 +14,8 @@ describe('SettingsComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
provideStore([SettingsState], ngxsConfig),
FormsModule,
provideTranslocoTesting(),
IonItem,
IonCheckbox,
IonList,
SettingsComponent,
],
imports: [AppTranslocoTestingModule, SettingsComponent],
providers: [provideStore([SettingsState], ngxsConfig)],
}).compileComponents();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import {ComponentFixture, TestBed} from '@angular/core/testing';
import {axe, toHaveNoViolations} from 'jasmine-axe';

import {BenchmarkItemComponent} from './benchmark-item.component';

import {MatTooltipModule} from '@angular/material/tooltip';
import {provideIonicAngular} from '@ionic/angular/standalone';

describe('BenchmarkItemComponent', () => {
let component: BenchmarkItemComponent;
let fixture: ComponentFixture<BenchmarkItemComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatTooltipModule, provideIonicAngular(), BenchmarkItemComponent],
imports: [BenchmarkItemComponent],
providers: [provideIonicAngular()],
}).compileComponents();
});

Expand Down
Loading

0 comments on commit 146b51d

Please sign in to comment.