2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2016-06-23 12:47:54 -04:00
|
|
|
*
|
|
|
|
* 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', () => {
|
2020-04-13 19:40:21 -04:00
|
|
|
expect(new PipeResolver(new JitReflector()).resolve(I18nSelectPipe)!.pure).toEqual(true);
|
2017-05-18 16:46:51 -04:00
|
|
|
});
|
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.');
|
|
|
|
});
|
|
|
|
|
2020-04-13 19:40:21 -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
|
|
|
});
|
|
|
|
|
2020-04-13 19:40:21 -04:00
|
|
|
it('should throw on bad arguments', () => {
|
2020-03-27 06:44:00 -04:00
|
|
|
expect(() => pipe.transform('male', 'hey' as any)).toThrowError();
|
2020-04-13 19:40:21 -04:00
|
|
|
});
|
2016-02-26 13:02:52 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|