Skip to content

Commit

Permalink
test: update ivy i18n integration test
Browse files Browse the repository at this point in the history
The integration test now checks that the locale inlining is working.
  • Loading branch information
petebacondarwin committed Oct 23, 2019
1 parent 8392657 commit 4b52ec0
Show file tree
Hide file tree
Showing 11 changed files with 399 additions and 291 deletions.
8 changes: 8 additions & 0 deletions integration/cli-hello-world-ivy-i18n/angular.json
Expand Up @@ -4,6 +4,13 @@
"newProjectRoot": "projects",
"projects": {
"cli-hello-world-ivy-i18n": {
"i18n": {
"locales": {
"fr": "src/locales/messages.fr.json",
"de": "src/locales/messages.de.json"
},
"sourceLocale": "en"
},
"projectType": "application",
"schematics": {},
"root": "",
Expand Down Expand Up @@ -33,6 +40,7 @@
"tsConfig": "tsconfig.view-engine.json"
},
"production": {
"localize": false, // TODO: enable when CLI supports inlining the locale
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
Expand Down
9 changes: 9 additions & 0 deletions integration/cli-hello-world-ivy-i18n/e2e/de/app.e2e-spec.ts
Expand Up @@ -14,4 +14,13 @@ describe('cli-hello-world-ivy App', () => {
it('should display welcome message', () => {
expect(page.getParagraph('message')).toEqual('Willkommen in der i18n App. (inline)');
});

it('should display the locale', () => { expect(page.getParagraph('locale')).toEqual('de'); });

// TODO : Re-enable when CLI translation inlining supports locale inlining (and so we can use it
// to load the correct locale data)
xit('the date pipe should show the localized month', () => {
page.navigateTo();
expect(page.getParagraph('date')).toEqual('Januar');
});
});
7 changes: 7 additions & 0 deletions integration/cli-hello-world-ivy-i18n/e2e/en/app.e2e-spec.ts
Expand Up @@ -12,4 +12,11 @@ describe('cli-hello-world-ivy App', () => {

it('should display welcome message',
() => { expect(page.getParagraph('message')).toEqual('Welcome to the i18n app.'); });

it('should display the locale', () => { expect(page.getParagraph('locale')).toEqual('en-US'); });

it('the date pipe should show the localized month', () => {
page.navigateTo();
expect(page.getParagraph('date')).toEqual('January');
});
});
7 changes: 7 additions & 0 deletions integration/cli-hello-world-ivy-i18n/e2e/fr/app.e2e-spec.ts
Expand Up @@ -13,4 +13,11 @@ describe('cli-hello-world-ivy App', () => {
it('should display welcome message', () => {
expect(page.getParagraph('message')).toEqual('Bienvenue sur l\'application i18n. (inline)');
});

it('should display the locale', () => { expect(page.getParagraph('locale')).toEqual('fr'); });

it('the date pipe should show the localized month', () => {
page.navigateTo();
expect(page.getParagraph('date')).toEqual('janvier');
});
});
Expand Up @@ -15,4 +15,6 @@ describe('cli-hello-world-ivy App', () => {
// See "translated:legacy:extract-and-update" in package.json.
expect(page.getParagraph('message')).toEqual('Welcome to the i18n app.');
});

it('should display the locale', () => { expect(page.getParagraph('locale')).toEqual('fr'); });
});
Expand Up @@ -19,4 +19,11 @@ describe('cli-hello-world-ivy App', () => {
page.navigateTo();
expect(page.getParagraph('pipe')).toEqual('100 % awesome');
});

it('should display the locale', () => { expect(page.getParagraph('locale')).toEqual('fr'); });

it('the date pipe should show the localized month', () => {
page.navigateTo();
expect(page.getParagraph('date')).toEqual('janvier');
});
});
9 changes: 2 additions & 7 deletions integration/cli-hello-world-ivy-i18n/package.json
Expand Up @@ -13,18 +13,13 @@
"pretest": "ng version",
"test": "ng test && yarn e2e --configuration=ci && yarn e2e --configuration=ci-production && yarn translated:test && yarn translated:legacy:test",
"translate": "localize-translate -r \"dist/\" -s \"**/*\" -l \"en-US\" -t \"src/locales/messages.*\" -o \"../tmp/translations/{{LOCALE}}\"",

"translated:test": "yarn build && yarn translate && yarn translated:fr:e2e && yarn translated:de:e2e && yarn translated:en:e2e",

"translated:fr:serve": "serve ../tmp/translations/fr --listen 4200",
"translated:fr:e2e": "npm-run-all -p -r translated:fr:serve \"ng e2e --configuration=translated-fr\"",

"translated:de:serve": "serve ../tmp/translations/de --listen 4200",
"translated:de:e2e": "npm-run-all -p -r translated:de:serve \"ng e2e --configuration=translated-de\"",

"translated:en:serve": "serve ../tmp/translations/en-US --listen 4200",
"translated:en:e2e": "npm-run-all -p -r translated:en:serve \"ng e2e --configuration=translated-en\"",

"translated:legacy:test": "yarn translated:legacy:extract-and-update && ng build --configuration=translated-legacy && yarn translated:legacy:translate && yarn translated:legacy:e2e",
"translated:legacy:extract-and-update": "ng xi18n && sed -i.bak -e 's/source>/target>'/ -e 's/Hello/Bonjour/' -e 's/source-language=\"en-US\"/source-language=\"en-US\" target-language=\"legacy\"/' ../tmp/legacy-locales/messages.legacy.xlf",
"translated:legacy:translate": "localize-translate -r \"dist/\" -s \"**/*\" -t \"../tmp/legacy-locales/messages.legacy.xlf\" -o \"../tmp/translations/{{LOCALE}}\"",
Expand All @@ -50,8 +45,8 @@
"zone.js": "file:../../node_modules/zone.js"
},
"devDependencies": {
"@angular-devkit/build-angular": "0.900.0-next.12",
"@angular/cli": "file:../../node_modules/@angular/cli",
"@angular-devkit/build-angular": "^0.900.0-next.14",
"@angular/cli": "^9.0.0-next.14",
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
"@angular/language-service": "file:../../dist/packages-dist/language-service",
"@types/jasmine": "~3.4.0",
Expand Down
Expand Up @@ -7,7 +7,9 @@ <h1 i18n>
<p id="message">{{ message }}</p>
<img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
</div>
<p id="locale">{{ locale }}</p>
<p id="pipe">{{ 1 | percent }} awesome</p>
<p id="date">{{ jan | date : 'LLLL' }}</p>
<h2>Here are some links to help you start: </h2>
<ul>
<li>
Expand Down
@@ -1,8 +1,10 @@
import {Component} from '@angular/core';
import {Component, Inject, LOCALE_ID} from '@angular/core';

@Component(
{selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css']})
export class AppComponent {
constructor(@Inject(LOCALE_ID) public locale: string) {}
title = `cli-hello-world-ivy-compat`;
message = $localize `Welcome to the i18n app.`;
jan = new Date(2000, 0, 1);
}
10 changes: 3 additions & 7 deletions integration/cli-hello-world-ivy-i18n/src/app/app.module.ts
@@ -1,17 +1,13 @@
import {registerLocaleData} from '@angular/common';
import {LOCALE_ID, NgModule} from '@angular/core';
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import localeFr from '@angular/common/locales/fr';
import {AppComponent} from './app.component';

// adding this code to detect issues like https://github.com/angular/angular-cli/issues/10322
// it should not affect the CLI importing additional locale data for compile time inlined bundles.
registerLocaleData(localeFr);

@NgModule({
declarations: [AppComponent],
imports: [BrowserModule],
providers: [{provide: LOCALE_ID, useValue: 'fr'}],
bootstrap: [AppComponent]
})
@NgModule({declarations: [AppComponent], imports: [BrowserModule], bootstrap: [AppComponent]})
export class AppModule {
}

0 comments on commit 4b52ec0

Please sign in to comment.