Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/cdk/tests/array/include.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('[TEST]: include', () => {
expect([1, 2, 3].filter(include(4))).toEqual([]);
expect([1, 2, 3].filter(include([2, 3, 4]))).toEqual([2, 3]);
expect([{v: 1}, {v: 2}, {v: 3}].filter(include({v: 1}))).toEqual([]);

const unique: PlainObject = {v: 1};

expect([unique, {v: 2}, {v: 3}].filter(include([unique]))).toEqual([unique]);
Expand Down
1 change: 1 addition & 0 deletions libs/cdk/tests/array/unique-array-of.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable sonarjs/no-hardcoded-ip */
import {uniqueArrayOf} from '@angular-ru/cdk/array';

describe('[TEST]: unique array of', () => {
Expand Down
9 changes: 9 additions & 0 deletions libs/cdk/tests/array/unique.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,65 @@ describe('[TEST]: unique', () => {
[],
);
});

it('should return one object', () => {
expect(
[a].filter((element, index, self) => unique(element, index, self)),
).toEqual([a]);
});

it('should return the same array', () => {
expect(
[a, b, c].filter((element, index, self) => unique(element, index, self)),
).toEqual([a, b, c]);
});

it('should return array with no duplicates of objects', () => {
expect(
[a, b, c, c, a].filter((element, index, self) =>
unique(element, index, self),
),
).toEqual([a, b, c]);
});

it('should return array with no duplicates of strings', () => {
expect(
['a', 'b', 'b', 'b'].filter((element, index, self) =>
unique(element, index, self),
),
).toEqual(['a', 'b']);
});

it('should return array with no duplicates of numbers', () => {
expect(
[13, 13, 13].filter((element, index, self) => unique(element, index, self)),
).toEqual([13]);
});

it('should return array with no duplicates according to values and types', () => {
expect(
[a, a, 'a', 13, 13, '13'].filter((element, index, self) =>
unique(element, index, self),
),
).toEqual([a, 'a', 13, '13']);
});

it('should return array with no duplicates of booleans', () => {
expect(
[true, true, false].filter((element, index, self) =>
unique(element, index, self),
),
).toEqual([true, false]);
});

it('should return array with no duplicates of "no value" types', () => {
expect(
[null, null, undefined, undefined, '', '', Infinity, Infinity].filter(
(element, index, self) => unique(element, index, self),
),
).toEqual([null, undefined, '', Infinity]);
});

it('should return empty array for the array of "NaN"', () => {
expect(
[NaN, NaN].filter((element, index, self) => unique(element, index, self)),
Expand Down
1 change: 1 addition & 0 deletions libs/cdk/tests/array/utility-arrays.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable sonarjs/no-undefined-argument */
import {
exclude,
hasAtMostOneItem,
Expand Down
1 change: 1 addition & 0 deletions libs/cdk/tests/big-decimal/add.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('[TEST]: BigDecimal - add', () => {
it('should: 126.7-13 = 113.7', () => {
expect(BigDecimal.add('126.7', '-13')).toBe('113.7');
});

it('should: 12.67-130.7 = -118.03', () => {
expect(BigDecimal.add('12.67', '-130.7')).toBe('-118.03');
});
Expand Down
1 change: 1 addition & 0 deletions libs/cdk/tests/big-decimal/big-decimal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ describe('[TEST]: BigDecimal - main', () => {
'0',
);
});

it('should: -0.0000005 * 13 = -0.0000065', () => {
expect(
new BigDecimal('-0.0000005').multiply(new BigDecimal('13')).getValue(),
Expand Down
5 changes: 5 additions & 0 deletions libs/cdk/tests/big-decimal/compare-to.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,23 @@ describe('[TEST]: BigDecimal - compareTo', () => {
it('should: 126.7, -13 = 1', () => {
expect(BigDecimal.compareTo('126.7', '-13')).toBe(1);
});

it('should: 12.67, -12.67 = 1', () => {
expect(BigDecimal.compareTo('12.67', '-12.67')).toBe(1);
});

it('should: 12.67, 12.67 = 0', () => {
expect(BigDecimal.compareTo('12.67', '12.67')).toBe(0);
});

it('should: 12.67, 12.6700 = 0', () => {
expect(BigDecimal.compareTo('12.67', '12.6700')).toBe(0);
});

it('should: -12.67, -12.6700 = 0', () => {
expect(BigDecimal.compareTo('-12.67', '-12.6700')).toBe(0);
});

it('should: 0.67, .6700 = 0', () => {
expect(BigDecimal.compareTo('0.67', '.6700')).toBe(0);
});
Expand Down
1 change: 1 addition & 0 deletions libs/cdk/tests/big-decimal/multiply.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('[TEST]: BigDecimal - multiply', () => {
it('should: -12 * -0 = 0', () => {
expect(BigDecimal.multiply('-12', '-0')).toBe('0');
});

it('should: -0.0000005 * 13 = -0.0000065', () => {
expect(BigDecimal.multiply('-0.0000005', '13')).toBe('-0.0000065');
});
Expand Down
2 changes: 2 additions & 0 deletions libs/cdk/tests/class-transformer/class-transformer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ describe('[TEST]: Integration with class-transformer', () => {
const actual: DemoDto = new DemoDto();

actual.numVal = 'INVALID NUMBER';

expect(actual.numVal).toBe('INVALID NUMBER');
expect(plainToClass(DemoDto, actual).numVal).toBeNaN();
});
Expand All @@ -137,6 +138,7 @@ describe('[TEST]: Integration with class-transformer', () => {
const actual: DemoDto = new DemoDto();

actual.numVal = ' 100 ';

expect(actual.numVal).toBe(' 100 ');
expect(plainToClass(DemoDto, actual).numVal).toBe(100);
});
Expand Down
50 changes: 21 additions & 29 deletions libs/cdk/tests/class-transformer/transform-to-boolean.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,28 @@ import {transformToBoolean} from '@angular-ru/cdk/class-transformer';
import {TransformFnParams} from 'class-transformer';

describe('[TEST] TransformToBoolean', () => {
it('should return true', () => {
const data: TransformFnParams[] = [
{value: true} as TransformFnParams,
{value: 'true'} as TransformFnParams,
{value: '12312s'} as TransformFnParams,
{value: '0'} as TransformFnParams,
{value: '1'} as TransformFnParams,
{value: {}} as TransformFnParams,
{value: []} as TransformFnParams,
{value: ''} as TransformFnParams,
{value: ' '} as TransformFnParams,
];

for (const item of data) {
expect(transformToBoolean(item)).toBe(true);
}
it.each<TransformFnParams>([
{value: true} as TransformFnParams,
{value: 'true'} as TransformFnParams,
{value: '12312s'} as TransformFnParams,
{value: '0'} as TransformFnParams,
{value: '1'} as TransformFnParams,
{value: {}} as TransformFnParams,
{value: []} as TransformFnParams,
{value: ''} as TransformFnParams,
{value: ' '} as TransformFnParams,
])('should return true', (item: TransformFnParams) => {
expect(transformToBoolean(item)).toBe(true);
});

it('should return false', () => {
const data: TransformFnParams[] = [
{value: ' false '} as TransformFnParams,
{value: 'false'} as TransformFnParams,
{value: false} as TransformFnParams,
{value: 0} as TransformFnParams,
{value: null} as TransformFnParams,
{value: undefined} as TransformFnParams,
];

for (const item of data) {
expect(transformToBoolean(item)).toBe(false);
}
it.each<TransformFnParams>([
{value: ' false '} as TransformFnParams,
{value: 'false'} as TransformFnParams,
{value: false} as TransformFnParams,
{value: 0} as TransformFnParams,
{value: null} as TransformFnParams,
{value: undefined} as TransformFnParams,
])('should return false', (item: TransformFnParams) => {
expect(transformToBoolean(item)).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,33 @@ import {transformToNullableBoolean} from '@angular-ru/cdk/class-transformer';
import {TransformFnParams} from 'class-transformer';

describe('[TEST] TransformToNullableBoolean', () => {
it('should return true', () => {
const data: TransformFnParams[] = [
{value: true} as TransformFnParams,
{value: 'true'} as TransformFnParams,
{value: '12312s'} as TransformFnParams,
{value: '0'} as TransformFnParams,
{value: '1'} as TransformFnParams,
{value: {}} as TransformFnParams,
{value: []} as TransformFnParams,
{value: ''} as TransformFnParams,
{value: ' '} as TransformFnParams,
];

for (const item of data) {
expect(transformToNullableBoolean(item)).toBe(true);
}
it.each<TransformFnParams>([
{value: true} as TransformFnParams,
{value: 'true'} as TransformFnParams,
{value: '12312s'} as TransformFnParams,
{value: '0'} as TransformFnParams,
{value: '1'} as TransformFnParams,
{value: {}} as TransformFnParams,
{value: []} as TransformFnParams,
{value: ''} as TransformFnParams,
{value: ' '} as TransformFnParams,
])('should return true', (item: TransformFnParams) => {
expect(transformToNullableBoolean(item)).toBe(true);
});

it('should return false', () => {
const data: TransformFnParams[] = [
{value: ' false '} as TransformFnParams,
{value: 'false'} as TransformFnParams,
{value: false} as TransformFnParams,
{value: 0} as TransformFnParams,
];

for (const item of data) {
expect(transformToNullableBoolean(item)).toBe(false);
}
it.each<TransformFnParams>([
{value: ' false '} as TransformFnParams,
{value: 'false'} as TransformFnParams,
{value: false} as TransformFnParams,
{value: 0} as TransformFnParams,
])('should return false', (item: TransformFnParams) => {
expect(transformToNullableBoolean(item)).toBe(false);
});

it('should return null', () => {
const data: TransformFnParams[] = [
{value: null} as TransformFnParams,
{value: undefined} as TransformFnParams,
];

for (const item of data) {
expect(transformToNullableBoolean(item)).toBeNull();
}
it.each<TransformFnParams>([
{value: null} as TransformFnParams,
{value: undefined} as TransformFnParams,
])('should return null', (item: TransformFnParams) => {
expect(transformToNullableBoolean(item)).toBeNull();
});
});
35 changes: 20 additions & 15 deletions libs/cdk/tests/date/end-of-day.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,38 @@ describe('[TEST]: EndOfDay', (): void => {
const expectDate: Date = endOfDay(someDate);
const withoutTimezone: string = toISOStringWithoutTimezone(expectDate);

if (timezoneOffSet <= 0) {
expect(withoutTimezone).toBe('2021-03-29T23:59:59.999');
} else {
expect(withoutTimezone).toBe('2021-03-28T23:59:59.999');
}
const result =
timezoneOffSet <= 0
? '2021-03-29T23:59:59.999'
: '2021-03-28T23:59:59.999';

expect(withoutTimezone).toBe(result);
});

it('should correctly convert "2021-03-29T23:00:00.000Z"', (): void => {
const someDate: Date = new Date('2021-03-29T23:00:00.000Z');
const expectDate: Date = endOfDay(someDate);
const withoutTimezone: string = toISOStringWithoutTimezone(expectDate);

if (timezoneOffSet <= -60) {
expect(withoutTimezone).toBe('2021-03-30T23:59:59.999');
} else {
expect(withoutTimezone).toBe('2021-03-29T23:59:59.999');
}
const result =
timezoneOffSet <= -60
? '2021-03-30T23:59:59.999'
: '2021-03-29T23:59:59.999';

expect(withoutTimezone).toBe(result);
});

it('should correctly convert "2021-03-29T23:59:59.999Z"', (): void => {
const someDate: Date = new Date('2021-03-29T23:59:59.999Z');
const expectDate: Date = endOfDay(someDate);
const withoutTimezone: string = toISOStringWithoutTimezone(expectDate);

if (timezoneOffSet < 0) {
expect(withoutTimezone).toBe('2021-03-30T23:59:59.999');
} else {
expect(withoutTimezone).toBe('2021-03-29T23:59:59.999');
}
const result =
timezoneOffSet < 0
? '2021-03-30T23:59:59.999'
: '2021-03-29T23:59:59.999';

expect(withoutTimezone).toBe(result);
});
});
});
6 changes: 6 additions & 0 deletions libs/cdk/tests/date/serial-date.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,27 @@ describe('[TEST]: Date', (): void => {
expect(date).toBe('2019-07-05 00:00:00');

date = toTimestamp('1.2.2019', isoFormat);

expect(date).toBe('2019-02-01 00:00:00');

date = toTimestamp('0.0.2019', isoFormat);

expect(date).toBe('2019-01-01 00:00:00');

date = toTimestamp('3..2019', isoFormat);

expect(date).toBe('2019-01-03 00:00:00');

date = toTimestamp('.2.2019', isoFormat);

expect(date).toBe('2019-02-01 00:00:00');

date = toTimestamp('..2019', isoFormat);

expect(date).toBe('2019-01-01 00:00:00');

date = toTimestamp('.2.2019 01:00', isoFormat);

expect(date).toBe('2019-02-01 01:00:00');
});

Expand Down
2 changes: 2 additions & 0 deletions libs/cdk/tests/date/shift-date.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ describe('[TEST]: ShiftDate', (): void => {

expect(expectDate.toISOString()).toBe('2022-05-23T00:00:06.000Z');
});

it('should correctly add year', (): void => {
const expectDate: Date = shiftDate({years: 1}, someDate);

expect(expectDate.toISOString()).toBe('2022-03-20T00:00:00.000Z');
});

it('should correctly minus year', (): void => {
const expectDate: Date = shiftDate({years: -1}, someDate);

Expand Down
Loading
Loading