test(ivy): add runtime translations to integration test app (#32867)

PR Close #32867
This commit is contained in:
Pete Bacon Darwin 2019-10-02 18:17:56 +01:00 committed by atscott
parent 9188751adc
commit 32e315755b
7 changed files with 51 additions and 46 deletions

View File

@ -3,17 +3,20 @@ import { AppPage } from './app.po';
describe('cli-hello-world-ivy App', () => { describe('cli-hello-world-ivy App', () => {
let page: AppPage; let page: AppPage;
beforeEach(() => { beforeEach(() => { page = new AppPage(); });
page = new AppPage();
it('should display title', () => {
page.navigateTo();
expect(page.getHeading()).toEqual('Bonjour cli-hello-world-ivy-compat!');
}); });
it('should display welcome message', () => { it('should display welcome message', () => {
page.navigateTo(); page.navigateTo();
expect(page.getParagraphText()).toEqual('Welcome to cli-hello-world-ivy-compat!'); expect(page.getParagraph('message')).toEqual('Bienvenue sur l\'application i18n.');
}); });
it('the percent pipe should work', () => { it('the percent pipe should work', () => {
page.navigateTo(); page.navigateTo();
expect(page.getPipeContent()).toEqual('100 % awesome'); expect(page.getParagraph('pipe')).toEqual('100 % awesome');
}) });
}); });

View File

@ -1,15 +1,9 @@
import {browser, by, element} from 'protractor'; import {browser, by, element} from 'protractor';
export class AppPage { export class AppPage {
navigateTo() { navigateTo() { return browser.get('/'); }
return browser.get('/');
}
getParagraphText() { getHeading() { return element(by.css('app-root h1')).getText(); }
return element(by.css('app-root h1')).getText();
}
getPipeContent() { getParagraph(name: string) { return element(by.css('app-root p#' + name)).getText(); }
return element(by.css('app-root p')).getText();
}
} }

View File

@ -1,11 +1,13 @@
<!--The content below is only a placeholder and can be replaced.--> <!--The content below is only a placeholder and can be replaced.-->
<div style="text-align:center"> <div style="text-align:center">
<h1 i18n> <h1 i18n>
Welcome to {{ title }}! Hello {{ title }}!
</h1> </h1>
<p id="message">{{ message }}</p>
<img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg=="> <img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
</div> </div>
<p>{{ 1 | percent }} awesome</p> <p id="pipe">{{ 1 | percent }} awesome</p>
<h2>Here are some links to help you start: </h2> <h2>Here are some links to help you start: </h2>
<ul> <ul>
<li> <li>

View File

@ -3,11 +3,11 @@ import { AppComponent } from './app.component';
describe('AppComponent', () => { describe('AppComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed
declarations: [ .configureTestingModule({
AppComponent declarations: [AppComponent],
], })
}).compileComponents(); .compileComponents();
})); }));
it('should create the app', () => { it('should create the app', () => {
@ -26,6 +26,7 @@ describe('AppComponent', () => {
const fixture = TestBed.createComponent(AppComponent); const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges(); fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement; const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('Welcome to cli-hello-world-ivy-compat!'); expect(compiled.querySelector('h1').textContent)
.toContain('Bonjour cli-hello-world-ivy-compat!');
}); });
}); });

View File

@ -1,10 +1,8 @@
import {Component} from '@angular/core'; import {Component} from '@angular/core';
@Component({ @Component(
selector: 'app-root', {selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css']})
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent { export class AppComponent {
title = $localize `cli-hello-world-ivy-compat`; title = `cli-hello-world-ivy-compat`;
message = $localize `Welcome to the i18n app.`;
} }

View File

@ -1,21 +1,17 @@
import { BrowserModule } from '@angular/platform-browser';
import { LOCALE_ID, NgModule } from '@angular/core';
import {registerLocaleData} from '@angular/common'; import {registerLocaleData} from '@angular/common';
import {LOCALE_ID, NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import localeFr from '@angular/common/locales/fr'; import localeFr from '@angular/common/locales/fr';
import {AppComponent} from './app.component'; import {AppComponent} from './app.component';
// adding this code to detect issues like https://github.com/angular/angular-cli/issues/10322 // adding this code to detect issues like https://github.com/angular/angular-cli/issues/10322
registerLocaleData(localeFr); registerLocaleData(localeFr);
@NgModule({ @NgModule({
declarations: [ declarations: [AppComponent],
AppComponent imports: [BrowserModule],
],
imports: [
BrowserModule
],
providers: [{provide: LOCALE_ID, useValue: 'fr'}], providers: [{provide: LOCALE_ID, useValue: 'fr'}],
bootstrap: [AppComponent] bootstrap: [AppComponent]
}) })
export class AppModule { } export class AppModule {
}

View File

@ -86,6 +86,17 @@ import 'zone.js/dist/zone'; // Included with Angular CLI.
*/ */
import '@angular/localize/init'; import '@angular/localize/init';
// Note that `computeMsgId` is a private API at this stage. It will probably be exported directly
// from `@angular/localize` at some point.
import {computeMsgId} from '@angular/compiler';
import {loadTranslations} from '@angular/localize';
// Load some runtime translations!
loadTranslations({
[computeMsgId(' Hello {$INTERPOLATION}! ')]: 'Bonjour {$INTERPOLATION}!',
[computeMsgId('Welcome to the i18n app.')]: 'Bienvenue sur l\'application i18n.',
});
/*************************************************************************************************** /***************************************************************************************************
* APPLICATION IMPORTS * APPLICATION IMPORTS
*/ */