2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
import {I18nSelectPipe} from '@angular/common';
|
|
|
|
import {PipeResolver} from '@angular/compiler/src/pipe_resolver';
|
2017-08-16 12:00:03 -04:00
|
|
|
import {JitReflector} from '@angular/platform-browser-dynamic/src/compiler_reflector';
|
2016-02-26 13:02:52 -05:00
|
|
|
|
2017-12-16 17:42:55 -05:00
|
|
|
{
|
2016-06-08 19:38:52 -04:00
|
|
|
describe('I18nSelectPipe', () => {
|
2016-11-04 17:49:53 -04:00
|
|
|
const pipe: I18nSelectPipe = new I18nSelectPipe();
|
|
|
|
const mapping = {'male': 'Invite him.', 'female': 'Invite her.', 'other': 'Invite them.'};
|
2016-02-26 13:02:52 -05:00
|
|
|
|
2017-05-18 16:46:51 -04:00
|
|
|
it('should be marked as pure', () => {
|
|
|
|
expect(new PipeResolver(new JitReflector()).resolve(I18nSelectPipe) !.pure).toEqual(true);
|
|
|
|
});
|
2016-02-26 13:02:52 -05:00
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
describe('transform', () => {
|
2016-11-04 17:49:53 -04:00
|
|
|
it('should return the "male" text if value is "male"', () => {
|
|
|
|
const val = pipe.transform('male', mapping);
|
2016-02-26 13:02:52 -05:00
|
|
|
expect(val).toEqual('Invite him.');
|
|
|
|
});
|
|
|
|
|
2016-11-04 17:49:53 -04:00
|
|
|
it('should return the "female" text if value is "female"', () => {
|
|
|
|
const val = pipe.transform('female', mapping);
|
2016-02-26 13:02:52 -05:00
|
|
|
expect(val).toEqual('Invite her.');
|
|
|
|
});
|
|
|
|
|
2016-11-04 17:49:53 -04:00
|
|
|
it('should return the "other" text if value is neither "male" nor "female"',
|
|
|
|
() => { expect(pipe.transform('Anything else', mapping)).toEqual('Invite them.'); });
|
2016-02-26 13:02:52 -05:00
|
|
|
|
2016-11-04 17:49:53 -04:00
|
|
|
it('should return an empty text if value is null or undefined', () => {
|
|
|
|
expect(pipe.transform(null, mapping)).toEqual('');
|
|
|
|
expect(pipe.transform(void 0, mapping)).toEqual('');
|
2016-02-26 13:02:52 -05:00
|
|
|
});
|
|
|
|
|
2016-11-04 17:49:53 -04:00
|
|
|
it('should throw on bad arguments',
|
2016-06-17 13:57:32 -04:00
|
|
|
() => { expect(() => pipe.transform('male', <any>'hey')).toThrowError(); });
|
2016-02-26 13:02:52 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|