Skip to content

Commit d6c130f

Browse files
committed
refactor spec test to handle translations correctly
1 parent 98e550d commit d6c130f

File tree

1 file changed

+62
-60
lines changed

1 file changed

+62
-60
lines changed

test/unit/app.spec.ts

Lines changed: 62 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7,91 +7,93 @@ import { HttpClient } from 'aurelia-fetch-client';
77

88
import { AppViewModel } from '../../src/app/app.vm';
99
import { AppConfigService } from '../../src/app/services/app-config.service';
10-
import EnglishTranslation from '../../src/locales/en_US.json';
10+
import en_USTranslation from './../../src/locales/en_US.json';
11+
import de_CHTranslation from './../../src/locales/de_CH.json';
1112

1213
class RouterStub {
13-
public routes;
14-
public options = {
14+
public routes;
15+
public options = {
1516
pushState: undefined
1617
};
1718

18-
public configure(handler): void {
19-
handler(this);
20-
}
19+
public configure(handler): void {
20+
handler(this);
21+
}
2122

22-
public map(routes): void {
23-
this.routes = routes;
24-
}
23+
public map(routes): void {
24+
this.routes = routes;
25+
}
2526

2627
public mapUnknownRoutes(route): void { ; }
2728

2829
public addAuthorizeStep(step): void { ; }
2930
}
3031

3132
describe('the App module', () => {
32-
let sut;
33-
let mockedRouter;
33+
let sut;
34+
let mockedRouter;
3435
let appConfigSub;
3536

36-
beforeEach(() => {
37-
mockedRouter = new RouterStub();
37+
beforeEach(() => {
38+
mockedRouter = new RouterStub();
3839

3940
const AnyMock: any = undefined;
4041

41-
// Translation setup
42+
// Translation setup
4243
sut = new I18N(new EventAggregator(), new BindingSignaler());
4344
sut.setup({
4445
resources: {
45-
en: {
46-
translation: EnglishTranslation
47-
}
46+
'en-US': {
47+
translation: en_USTranslation
48+
},
49+
'de-CH': {
50+
translation: de_CHTranslation
51+
}
4852
},
49-
lng: 'en',
50-
fallbackLng: 'en',
51-
debug: false
53+
lng: 'en-US'
5254
});
5355

5456
appConfigSub = new AppConfigService();
5557

5658
sut = new AppViewModel(sut, appConfigSub, AnyMock, AnyMock, AnyMock, new HttpClient());
57-
sut.configureRouter(mockedRouter, mockedRouter);
58-
});
59-
60-
it('contains a router property', () => {
61-
expect(sut.router).toBeDefined();
62-
});
63-
64-
it('configures the router title', () => {
65-
expect(sut.router.title).toEqual('Transaltion Title');
66-
});
67-
68-
it('should have a welcome route', () => {
69-
expect(sut.router.routes).toContain({
70-
route: ['', 'welcome'],
71-
name: 'welcome',
72-
moduleId: './modules/welcome/welcome.vm',
73-
nav: true,
74-
title: 'Welcome'
75-
});
76-
});
77-
78-
it('should have a users route', () => {
79-
expect(sut.router.routes).toContain({
80-
route: 'users',
81-
name: 'users',
82-
moduleId: './modules/users/users.vm',
83-
nav: true,
84-
title: 'Github Users'
85-
});
86-
});
87-
88-
it('should have a child router route', () => {
89-
expect(sut.router.routes).toContain({
90-
route: 'child-router',
91-
name: 'child-router',
92-
moduleId: './modules/child-router/child-router.vm',
93-
nav: true,
94-
title: 'Child Router'
95-
});
96-
});
59+
sut.configureRouter(mockedRouter, mockedRouter);
60+
});
61+
62+
it('contains a router property', () => {
63+
expect(sut.router).toBeDefined();
64+
});
65+
66+
it('configures the router title', () => {
67+
expect(sut.router.title).toEqual('Transaltion Title');
68+
});
69+
70+
it('should have a welcome route', () => {
71+
expect(sut.router.routes).toContain({
72+
route: ['', 'welcome'],
73+
name: 'welcome',
74+
moduleId: './modules/welcome/welcome.vm',
75+
nav: true,
76+
title: 'Welcome'
77+
});
78+
});
79+
80+
it('should have a users route', () => {
81+
expect(sut.router.routes).toContain({
82+
route: 'users',
83+
name: 'users',
84+
moduleId: './modules/users/users.vm',
85+
nav: true,
86+
title: 'Github Users'
87+
});
88+
});
89+
90+
it('should have a child router route', () => {
91+
expect(sut.router.routes).toContain({
92+
route: 'child-router',
93+
name: 'child-router',
94+
moduleId: './modules/child-router/child-router.vm',
95+
nav: true,
96+
title: 'Child Router'
97+
});
98+
});
9799
});

0 commit comments

Comments
 (0)