Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Romanchuk committed Jun 3, 2024
1 parent 5e96955 commit 50c5f38
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 32 deletions.
11 changes: 7 additions & 4 deletions apps/angular-i18next-demo/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { TestBed } from '@angular/core/testing';
import { TestBed, waitForAsync } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { RouterTestingModule } from '@angular/router/testing';
import { I18NextModule } from 'angular-i18next';
import { I18N_PROVIDERS } from './app.module';

describe('AppComponent', () => {
beforeEach(waitForAsync(() => {
beforeEach(waitForAsync(async () => {
await TestBed.configureTestingModule({
imports: [RouterTestingModule],
imports: [I18NextModule.forRoot(), RouterTestingModule],
providers: [I18N_PROVIDERS],
declarations: [AppComponent],
}).compileComponents();
});
}));

it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
Expand Down
27 changes: 20 additions & 7 deletions apps/angular-i18next-demo/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import {
Event as RouterEvent, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, Router
} from '@angular/router';
import { I18NEXT_SERVICE, ITranslationService } from 'angular-i18next';
import { filter, map, mergeMap } from 'rxjs/operators';
import { filter, map, mergeMap, tap } from 'rxjs/operators';

// import 'assets/ng-validation.css';

@Component({
selector: 'app',
Expand All @@ -17,9 +16,16 @@ export class AppComponent implements OnInit {

loading = true;
start = 0;

get title() {
return this._title.getTitle();
}

constructor(private router: Router,
private title: Title,
private _title: Title,
@Inject(I18NEXT_SERVICE) private i18NextService: ITranslationService) {


// spinner/loader subscription
router.events
.subscribe((event: RouterEvent) => {
Expand All @@ -42,11 +48,18 @@ export class AppComponent implements OnInit {
}

ngOnInit() {
this.i18NextService.events.languageChanged.subscribe(lang => {
this.i18NextService.events.languageChanged.subscribe(() => {
const root = this.router.routerState.root;
if (root != null && root.firstChild != null) {
const data: any = root.firstChild.data;
this.updatePageTitle(data && data.value && data.value.title);
const data = root.firstChild.data;
data
.pipe(
tap((data) => {
this.updatePageTitle(data && data['value'] && data['value'].title);
})
)
.subscribe();

}
});
}
Expand All @@ -66,7 +79,7 @@ export class AppComponent implements OnInit {
updatePageTitle(title: string): void {
const newTitle = title || 'application_title';
console.log('Setting page title:', newTitle);
this.title.setTitle(newTitle);
this._title.setTitle(newTitle);
console.log('Setting page title end:', newTitle);
}
}
4 changes: 1 addition & 3 deletions libs/angular-i18next/src/test-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ import {
} from '@angular/platform-browser-dynamic/testing';

getTestBed().resetTestEnvironment();
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), {
teardown: { destroyAfterEach: false },
});
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
2 changes: 1 addition & 1 deletion libs/angular-i18next/src/tests/pipes/I18NextPipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { I18N_PROVIDERS } from '../setup';

describe('I18NextPipe tests', function () {

beforeEach(async () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [I18NextModule.forRoot()],
providers: [...I18N_PROVIDERS],
Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"eslint-plugin-cypress": "2.15.1",
"i18next": "23.7.6",
"jest": "^29.7.0",
"jest-preset-angular": "13.1.4",
"jest-preset-angular": "~14.1.0",
"keyv": "^4.5.1",
"ng-packagr": "17.0.2",
"np": "~8.0.4",
Expand Down

0 comments on commit 50c5f38

Please sign in to comment.