diff --git a/.github/workflows/deploy-apps.yml b/.github/workflows/deploy-apps.yml index cfc2aae27..765cad8fc 100644 --- a/.github/workflows/deploy-apps.yml +++ b/.github/workflows/deploy-apps.yml @@ -2,7 +2,7 @@ name: CI Deploy on: push: - branches: [ "main" ] + branches: ['main'] paths: - 'apps/**' - 'libs/**' @@ -20,7 +20,7 @@ permissions: # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. concurrency: - group: "pages" + group: 'pages' cancel-in-progress: false jobs: @@ -91,7 +91,7 @@ jobs: cp -r dist/tooltip-demo/* deploy/tooltip-demo/ mkdir deploy/virtual-table-demo cp -r dist/virtual-table-demo/* deploy/virtual-table-demo/ - + # Create a 404.html to handle SPA routing redirects cp deploy/index.html deploy/404.html diff --git a/libs/cdk/CHANGELOG.md b/libs/cdk/CHANGELOG.md index 933bd9622..db893552e 100644 --- a/libs/cdk/CHANGELOG.md +++ b/libs/cdk/CHANGELOG.md @@ -7,12 +7,15 @@ All notable changes to this project will be documented in this file. See ### Bug Fixes -* **cdk:** virtual table now correctly rerenders after setting sort types manually multiple times ([c5f715c](https://github.com/Angular-RU/angular-ru-sdk/commit/c5f715c3098aa53f18d66da72b49bacdd190524a)) +- **cdk:** virtual table now correctly rerenders after setting sort types manually multiple times + ([c5f715c](https://github.com/Angular-RU/angular-ru-sdk/commit/c5f715c3098aa53f18d66da72b49bacdd190524a)) ### Features -* angular v20 and NX v21 ([1aa382d](https://github.com/Angular-RU/angular-ru-sdk/commit/1aa382d505962c260c6f8a871bdb7d58d2b8b1cb)) -* standalone components and pipes; root providers instead of forRoot(); removal of ngModules ([729959c](https://github.com/Angular-RU/angular-ru-sdk/commit/729959c201623ffc4406d680d46908059d9a5754)) +- angular v20 and NX v21 + ([1aa382d](https://github.com/Angular-RU/angular-ru-sdk/commit/1aa382d505962c260c6f8a871bdb7d58d2b8b1cb)) +- standalone components and pipes; root providers instead of forRoot(); removal of ngModules + ([729959c](https://github.com/Angular-RU/angular-ru-sdk/commit/729959c201623ffc4406d680d46908059d9a5754)) # [15.2.0](https://github.com/Angular-RU/angular-ru-sdk/compare/@angular-ru/cdk@15.1.0...@angular-ru/cdk@15.2.0) (2024-04-10) diff --git a/libs/cdk/tests/array/include.spec.ts b/libs/cdk/tests/array/include.spec.ts index 244dbf988..9dfac22c5 100644 --- a/libs/cdk/tests/array/include.spec.ts +++ b/libs/cdk/tests/array/include.spec.ts @@ -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]); diff --git a/libs/cdk/tests/array/unique-array-of.spec.ts b/libs/cdk/tests/array/unique-array-of.spec.ts index f7fc2c6fc..e84b9c8c3 100644 --- a/libs/cdk/tests/array/unique-array-of.spec.ts +++ b/libs/cdk/tests/array/unique-array-of.spec.ts @@ -1,3 +1,4 @@ +/* eslint-disable sonarjs/no-hardcoded-ip */ import {uniqueArrayOf} from '@angular-ru/cdk/array'; describe('[TEST]: unique array of', () => { diff --git a/libs/cdk/tests/array/unique.spec.ts b/libs/cdk/tests/array/unique.spec.ts index 11010cccd..d7424cb37 100644 --- a/libs/cdk/tests/array/unique.spec.ts +++ b/libs/cdk/tests/array/unique.spec.ts @@ -10,16 +10,19 @@ 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) => @@ -27,6 +30,7 @@ describe('[TEST]: unique', () => { ), ).toEqual([a, b, c]); }); + it('should return array with no duplicates of strings', () => { expect( ['a', 'b', 'b', 'b'].filter((element, index, self) => @@ -34,11 +38,13 @@ describe('[TEST]: unique', () => { ), ).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) => @@ -46,6 +52,7 @@ describe('[TEST]: unique', () => { ), ).toEqual([a, 'a', 13, '13']); }); + it('should return array with no duplicates of booleans', () => { expect( [true, true, false].filter((element, index, self) => @@ -53,6 +60,7 @@ describe('[TEST]: unique', () => { ), ).toEqual([true, false]); }); + it('should return array with no duplicates of "no value" types', () => { expect( [null, null, undefined, undefined, '', '', Infinity, Infinity].filter( @@ -60,6 +68,7 @@ describe('[TEST]: unique', () => { ), ).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)), diff --git a/libs/cdk/tests/array/utility-arrays.spec.ts b/libs/cdk/tests/array/utility-arrays.spec.ts index 190fa3fce..3770ec412 100644 --- a/libs/cdk/tests/array/utility-arrays.spec.ts +++ b/libs/cdk/tests/array/utility-arrays.spec.ts @@ -1,3 +1,4 @@ +/* eslint-disable sonarjs/no-undefined-argument */ import { exclude, hasAtMostOneItem, diff --git a/libs/cdk/tests/big-decimal/add.spec.ts b/libs/cdk/tests/big-decimal/add.spec.ts index af8cee639..c964d21e3 100644 --- a/libs/cdk/tests/big-decimal/add.spec.ts +++ b/libs/cdk/tests/big-decimal/add.spec.ts @@ -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'); }); diff --git a/libs/cdk/tests/big-decimal/big-decimal.spec.ts b/libs/cdk/tests/big-decimal/big-decimal.spec.ts index d88e20507..cd3d32a25 100644 --- a/libs/cdk/tests/big-decimal/big-decimal.spec.ts +++ b/libs/cdk/tests/big-decimal/big-decimal.spec.ts @@ -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(), diff --git a/libs/cdk/tests/big-decimal/compare-to.spec.ts b/libs/cdk/tests/big-decimal/compare-to.spec.ts index fa63150d0..3da866308 100644 --- a/libs/cdk/tests/big-decimal/compare-to.spec.ts +++ b/libs/cdk/tests/big-decimal/compare-to.spec.ts @@ -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); }); diff --git a/libs/cdk/tests/big-decimal/multiply.spec.ts b/libs/cdk/tests/big-decimal/multiply.spec.ts index 4633f89b6..de4eb87ec 100644 --- a/libs/cdk/tests/big-decimal/multiply.spec.ts +++ b/libs/cdk/tests/big-decimal/multiply.spec.ts @@ -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'); }); diff --git a/libs/cdk/tests/class-transformer/class-transformer.spec.ts b/libs/cdk/tests/class-transformer/class-transformer.spec.ts index 1b543dc6a..3349dde08 100644 --- a/libs/cdk/tests/class-transformer/class-transformer.spec.ts +++ b/libs/cdk/tests/class-transformer/class-transformer.spec.ts @@ -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(); }); @@ -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); }); diff --git a/libs/cdk/tests/class-transformer/transform-to-boolean.spec.ts b/libs/cdk/tests/class-transformer/transform-to-boolean.spec.ts index 41aa7ae35..6257454cf 100644 --- a/libs/cdk/tests/class-transformer/transform-to-boolean.spec.ts +++ b/libs/cdk/tests/class-transformer/transform-to-boolean.spec.ts @@ -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([ + {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([ + {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); }); }); diff --git a/libs/cdk/tests/class-transformer/transform-to-nullable-boolean.spec.ts b/libs/cdk/tests/class-transformer/transform-to-nullable-boolean.spec.ts index 85d15edba..f059d3abb 100644 --- a/libs/cdk/tests/class-transformer/transform-to-nullable-boolean.spec.ts +++ b/libs/cdk/tests/class-transformer/transform-to-nullable-boolean.spec.ts @@ -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([ + {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([ + {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([ + {value: null} as TransformFnParams, + {value: undefined} as TransformFnParams, + ])('should return null', (item: TransformFnParams) => { + expect(transformToNullableBoolean(item)).toBeNull(); }); }); diff --git a/libs/cdk/tests/date/end-of-day.spec.ts b/libs/cdk/tests/date/end-of-day.spec.ts index 7281dd7ed..b14ccd1d2 100644 --- a/libs/cdk/tests/date/end-of-day.spec.ts +++ b/libs/cdk/tests/date/end-of-day.spec.ts @@ -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); }); }); }); diff --git a/libs/cdk/tests/date/serial-date.spec.ts b/libs/cdk/tests/date/serial-date.spec.ts index c418e1723..e56c2fccf 100644 --- a/libs/cdk/tests/date/serial-date.spec.ts +++ b/libs/cdk/tests/date/serial-date.spec.ts @@ -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'); }); diff --git a/libs/cdk/tests/date/shift-date.spec.ts b/libs/cdk/tests/date/shift-date.spec.ts index f6fe84a98..3e25c6264 100644 --- a/libs/cdk/tests/date/shift-date.spec.ts +++ b/libs/cdk/tests/date/shift-date.spec.ts @@ -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); diff --git a/libs/cdk/tests/date/start-of-day.spec.ts b/libs/cdk/tests/date/start-of-day.spec.ts index 081b3cb7e..144390ef0 100644 --- a/libs/cdk/tests/date/start-of-day.spec.ts +++ b/libs/cdk/tests/date/start-of-day.spec.ts @@ -10,33 +10,38 @@ describe('[TEST]: StartOfDay', (): void => { const expectDate: Date = startOfDay(someDate); const withoutTimezone: string = toISOStringWithoutTimezone(expectDate); - if (timezoneOffSet <= 0) { - expect(withoutTimezone).toBe('2021-03-29T00:00:00.000'); - } else { - expect(withoutTimezone).toBe('2021-03-28T00:00:00.000'); - } + const result = + timezoneOffSet <= 0 + ? '2021-03-29T00:00:00.000' + : '2021-03-28T00:00:00.000'; + + expect(withoutTimezone).toBe(result); }); + it('should correctly convert "2021-03-29T20:00:00.000Z"', (): void => { const someDate: Date = new Date('2021-03-29T23:00:00.000Z'); const expectDate: Date = startOfDay(someDate); const withoutTimezone: string = toISOStringWithoutTimezone(expectDate); - if (timezoneOffSet <= -60) { - expect(withoutTimezone).toBe('2021-03-30T00:00:00.000'); - } else { - expect(withoutTimezone).toBe('2021-03-29T00:00:00.000'); - } + const result = + timezoneOffSet <= -60 + ? '2021-03-30T00:00:00.000' + : '2021-03-29T00:00:00.000'; + + 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 = startOfDay(someDate); const withoutTimezone: string = toISOStringWithoutTimezone(expectDate); - if (timezoneOffSet < 0) { - expect(withoutTimezone).toBe('2021-03-30T00:00:00.000'); - } else { - expect(withoutTimezone).toBe('2021-03-29T00:00:00.000'); - } + const result = + timezoneOffSet < 0 + ? '2021-03-30T00:00:00.000' + : '2021-03-29T00:00:00.000'; + + expect(withoutTimezone).toBe(result); }); }); }); diff --git a/libs/cdk/tests/date/to-iso-string-without-timezone.spec.ts b/libs/cdk/tests/date/to-iso-string-without-timezone.spec.ts index bbe771142..a61f9b0b0 100644 --- a/libs/cdk/tests/date/to-iso-string-without-timezone.spec.ts +++ b/libs/cdk/tests/date/to-iso-string-without-timezone.spec.ts @@ -1,30 +1,24 @@ import {toISOStringWithoutTimezone} from '@angular-ru/cdk/date'; describe('[TEST]: toISOStringWithoutTimezone', (): void => { - const timezoneOffSet: number = new Date().getTimezoneOffset(); - it('should correctly parse "2020-01-01T00:00:00.000Z"', (): void => { const someDate: Date = new Date('2020-01-01T00:00:00.000Z'); const expectDate: string = toISOStringWithoutTimezone(someDate); - if (timezoneOffSet === -180) { - expect(expectDate).toBe('2020-01-01T03:00:00.000'); - } + expect(expectDate).toBe('2020-01-01T03:00:00.000'); }); + it('should correctly parse "2020-02-02T10:10:10.000Z"', (): void => { const someDate: Date = new Date('2020-02-02T10:10:10.000Z'); const expectDate: string = toISOStringWithoutTimezone(someDate); - if (timezoneOffSet === -180) { - expect(expectDate).toBe('2020-02-02T13:10:10.000'); - } + expect(expectDate).toBe('2020-02-02T13:10:10.000'); }); + it('should correctly parse "2020-12-31T23:59:59.999Z"', (): void => { const someDate: Date = new Date('2020-12-31T23:59:59.999Z'); const expectDate: string = toISOStringWithoutTimezone(someDate); - if (timezoneOffSet === -180) { - expect(expectDate).toBe('2021-01-01T02:59:59.999'); - } + expect(expectDate).toBe('2021-01-01T02:59:59.999'); }); }); diff --git a/libs/cdk/tests/http/limit-concurrency/limit-concurrency.service.spec.ts b/libs/cdk/tests/http/limit-concurrency/limit-concurrency.service.spec.ts index e1f0ccf1e..6c712cd27 100644 --- a/libs/cdk/tests/http/limit-concurrency/limit-concurrency.service.spec.ts +++ b/libs/cdk/tests/http/limit-concurrency/limit-concurrency.service.spec.ts @@ -1,3 +1,4 @@ +/* eslint-disable jest/prefer-ending-with-an-expect */ import {LimitConcurrencyService} from '@angular-ru/cdk/http'; import {merge} from 'rxjs'; import {TestScheduler} from 'rxjs/testing'; diff --git a/libs/cdk/tests/number/number.spec.ts b/libs/cdk/tests/number/number.spec.ts index dac69566f..f18242439 100644 --- a/libs/cdk/tests/number/number.spec.ts +++ b/libs/cdk/tests/number/number.spec.ts @@ -128,6 +128,7 @@ describe('[TEST]: Number', () => { '1 500 300', ); expect(numberFormat(null)).toBe(''); + // eslint-disable-next-line sonarjs/no-undefined-argument expect(numberFormat(undefined)).toBe(''); expect(numberFormat()).toBe(''); expect(numberFormat(NaN)).toBe(''); diff --git a/libs/cdk/tests/object/object.spec.ts b/libs/cdk/tests/object/object.spec.ts index 75e31a9eb..ea907956a 100644 --- a/libs/cdk/tests/object/object.spec.ts +++ b/libs/cdk/tests/object/object.spec.ts @@ -1,3 +1,4 @@ +/* eslint-disable sonarjs/no-primitive-wrappers */ import { checkIsShallowEmpty, clean, @@ -254,9 +255,11 @@ describe('[TEST]: Object', () => { expect(Object.is(origin, copy)).toBe(false); copy.b.c = 4; + expect(origin.b.c).toBe(2); origin.b.c = 3; + expect(origin.b.c).toBe(3); expect(copy.b.c).toBe(4); }); @@ -274,6 +277,7 @@ describe('[TEST]: Object', () => { expect(deepClone(NaN)).toBeNull(); expect(deepClone(Infinity)).toBeNull(); expect(deepClone(null)).toBeNull(); + // eslint-disable-next-line sonarjs/no-undefined-argument expect(deepClone(undefined)).toBeUndefined(); }); diff --git a/libs/cdk/tests/pipes/file-size.pipe.spec.ts b/libs/cdk/tests/pipes/file-size.pipe.spec.ts index 672809964..8394db752 100644 --- a/libs/cdk/tests/pipes/file-size.pipe.spec.ts +++ b/libs/cdk/tests/pipes/file-size.pipe.spec.ts @@ -11,15 +11,25 @@ describe('[TEST]: File Size Pipe', (): void => { let fileSize = 1100; expect(fileSizePipe.transform(fileSize)).toBe('1.07 Kb'); + fileSize = 13; + expect(fileSizePipe.transform(fileSize)).toBe('13.00 bytes'); + fileSize = 2399033; + expect(fileSizePipe.transform(fileSize)).toBe('2.29 Mb'); + fileSize = 2399030030; + expect(fileSizePipe.transform(fileSize)).toBe('2.23 Gb'); + fileSize = 2399030030033; + expect(fileSizePipe.transform(fileSize)).toBe('2.18 Tb'); + fileSize = 2399030303030030; + expect(fileSizePipe.transform(fileSize)).toBe('2.13 Pb'); }); }); diff --git a/libs/cdk/tests/pipes/filter-unique.pipe.spec.ts b/libs/cdk/tests/pipes/filter-unique.pipe.spec.ts index 7ce96cdc9..64a994d98 100644 --- a/libs/cdk/tests/pipes/filter-unique.pipe.spec.ts +++ b/libs/cdk/tests/pipes/filter-unique.pipe.spec.ts @@ -1,3 +1,4 @@ +/* eslint-disable sonarjs/no-hardcoded-ip */ import {FilterUniquePipe} from '../../pipes/filter-unique/filter-unique.pipe'; describe('[TEST]: Filter Unique Pipe', (): void => { diff --git a/libs/cdk/tests/rxjs/number.spec.ts b/libs/cdk/tests/rxjs/number.spec.ts index 0a1eeccbd..1b1033255 100644 --- a/libs/cdk/tests/rxjs/number.spec.ts +++ b/libs/cdk/tests/rxjs/number.spec.ts @@ -1,12 +1,11 @@ import {mapToVoid} from '@angular-ru/cdk/rxjs'; -import {of} from 'rxjs'; +import {firstValueFrom, of} from 'rxjs'; describe('[TEST]: RxJS', () => { - it('mapToVoid', () => { - of([1, 2, 3]) - .pipe(mapToVoid()) - .subscribe((result) => { - expect(result).toBeUndefined(); - }); + it('mapToVoid', async () => { + const value$ = of([1, 2, 3]).pipe(mapToVoid()); + const result = await firstValueFrom(value$); + + expect(result).toBeUndefined(); }); }); diff --git a/libs/cdk/tests/stream/jwt.spec.ts b/libs/cdk/tests/stream/jwt.spec.ts index bd64a6c30..bf1c6fd68 100644 --- a/libs/cdk/tests/stream/jwt.spec.ts +++ b/libs/cdk/tests/stream/jwt.spec.ts @@ -48,6 +48,7 @@ describe('[TEST]: JWT', (): void => { }); it('should be correct encode', (): void => { + // eslint-disable-next-line sonarjs/no-hardcoded-credentials expect(toBase64({login: 'username', password: 'password'})).toBe( 'eyJsb2dpbiI6InVzZXJuYW1lIiwicGFzc3dvcmQiOiJwYXNzd29yZCJ9', ); diff --git a/libs/cdk/tests/string/filter.spec.ts b/libs/cdk/tests/string/filter.spec.ts index 3e34314c0..e44296f57 100644 --- a/libs/cdk/tests/string/filter.spec.ts +++ b/libs/cdk/tests/string/filter.spec.ts @@ -26,7 +26,7 @@ describe('[TEST]: Filter', () => { it('should remove spaces', () => { expect(filter(' a b c ', ['a', 'b', 'c'])).toBe('abc'); - expect(filter(' a b c ', ['a', 'b', 'c', '\\s'])).toBe('abc'); + expect(filter(' a b c ', ['a', 'b', 'c', String.raw`\s`])).toBe('abc'); }); it('should keep spaces', () => { diff --git a/libs/cdk/tests/utils/utils.spec.ts b/libs/cdk/tests/utils/utils.spec.ts index 7ebb7e81c..37f2c8758 100644 --- a/libs/cdk/tests/utils/utils.spec.ts +++ b/libs/cdk/tests/utils/utils.spec.ts @@ -278,6 +278,7 @@ describe('[TEST]: Common utils', () => { it('should correct build file name', () => { jest.spyOn(document, 'createElement').mockImplementation(() => link); downloadFile(file); + expect(link.download).toBe('text.txt'); }); @@ -306,6 +307,7 @@ describe('[TEST]: Common utils', () => { it('should create download link', () => { jest.spyOn(document, 'createElement').mockImplementation(() => link); downloadFile(file); + expect(link.href).toBeDefined(); }); diff --git a/libs/cdk/tests/validators/date-interval-validator.spec.ts b/libs/cdk/tests/validators/date-interval-validator.spec.ts index affe8e59c..403ff9da3 100644 --- a/libs/cdk/tests/validators/date-interval-validator.spec.ts +++ b/libs/cdk/tests/validators/date-interval-validator.spec.ts @@ -25,6 +25,7 @@ describe('date interval validator', () => { // changing to valid value form.controls?.['dateFrom']?.setValue(toUtc({month: new Date().getMonth() - 1})); + expect(form.valid).toBe(true); }); @@ -47,6 +48,7 @@ describe('date interval validator', () => { // changing to valid value form.controls?.['dateFrom']?.setValue(toUtc({month: new Date().getMonth() - 3})); + expect(form.valid).toBe(true); }); @@ -73,10 +75,12 @@ describe('date interval validator', () => { // changing to valid value form.controls?.['dateFrom']?.setValue(toUtc({month: new Date().getMonth() - 2})); + expect(form.valid).toBe(true); // changing to invalid value again form.controls?.['dateFrom']?.setValue(toUtc({month: new Date().getMonth() - 3})); + expect(form.errors).toEqual({maxDateIntervalLimit: true}); }); }); diff --git a/libs/cdk/tests/validators/date-limit-validator.spec.ts b/libs/cdk/tests/validators/date-limit-validator.spec.ts index f1325059d..1fea69fb7 100644 --- a/libs/cdk/tests/validators/date-limit-validator.spec.ts +++ b/libs/cdk/tests/validators/date-limit-validator.spec.ts @@ -14,10 +14,12 @@ describe('date limit validator', () => { // changing to extreme valid value control.setValue(toUtc({month: new Date().getMonth() - 2})); + expect(control.valid).toBe(true); // changing to valid value control.setValue(toUtc({month: new Date().getMonth() - 3})); + expect(control.valid).toBe(true); }); @@ -32,10 +34,12 @@ describe('date limit validator', () => { // changing to extreme valid value control.setValue(toUtc({month: new Date().getMonth() - 2})); + expect(control.valid).toBe(true); // changing to valid value control.setValue(toUtc({month: new Date().getMonth() - 1})); + expect(control.valid).toBe(true); }); @@ -53,17 +57,21 @@ describe('date limit validator', () => { // changing to extreme valid value control.setValue(toUtc({month: new Date().getMonth() - 3})); + expect(control.valid).toBe(true); control.setValue(toUtc({month: new Date().getMonth() - 1})); + expect(control.valid).toBe(true); // changing to valid value control.setValue(toUtc({month: new Date().getMonth() - 2})); + expect(control.valid).toBe(true); // changing to invalid value again control.setValue(toUtc({month: new Date().getMonth()})); + expect(control.errors).toEqual({maxDateLimitExceeded: true}); }); }); diff --git a/libs/cdk/tests/validators/long-validator.spec.ts b/libs/cdk/tests/validators/long-validator.spec.ts index 93a0ba919..f2328dd5b 100644 --- a/libs/cdk/tests/validators/long-validator.spec.ts +++ b/libs/cdk/tests/validators/long-validator.spec.ts @@ -10,89 +10,114 @@ describe('[TEST]: longValidator', () => { it('should be valid with values range: (-9223372036854775808, 9223372036854775807)', () => { control.setValue('13'); + expect(control.errors).toBeNull(); control.setValue('-9223372036854775808'); + expect(control.errors).toBeNull(); control.setValue('9223372036854775807'); + expect(control.errors).toBeNull(); control.setValue('-1'); + expect(control.errors).toBeNull(); control.setValue('0'); + expect(control.errors).toBeNull(); control.setValue('1'); + expect(control.errors).toBeNull(); }); it('should switch validation correctly', () => { control.setValue('13'); + expect(control.errors).toBeNull(); control.setValue('99999999999999999999999999999'); + expect(control.errors?.['long']).toBe(true); control.setValue('13'); + expect(control.errors).toBeNull(); }); it('should return error if value is out of range: (-9223372036854775808, 9223372036854775807)', () => { control.setValue('-9223372036854775809'); + expect(control.errors?.['long']).toBe(true); control.setValue('9223372036854775808'); + expect(control.errors?.['long']).toBe(true); control.setValue('-99999999999999999999999999999'); + expect(control.errors?.['long']).toBe(true); control.setValue('99999999999999999999999999999'); + expect(control.errors?.['long']).toBe(true); }); it('should not return error for empty values', () => { control.setValue(''); + expect(control.errors).toBeNull(); control.setValue(' '); + expect(control.errors).toBeNull(); control.setValue(undefined); + expect(control.errors).toBeNull(); control.setValue(null); + expect(control.errors).toBeNull(); }); it('should correctly validate numbers', () => { control.setValue(13); + expect(control.errors).toBeNull(); // eslint-disable-next-line @typescript-eslint/no-loss-of-precision control.setValue(99999999999999999999999999999); + expect(control.errors?.['long']).toBe(true); }); it('should return errors for incorrect numbers', () => { control.setValue('a'); + expect(control.errors?.['long']).toBe(true); control.setValue('abc'); + expect(control.errors?.['long']).toBe(true); control.setValue('1a'); + expect(control.errors?.['long']).toBe(true); control.setValue('a1'); + expect(control.errors?.['long']).toBe(true); control.setValue('abc13abc'); + expect(control.errors?.['long']).toBe(true); control.setValue('abc 13 abc'); + expect(control.errors?.['long']).toBe(true); }); }); diff --git a/libs/cdk/tests/validators/multi-validators.spec.ts b/libs/cdk/tests/validators/multi-validators.spec.ts index 0c3d0a4d9..b6179eef1 100644 --- a/libs/cdk/tests/validators/multi-validators.spec.ts +++ b/libs/cdk/tests/validators/multi-validators.spec.ts @@ -36,6 +36,7 @@ describe('[TEST]: requiredSomeValueByKeysValidator vs orderedIntervalValidator', controlFrom.setValue(toUtc()); controlTo.setValue(toUtc({month: new Date().getMonth() + 1})); controlA.setValue(1); + expect(form.valid).toBe(true); }); @@ -61,6 +62,7 @@ describe('[TEST]: requiredSomeValueByKeysValidator vs orderedIntervalValidator', controlFrom.setValue(toUtc()); controlTo.setValue(toUtc()); + expect(form.errors).toEqual({requiredSomeValueByKeys: true}); }); @@ -72,6 +74,7 @@ describe('[TEST]: requiredSomeValueByKeysValidator vs orderedIntervalValidator', controlFrom.setValue(toUtc()); controlTo.setValue(toUtc({month: new Date().getMonth() - 1})); controlA.setValue(1); + expect(form.errors).toEqual({orderedInterval: true}); }); }); diff --git a/libs/cdk/tests/validators/ordered-interval-validator.spec.ts b/libs/cdk/tests/validators/ordered-interval-validator.spec.ts index c08369ff6..5ba420f9a 100644 --- a/libs/cdk/tests/validators/ordered-interval-validator.spec.ts +++ b/libs/cdk/tests/validators/ordered-interval-validator.spec.ts @@ -21,27 +21,32 @@ describe('ordered interval validator', () => { it('should be valid if "from < to"', () => { form.controls?.['dateFrom']?.setValue(toUtc({month: new Date().getMonth() - 1})); + expect(form.valid).toBe(true); }); it('should be valid if "from = null"', () => { form.controls?.['dateFrom']?.setValue(null); + expect(form.valid).toBe(true); }); it('should be valid if "to = null"', () => { form.controls?.['dateTo']?.setValue(null); + expect(form.valid).toBe(true); }); it('should be valid if "from = null" and "to = null"', () => { form.controls?.['dateFrom']?.setValue(null); form.controls?.['dateTo']?.setValue(null); + expect(form.valid).toBe(true); }); it('should return error if "from > to"', () => { form.controls?.['dateFrom']?.setValue(toUtc({month: new Date().getMonth() + 1})); + expect(form.errors).toEqual({orderedInterval: true}); }); diff --git a/libs/cdk/tests/validators/required-some-value-by-keys-validator.spec.ts b/libs/cdk/tests/validators/required-some-value-by-keys-validator.spec.ts index aaac01d7a..94b262dc4 100644 --- a/libs/cdk/tests/validators/required-some-value-by-keys-validator.spec.ts +++ b/libs/cdk/tests/validators/required-some-value-by-keys-validator.spec.ts @@ -24,9 +24,10 @@ describe('[TEST]: requiredSomeValueByKeysValidator', () => { 'ccc', ]); - expect(() => validator(control))?.toThrow( - new Error('requiredSomeValueByKeys must be used on form group'), - ); + const error = new Error('requiredSomeValueByKeys must be used on form group'); + const testFn = () => validator(control); + + expect(testFn).toThrow(error); }); // noinspection DuplicatedCode @@ -34,6 +35,7 @@ describe('[TEST]: requiredSomeValueByKeysValidator', () => { form.controls?.['aaa']?.setValue(undefined); form.controls?.['bbb']?.setValue(null); form.controls?.['ccc']?.setValue(NaN); + expect(form.errors).toEqual({requiredSomeValueByKeys: true}); }); @@ -41,11 +43,13 @@ describe('[TEST]: requiredSomeValueByKeysValidator', () => { form.controls?.['aaa']?.setValue(''); form.controls?.['bbb']?.setValue(null); form.controls?.['ccc']?.setValue(Infinity); + expect(form.errors).toEqual({requiredSomeValueByKeys: true}); }); it('should return error if all controls with no values: []', () => { form.controls?.['aaa']?.setValue([]); + expect(form.errors).toEqual({requiredSomeValueByKeys: true}); }); @@ -55,16 +59,19 @@ describe('[TEST]: requiredSomeValueByKeysValidator', () => { it('should be valid if there is only one value with type number', () => { form.controls?.['aaa']?.setValue(13); + expect(form.valid).toBe(true); }); it('should be valid if there is only one value with type string', () => { form.controls?.['bbb']?.setValue('awesome'); + expect(form.valid).toBe(true); }); it('should be valid if there is only one value with type Object', () => { form.controls?.['ccc']?.setValue({}); + expect(form.valid).toBe(true); }); @@ -72,11 +79,13 @@ describe('[TEST]: requiredSomeValueByKeysValidator', () => { form.controls?.['aaa']?.setValue(13); form.controls?.['bbb']?.setValue('awesome'); form.controls?.['ccc']?.setValue({}); + expect(form.valid).toBe(true); }); it('should be valid if there is null as a parameter', () => { form = new FormGroup({}, {validators: [requiredSomeValueByKeysValidator()]}); + expect(form.valid).toBe(true); }); @@ -85,6 +94,7 @@ describe('[TEST]: requiredSomeValueByKeysValidator', () => { {}, {validators: [requiredSomeValueByKeysValidator([])]}, ); + expect(form.valid).toBe(true); }); }); @@ -110,6 +120,7 @@ describe('[TEST]: requiredSomeValueByKeysValidator', () => { const control: AbstractControl = form.get('ddd.eee') ?? new FormControl(); control.setValue(1); + expect(form.valid).toBe(true); }); }); @@ -137,6 +148,7 @@ describe('[TEST]: requiredSomeValueByKeysValidator', () => { const control: AbstractControl = form.get('aaa.bbb.ccc') ?? new FormControl(); control.setValue(1); + expect(form.valid).toBe(true); }); }); @@ -165,6 +177,7 @@ describe('[TEST]: requiredSomeValueByKeysValidator', () => { const control: AbstractControl = form.get('aaa.bbb.ccc') ?? new FormControl(); control.setValue(1); + expect(form.valid).toBe(true); }); @@ -173,6 +186,7 @@ describe('[TEST]: requiredSomeValueByKeysValidator', () => { const control: AbstractControl = form.get('ddd') ?? new FormControl(); control.setValue(1); + expect(form.valid).toBe(true); }); @@ -182,12 +196,14 @@ describe('[TEST]: requiredSomeValueByKeysValidator', () => { nested.setValue(2); control.setValue(1); + expect(form.valid).toBe(true); }); it('should be always valid for parent control', () => { form.setValidators(requiredSomeValueByKeysValidator(['aaa'])); form.updateValueAndValidity(); + expect(form.valid).toBe(true); }); }); @@ -212,6 +228,7 @@ describe('[TEST]: requiredSomeValueByKeysValidator', () => { const control: AbstractControl = form.get('ddd.eee') ?? new FormControl(); control.setValue(1); + expect(form.valid).toBe(true); }); }); @@ -240,6 +257,7 @@ describe('[TEST]: requiredSomeValueByKeysValidator', () => { const control: AbstractControl = form.get('aaa.bbb.ccc') ?? new FormControl(); control.setValue(1); + expect(form.valid).toBe(true); }); }); @@ -267,6 +285,7 @@ describe('[TEST]: requiredSomeValueByKeysValidator', () => { const control: AbstractControl = form.get('aaa.bbb.ccc') ?? new FormControl(); control.setValue(1); + expect(form.valid).toBe(true); }); @@ -274,6 +293,7 @@ describe('[TEST]: requiredSomeValueByKeysValidator', () => { const control: AbstractControl = form.get('ddd') ?? new FormControl(); control.setValue(1); + expect(form.valid).toBe(true); }); @@ -283,12 +303,14 @@ describe('[TEST]: requiredSomeValueByKeysValidator', () => { nested.setValue(2); control.setValue(1); + expect(form.valid).toBe(true); }); it('should be always valid for parent control', () => { form.setValidators(requiredSomeValueByKeysValidator(['aaa'])); form.updateValueAndValidity(); + expect(form.valid).toBe(true); }); }); diff --git a/libs/cdk/tests/validators/required-some-value-validator.spec.ts b/libs/cdk/tests/validators/required-some-value-validator.spec.ts index 167a5658f..9e5539540 100644 --- a/libs/cdk/tests/validators/required-some-value-validator.spec.ts +++ b/libs/cdk/tests/validators/required-some-value-validator.spec.ts @@ -19,9 +19,10 @@ describe('[TEST]: requiredSomeValueValidator', () => { const control: AbstractControl = new FormControl(); const validator: ValidatorFn = requiredSomeValueValidator(); - expect(() => validator(control))?.toThrow( - new Error('requiredSomeValue must be used on form group'), - ); + const error = new Error('requiredSomeValue must be used on form group'); + const testFn = () => validator(control); + + expect(testFn).toThrow(error); }); // TODO: refactor duplicate tests @@ -29,6 +30,7 @@ describe('[TEST]: requiredSomeValueValidator', () => { form.controls?.['aaa']?.setValue(undefined); form.controls?.['bbb']?.setValue(null); form.controls?.['ccc']?.setValue(NaN); + expect(form.errors).toEqual({requiredSomeValue: true}); }); @@ -36,11 +38,13 @@ describe('[TEST]: requiredSomeValueValidator', () => { form.controls?.['aaa']?.setValue(''); form.controls?.['bbb']?.setValue(null); form.controls?.['ccc']?.setValue(Infinity); + expect(form.errors).toEqual({requiredSomeValue: true}); }); it('should return error if all controls with no values: []', () => { form.controls?.['aaa']?.setValue([]); + expect(form.errors).toEqual({requiredSomeValue: true}); }); @@ -50,16 +54,19 @@ describe('[TEST]: requiredSomeValueValidator', () => { it('should be valid if there is only one value with type number', () => { form.controls?.['aaa']?.setValue(13); + expect(form.valid).toBe(true); }); it('should be valid if there is only one value with type string', () => { form.controls?.['bbb']?.setValue('awesome'); + expect(form.valid).toBe(true); }); it('should be valid if there is only one value with type Object', () => { form.controls?.['ccc']?.setValue({}); + expect(form.valid).toBe(true); }); @@ -67,6 +74,7 @@ describe('[TEST]: requiredSomeValueValidator', () => { form.controls?.['aaa']?.setValue(13); form.controls?.['bbb']?.setValue('awesome'); form.controls?.['ccc']?.setValue({}); + expect(form.valid).toBe(true); }); }); diff --git a/libs/cdk/tests/websocket/websocket-client.spec.ts b/libs/cdk/tests/websocket/websocket-client.spec.ts index 3b83abf94..9ddaeacdc 100644 --- a/libs/cdk/tests/websocket/websocket-client.spec.ts +++ b/libs/cdk/tests/websocket/websocket-client.spec.ts @@ -75,7 +75,9 @@ describe('[TEST] Websocket client', (): void => { const spyClose: jest.SpyInstance = jest.spyOn(nativeSocket, 'close'); expect(nativeSocket).toBeInstanceOf(WebSocket); + nativeSocket.dispatchEvent(new MessageEvent('open')); + expect(nativeSocket.url).toBe('ws://null/'); // sending legal message @@ -87,20 +89,25 @@ describe('[TEST] Websocket client', (): void => { }), }), ); + expect(observer.mock.calls).toEqual([['some_data']]); expect(spyReconnect).toHaveBeenCalledTimes(0); expect(spyClose).toHaveBeenCalledTimes(0); // sending breaking message nativeSocket.dispatchEvent(new MessageEvent('message', {data: 'some_data'})); + expect(observer.mock.calls).toEqual([['some_data']]); expect(spyReconnect).toHaveBeenCalledTimes(1); expect(spyClose).toHaveBeenCalledTimes(1); // checking if there is a new connection expect((client as any).socket$._socket).not.toBe(nativeSocket); + nativeSocket = (client as any).socket$._socket; + expect(nativeSocket).toBeInstanceOf(WebSocket); + nativeSocket.dispatchEvent(new MessageEvent('open')); // sending legal message again @@ -112,6 +119,7 @@ describe('[TEST] Websocket client', (): void => { }), }), ); + expect(observer.mock.calls).toEqual([['some_data'], ['some_another_data']]); expect(spyReconnect).toHaveBeenCalledTimes(1); expect(spyClose).toHaveBeenCalledTimes(1); @@ -140,8 +148,11 @@ describe('[TEST] Websocket client', (): void => { }); expect(nativeSocket).toBeInstanceOf(WebSocket); + nativeSocket.dispatchEvent(new MessageEvent('open')); + expect(nativeSocket.url).toBe('ws://null/'); + Object.defineProperty(nativeSocket, 'readyState', {value: 1}); // sending json message @@ -151,12 +162,14 @@ describe('[TEST] Websocket client', (): void => { }); nativeSocket.dispatchEvent(new MessageEvent('message', {data: jsonData})); + expect(messageObserver.mock.calls).toEqual([['some_data']]); expect(spyReconnect).toHaveBeenCalledTimes(0); expect(spyClose).toHaveBeenCalledTimes(0); // sending plain message nativeSocket.dispatchEvent(new MessageEvent('message', {data: 'some_data'})); + expect(plainTextObserver.mock.calls).toEqual([['some_data']]); expect(spyReconnect).toHaveBeenCalledTimes(0); expect(spyClose).toHaveBeenCalledTimes(0); @@ -165,6 +178,7 @@ describe('[TEST] Websocket client', (): void => { const binaryData = new ArrayBuffer(1); nativeSocket.dispatchEvent(new MessageEvent('message', {data: binaryData})); + expect(binaryObserver.mock.calls[0][0]).toEqual(binaryData); expect(spyReconnect).toHaveBeenCalledTimes(0); expect(spyClose).toHaveBeenCalledTimes(0); @@ -172,12 +186,15 @@ describe('[TEST] Websocket client', (): void => { const message = {type: 'outgoing', data: 'message'}; client.sendMessage(message.type, message.data); + expect(spySend.mock.calls).toEqual([[JSON.stringify(message)]]); client.sendMessage(PLAIN_TEXT, 'message'); + expect(spySend.mock.calls).toEqual([[JSON.stringify(message)], ['message']]); client.sendMessage(BINARY, binaryData); + expect(spySend.mock.calls[2][0]).toEqual(binaryData); }); }); diff --git a/libs/ngxs/CHANGELOG.md b/libs/ngxs/CHANGELOG.md index 4367333de..291ecf96a 100644 --- a/libs/ngxs/CHANGELOG.md +++ b/libs/ngxs/CHANGELOG.md @@ -6,9 +6,11 @@ All notable changes to this project will be documented in this file. See ## [19.0.0](https://github.com/Angular-RU/angular-ru-sdk/compare/v18.11.0...v19.0.0) (2025-09-01) ### Features - -* angular v20 and NX v21 ([1aa382d](https://github.com/Angular-RU/angular-ru-sdk/commit/1aa382d505962c260c6f8a871bdb7d58d2b8b1cb)) -* standalone components and pipes; root providers instead of forRoot(); removal of ngModules ([729959c](https://github.com/Angular-RU/angular-ru-sdk/commit/729959c201623ffc4406d680d46908059d9a5754)) + +- angular v20 and NX v21 + ([1aa382d](https://github.com/Angular-RU/angular-ru-sdk/commit/1aa382d505962c260c6f8a871bdb7d58d2b8b1cb)) +- standalone components and pipes; root providers instead of forRoot(); removal of ngModules + ([729959c](https://github.com/Angular-RU/angular-ru-sdk/commit/729959c201623ffc4406d680d46908059d9a5754)) ## [14.2.2](https://github.com/Angular-RU/angular-ru-sdk/compare/@angular-ru/ngxs@14.2.1...@angular-ru/ngxs@14.2.2) (2023-10-21) diff --git a/libs/ngxs/tests/entity/primary-key-or-unique-id.spec.ts b/libs/ngxs/tests/entity/primary-key-or-unique-id.spec.ts index 23b10ce73..947ed2692 100644 --- a/libs/ngxs/tests/entity/primary-key-or-unique-id.spec.ts +++ b/libs/ngxs/tests/entity/primary-key-or-unique-id.spec.ts @@ -60,6 +60,7 @@ describe('[TEST]: Entity - primary key or unique id', () => { }); lesson.set(createEntityCollections()); + expect(lesson.getState()).toEqual({ids: [], entities: {}}); // eslint-disable-next-line rxjs/no-ignored-observable @@ -147,6 +148,7 @@ describe('[TEST]: Entity - primary key or unique id', () => { expect(lesson.getState()).toEqual({ids: [], entities: {}}); lesson.updateOne({id: 1, changes: {lessonId: 1, title: 'A'}}); + expect(lesson.getState()).toEqual({ids: [], entities: {}}); lesson.upsertMany([ @@ -383,6 +385,7 @@ describe('[TEST]: Entity - primary key or unique id', () => { ]); studentEntities.removeByEntity(entity); + expect(studentEntities.selectAll()).toEqual([]); expect(idEvents).toEqual([ diff --git a/libs/ngxs/tests/entity/sort-by.spec.ts b/libs/ngxs/tests/entity/sort-by.spec.ts index b3dc66a5e..48b6c0aa5 100644 --- a/libs/ngxs/tests/entity/sort-by.spec.ts +++ b/libs/ngxs/tests/entity/sort-by.spec.ts @@ -50,6 +50,7 @@ describe('sort by entities', () => { }); people.sort(); + expect(spy).toHaveBeenCalledTimes(1); expect(console.warn).toHaveBeenLastCalledWith( diff --git a/libs/ngxs/tests/testing/testing-v2.spec.ts b/libs/ngxs/tests/testing/testing-v2.spec.ts index faf7adb1b..51556bcf0 100644 --- a/libs/ngxs/tests/testing/testing-v2.spec.ts +++ b/libs/ngxs/tests/testing/testing-v2.spec.ts @@ -113,6 +113,7 @@ describe('[TEST]: Abstract ngxs data repository', () => { expect(a.name).toBe('a'); a.setState({value: 2}); + expect(a.getState()).toStrictEqual({value: 2}); a.initialState.value = 5; // not affected @@ -172,6 +173,7 @@ describe('[TEST]: Abstract ngxs data repository', () => { expect(b.name).toBe('b'); b.setState({value: 2}); + expect(b.getState()).toEqual({value: 2}); (b.initialState as any).value = 5; // not affected