Skip to content

Commit

Permalink
fix(trim): Fixed boolean option condition and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengunneweg authored and bartholomej committed Aug 20, 2024
1 parent aad6e96 commit 8432f28
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { SEPARATOR } from './ngx-translate-cut.constants';
import { ngxTranslateCutOptionsFactory } from './ngx-translate-cut.options.factory';
import { NgxTranslateCutOptions } from './ngx-translate-cut.options.interface';
import { NgxTranslateCutOptionsService } from './ngx-translate-cut.options.service';

describe('ngxTranslateCutOptionsFactory', () => {
let factory: (options?: NgxTranslateCutOptions) => NgxTranslateCutOptionsService;

beforeEach(() => {
factory = ngxTranslateCutOptionsFactory;
});

it('should be created with default options', () => {
const result = factory();

expect(result.separator).toEqual(SEPARATOR);
expect(result.trim).toEqual(true);
});

it('should be created with custom options', () => {
const result = factory({
separator: '*',
trim: false,
});

expect(result.separator).toEqual('*');
expect(result.trim).toEqual(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const ngxTranslateCutOptionsFactory = (
if (options.separator) {
ngxTranslateCutOptionsService.separator = options.separator;
}
if (options.trim) {
if (options.trim !== undefined) {
ngxTranslateCutOptionsService.trim = options.trim;
}
}
Expand Down
28 changes: 28 additions & 0 deletions projects/ngx-translate-cut/src/lib/ngx-translate-cut.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,32 @@ describe('NgxTranslateCutPipe', () => {
expect(pipe.transform(null, 0))
.toEqual('');
});

describe('Separator', () => {
const dataWithCustomSeparator = 'first * second * last';

it('Should use custom separator', () => {
options.separator = '*';

expect(pipe.transform(dataWithCustomSeparator, 0))
.toEqual('first');
expect(pipe.transform(dataWithCustomSeparator, 1))
.toEqual('second');
expect(pipe.transform(dataWithCustomSeparator, 2))
.toEqual('last');
});
});

describe('Trim', () => {
it('Should omit trim', () => {
options.trim = false;

expect(pipe.transform(data, 0))
.toEqual('first ');
expect(pipe.transform(data, 1))
.toEqual(' second ');
expect(pipe.transform(data, 2))
.toEqual(' last');
});
});
});

0 comments on commit 8432f28

Please sign in to comment.