diff --git a/projects/addon-charts/components/line-chart/line-chart.component.ts b/projects/addon-charts/components/line-chart/line-chart.component.ts index 5713ca19605cc..92d238acef37f 100644 --- a/projects/addon-charts/components/line-chart/line-chart.component.ts +++ b/projects/addon-charts/components/line-chart/line-chart.component.ts @@ -11,9 +11,9 @@ import { import {TuiLineChartHintContext} from '@taiga-ui/addon-charts/interfaces'; import {draw} from '@taiga-ui/addon-charts/utils'; import { - inRange, tuiDefaultProp, TuiIdService, + tuiInRange, tuiPure, TuiStringHandler, tuiZoneOptimized, @@ -27,7 +27,7 @@ import {TuiLineChartHintDirective} from './line-chart-hint.directive'; // eslint-disable-next-line @typescript-eslint/naming-convention export function smoothingAssertion(smoothingFactor: number): boolean { - return inRange(smoothingFactor, 0, 100); + return tuiInRange(smoothingFactor, 0, 100); } const SMOOTHING_MESSAGE = `smoothingFactor must be between 0 and 100`; diff --git a/projects/addon-editor/components/toolbar-new/toolbar-navigation-manager.directive.ts b/projects/addon-editor/components/toolbar-new/toolbar-navigation-manager.directive.ts index b6219b1c11ac0..73275bf3d74d7 100644 --- a/projects/addon-editor/components/toolbar-new/toolbar-navigation-manager.directive.ts +++ b/projects/addon-editor/components/toolbar-new/toolbar-navigation-manager.directive.ts @@ -1,10 +1,10 @@ import {Directive, ElementRef, HostListener, Inject} from '@angular/core'; import { clamp, - getClosestFocusable, - isNativeMouseFocusable, setNativeFocused, + tuiGetClosestFocusable, tuiIsNativeFocusedIn, + tuiIsNativeMouseFocusable, TuiNativeFocusableElement, } from '@taiga-ui/cdk'; @@ -49,9 +49,9 @@ export class TuiToolbarNavigationManagerDirective { : this.toolsContainers; for (const el of tools) { - const focusableElement = isNativeMouseFocusable(el) + const focusableElement = tuiIsNativeMouseFocusable(el) ? el - : getClosestFocusable(el, false, el, false); + : tuiGetClosestFocusable(el, false, el, false); if (focusableElement) { return focusableElement; @@ -62,21 +62,26 @@ export class TuiToolbarNavigationManagerDirective { } private findPreviousTool(wrapper: HTMLElement): HTMLElement | null { - if (isNativeMouseFocusable(wrapper)) { + if (tuiIsNativeMouseFocusable(wrapper)) { return wrapper; } - const lookedInside = getClosestFocusable(wrapper, false, wrapper, false); + const lookedInside = tuiGetClosestFocusable(wrapper, false, wrapper, false); return ( lookedInside || - getClosestFocusable(wrapper, true, this.elementRef.nativeElement, false) + tuiGetClosestFocusable(wrapper, true, this.elementRef.nativeElement, false) ); } private findNextTool(wrapper: HTMLElement): HTMLElement | null { - return isNativeMouseFocusable(wrapper) + return tuiIsNativeMouseFocusable(wrapper) ? wrapper - : getClosestFocusable(wrapper, false, this.elementRef.nativeElement, false); + : tuiGetClosestFocusable( + wrapper, + false, + this.elementRef.nativeElement, + false, + ); } } diff --git a/projects/addon-editor/directives/design-mode/design-mode.directive.ts b/projects/addon-editor/directives/design-mode/design-mode.directive.ts index ddde30465f75b..859ddc3ad50df 100644 --- a/projects/addon-editor/directives/design-mode/design-mode.directive.ts +++ b/projects/addon-editor/directives/design-mode/design-mode.directive.ts @@ -21,7 +21,6 @@ import {tuiInsertHtml} from '@taiga-ui/addon-editor/utils'; import { EMPTY_FUNCTION, getClipboardDataText, - getClosestFocusable, preventDefault, setNativeFocused, TUI_FOCUSABLE_ITEM_ACCESSOR, @@ -29,6 +28,7 @@ import { TuiDestroyService, TuiEventWith, TuiFocusableElementAccessor, + tuiGetClosestFocusable, TuiHandler, tuiIsNativeFocused, tuiRequiredSetter, @@ -219,7 +219,7 @@ export class TuiDesignModeDirective event.preventDefault(); - const element = getClosestFocusable( + const element = tuiGetClosestFocusable( this.elementRef.nativeElement, event.shiftKey, this.elementRef.nativeElement.ownerDocument.body, diff --git a/projects/addon-mobile/components/sheet/sheet-options.ts b/projects/addon-mobile/components/sheet/sheet-options.ts index e9b11971d8fe2..0b76ece93af93 100644 --- a/projects/addon-mobile/components/sheet/sheet-options.ts +++ b/projects/addon-mobile/components/sheet/sheet-options.ts @@ -1,8 +1,7 @@ -import {inject, InjectionToken} from '@angular/core'; +import {InjectionToken} from '@angular/core'; import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus'; import {TuiSheet} from './sheet'; -import {TUI_SHEET_OFFSET} from './sheet-tokens'; export interface TuiSheetOptions { readonly image: PolymorpheusContent>; @@ -28,6 +27,6 @@ export const TUI_SHEET_DEFAULT_OPTIONS: Omit = { export const TUI_SHEET_OPTIONS = new InjectionToken>( `Default parameters for sheet component`, { - factory: () => ({...TUI_SHEET_DEFAULT_OPTIONS, offset: inject(TUI_SHEET_OFFSET)}), + factory: () => ({...TUI_SHEET_DEFAULT_OPTIONS}), }, ); diff --git a/projects/addon-mobile/components/sheet/sheet-tokens.ts b/projects/addon-mobile/components/sheet/sheet-tokens.ts index dc6a0c6c4fdc4..8f6c539a12c14 100644 --- a/projects/addon-mobile/components/sheet/sheet-tokens.ts +++ b/projects/addon-mobile/components/sheet/sheet-tokens.ts @@ -13,11 +13,3 @@ export const TUI_SHEET_SCROLL = new InjectionToken( export const TUI_SHEET_DRAGGED = new InjectionToken( 'The sheet is being dragged', ); - -/** @deprecated use option argument for each Sheet */ -export const TUI_SHEET_OFFSET = new InjectionToken( - 'Offset from the top at which the sheet stops', - { - factory: () => 16, - }, -); diff --git a/projects/addon-mobile/directives/touchable/touchable.directive.ts b/projects/addon-mobile/directives/touchable/touchable.directive.ts index bdcea3ab07fc0..4c4055f2227ee 100644 --- a/projects/addon-mobile/directives/touchable/touchable.directive.ts +++ b/projects/addon-mobile/directives/touchable/touchable.directive.ts @@ -1,6 +1,6 @@ import {Directive, ElementRef, Inject, Input, Optional, Renderer2} from '@angular/core'; import {TuiTouchMode} from '@taiga-ui/addon-mobile/types'; -import {findTouchIndex} from '@taiga-ui/addon-mobile/utils'; +import {tuiFindTouchIndex} from '@taiga-ui/addon-mobile/utils'; import { TUI_IS_IOS, tuiDefaultProp, @@ -74,7 +74,7 @@ export class TuiTouchableDirective { identifier: number, ): boolean { const {ownerDocument} = element; - const id = findTouchIndex(touches, identifier); + const id = tuiFindTouchIndex(touches, identifier); if (!ownerDocument || id === -1) { return true; diff --git a/projects/addon-mobile/utils/find-touch-index.ts b/projects/addon-mobile/utils/find-touch-index.ts index d4c48be638543..c416e1354372a 100644 --- a/projects/addon-mobile/utils/find-touch-index.ts +++ b/projects/addon-mobile/utils/find-touch-index.ts @@ -1,8 +1,4 @@ -/** - * @deprecated: use {@link tuiFindTouchIndex} instead - */ -// eslint-disable-next-line @typescript-eslint/naming-convention -export function findTouchIndex(touches: TouchList, id: number): number { +export function tuiFindTouchIndex(touches: TouchList, id: number): number { for (let i = 0; i < touches.length; i++) { const {identifier} = touches[i]; @@ -13,5 +9,3 @@ export function findTouchIndex(touches: TouchList, id: number): number { return -1; } - -export const tuiFindTouchIndex = findTouchIndex; diff --git a/projects/cdk/constants/empty.ts b/projects/cdk/constants/empty.ts index daf2f079081ed..3e167eebb1794 100644 --- a/projects/cdk/constants/empty.ts +++ b/projects/cdk/constants/empty.ts @@ -1,5 +1,4 @@ import {QueryList} from '@angular/core'; -import {ValidatorFn} from '@angular/forms'; /** * For type safety when using @ContentChildren and @ViewChildren @@ -9,8 +8,6 @@ import {ValidatorFn} from '@angular/forms'; export const EMPTY_QUERY = new QueryList(); export const EMPTY_ARRAY: [] = []; export const EMPTY_FUNCTION: (...args: any[]) => void = () => {}; -/** @deprecated use Validators.nullValidator */ -export const EMPTY_VALIDATOR: ValidatorFn = () => null; export const EMPTY_CLIENT_RECT: ClientRect = { bottom: 0, height: 0, diff --git a/projects/cdk/constants/test/handler.spec.ts b/projects/cdk/constants/test/handler.spec.ts index 7196f8b6f9716..607da9b78b4d4 100644 --- a/projects/cdk/constants/test/handler.spec.ts +++ b/projects/cdk/constants/test/handler.spec.ts @@ -1,19 +1,12 @@ -import {AbstractControl} from '@angular/forms'; - import {ALWAYS_FALSE_HANDLER} from '../always-false-handler'; import {ALWAYS_TRUE_HANDLER} from '../always-true-handler'; -import {EMPTY_VALIDATOR} from '../empty'; -describe(`Handler functions`, () => { - it(`Always false`, () => { +describe('Handler functions', () => { + it('Always false', () => { expect(ALWAYS_FALSE_HANDLER()).toBe(false); }); - it(`Always true`, () => { + it('Always true', () => { expect(ALWAYS_TRUE_HANDLER()).toBe(true); }); - - it(`EMPTY_VALIDATOR`, () => { - expect(EMPTY_VALIDATOR({} as unknown as AbstractControl)).toBe(null); - }); }); diff --git a/projects/cdk/date-time/date-fillers.ts b/projects/cdk/date-time/date-fillers.ts index aa5824b294d06..f5ccb7c5a0e3d 100644 --- a/projects/cdk/date-time/date-fillers.ts +++ b/projects/cdk/date-time/date-fillers.ts @@ -1,28 +1,5 @@ -import {inject, InjectionToken} from '@angular/core'; - import {RANGE_SEPARATOR_CHAR} from './date-time'; -/** - * @deprecated dont use it. See {@link TUI_DATE_FORMAT} - */ -export const TUI_DATE_FILLER = new InjectionToken(`date filler for Taiga UI`, { - factory: () => `dd.mm.yyyy`, -}); - -/** - * @deprecated dont use it - */ -export const TUI_DATE_RANGE_FILLER = new InjectionToken( - `date range filler for Taiga UI`, - { - factory: () => { - const dateFiller = inject(TUI_DATE_FILLER); - - return `${dateFiller}${RANGE_SEPARATOR_CHAR}${dateFiller}`; - }, - }, -); - /** * @internal 'dd.mm.yyyy'.length * Used in: diff --git a/projects/cdk/date-time/day-range.ts b/projects/cdk/date-time/day-range.ts index da5e44ee1916e..9eb0e78abece0 100644 --- a/projects/cdk/date-time/day-range.ts +++ b/projects/cdk/date-time/day-range.ts @@ -11,7 +11,7 @@ import {TuiMonthRange} from './month-range'; * @deprecated */ export const isDateMode = (dateMode: string): dateMode is TuiDateMode => - [`DMY`, `YMD`, `MDY`].includes(dateMode); + ['DMY', 'YMD', 'MDY'].includes(dateMode); /** * An immutable range of two {@link TuiDay} objects @@ -36,16 +36,6 @@ export class TuiDayRange extends TuiMonthRange { : new TuiDayRange(day2, day1); } - /** - * @deprecated - */ - static normalizeParse( - rangeString: string, - dateFiller: string, - dateRangeFiller: string, - ): TuiDayRange; - static normalizeParse(rangeString: string, dateMode?: TuiDateMode): TuiDayRange; - /** * Parse and correct a day range in string format * @@ -55,13 +45,11 @@ export class TuiDayRange extends TuiMonthRange { */ static normalizeParse( rangeString: string, - dateMode: string | TuiDateMode = `DMY`, + dateMode: TuiDateMode = 'DMY', ): TuiDayRange { - const dateFormat = isDateMode(dateMode) ? dateMode : `DMY`; - const leftDay = TuiDay.normalizeParse( rangeString.slice(0, DATE_FILLER_LENGTH), - dateFormat, + dateMode, ); if (rangeString.length < DATE_RANGE_FILLER_LENGTH) { @@ -72,7 +60,7 @@ export class TuiDayRange extends TuiMonthRange { leftDay, TuiDay.normalizeParse( rangeString.slice(DATE_FILLER_LENGTH + RANGE_SEPARATOR_CHAR.length), - dateFormat, + dateMode, ), ); } @@ -81,17 +69,6 @@ export class TuiDayRange extends TuiMonthRange { return this.from.daySame(this.to); } - /** - * Human readable format. - * @deprecated use {@link getFormattedDayRange} instead - */ - get formattedDayRange(): string { - const from = this.from.getFormattedDay(`DMY`, `.`); - const to = this.to.getFormattedDay(`DMY`, `.`); - - return `${from}${RANGE_SEPARATOR_CHAR}${to}`; - } - /** * Tests ranges for identity * @@ -123,7 +100,7 @@ export class TuiDayRange extends TuiMonthRange { return `${from}${RANGE_SEPARATOR_CHAR}${to}`; } - toString(dateFormat: TuiDateMode = `DMY`, dateSeparator: string = `.`): string { + toString(dateFormat: TuiDateMode = 'DMY', dateSeparator: string = '.'): string { const from = this.from.getFormattedDay(dateFormat, dateSeparator); const to = this.to.getFormattedDay(dateFormat, dateSeparator); diff --git a/projects/cdk/date-time/day.ts b/projects/cdk/date-time/day.ts index be46106c24c56..2640bcbdb8a0d 100644 --- a/projects/cdk/date-time/day.ts +++ b/projects/cdk/date-time/day.ts @@ -1,16 +1,16 @@ import {tuiAssert} from '@taiga-ui/cdk/classes'; import {TuiDayOfWeek, TuiMonthNumber} from '@taiga-ui/cdk/enums'; import { - InvalidDayException, - InvalidMonthException, - InvalidYearException, + TuiInvalidDayException, + TuiInvalidMonthException, + TuiInvalidYearException, } from '@taiga-ui/cdk/exceptions'; import {TuiDayLike} from '@taiga-ui/cdk/interfaces'; import {TuiDateMode} from '@taiga-ui/cdk/types'; -import {inRange, normalizeToIntNumber} from '@taiga-ui/cdk/utils/math'; +import {tuiInRange, tuiNormalizeToIntNumber} from '@taiga-ui/cdk/utils/math'; import {DATE_FILLER_LENGTH} from './date-fillers'; -import {DAYS_IN_WEEK, MIN_DAY, MONTHS_IN_YEAR} from './date-time'; +import {MIN_DAY, MONTHS_IN_YEAR} from './date-time'; import {TuiMonth} from './month'; import {TuiYear} from './year'; @@ -50,7 +50,7 @@ export class TuiDay extends TuiMonth { return ( TuiMonth.isValidMonth(year, month) && Number.isInteger(day) && - inRange( + tuiInRange( day, MIN_DAY, TuiMonth.getMonthDaysCount(month, TuiYear.isLeapYear(year)) + 1, @@ -58,37 +58,6 @@ export class TuiDay extends TuiMonth { ); } - /** - * @deprecated DONT USE IT (will be deleted soon) - * - * Calculated day on a calendar grid - * - * @param month - * @param row row in a calendar - * @param col column in a calendar - * @return resulting day on these coordinates (could exceed passed month) - */ - static getDayFromMonthRowCol(month: TuiMonth, row: number, col: number): TuiDay { - tuiAssert.assert(Number.isInteger(row)); - tuiAssert.assert(inRange(row, 0, 6)); - tuiAssert.assert(Number.isInteger(col)); - tuiAssert.assert(inRange(col, 0, DAYS_IN_WEEK)); - - let day = row * DAYS_IN_WEEK + col - month.monthStartDaysOffset + 1; - - if (day > month.daysCount) { - day = day - month.daysCount; - month = month.append({month: 1}); - } - - if (day <= 0) { - month = month.append({month: -1}); - day = month.daysCount + day; - } - - return new TuiDay(month.year, month.month, day); - } - /** * Current day based on local time zone */ @@ -198,22 +167,22 @@ export class TuiDay extends TuiMonth { const {day, month, year} = this.parseRawDateString(yearMonthDayString, 'YMD'); if (!TuiYear.isValidYear(year)) { - throw new InvalidYearException(year); + throw new TuiInvalidYearException(year); } if (!TuiMonth.isValidMonth(year, month)) { - throw new InvalidMonthException(month); + throw new TuiInvalidMonthException(month); } if ( !Number.isInteger(day) || - !inRange( + !tuiInRange( day, MIN_DAY, TuiMonth.getMonthDaysCount(month, TuiYear.isLeapYear(year)) + 1, ) ) { - throw new InvalidDayException(day); + throw new TuiInvalidDayException(day); } return new TuiDay(year, month, day); @@ -227,21 +196,13 @@ export class TuiDay extends TuiMonth { TuiYear.isLeapYear(year), ); - return normalizeToIntNumber(day, 1, monthDaysCount); + return tuiNormalizeToIntNumber(day, 1, monthDaysCount); } get formattedDayPart(): string { return String(this.day).padStart(2, '0'); } - /** - * @deprecated use {@link getFormattedDay} instead - * Formatted whole date - */ - get formattedDay(): string { - return `${this.formattedDayPart}.${this.formattedMonth}`; - } - get isWeekend(): boolean { const dayOfWeek = this.dayOfWeek(false); diff --git a/projects/cdk/date-time/month-range.ts b/projects/cdk/date-time/month-range.ts index 87b1a22ac1692..c45c0e738e773 100644 --- a/projects/cdk/date-time/month-range.ts +++ b/projects/cdk/date-time/month-range.ts @@ -21,13 +21,6 @@ export class TuiMonthRange { return this.from.monthSame(this.to); } - /** - * @deprecated - */ - get formattedMonthRange(): string { - return `${this.from.formattedMonth}${RANGE_SEPARATOR_CHAR}${this.to.formattedMonth}`; - } - monthSame(another: TuiMonthRange): boolean { return this.from.monthSame(another.from) && this.to.monthSame(another.to); } diff --git a/projects/cdk/date-time/month.ts b/projects/cdk/date-time/month.ts index a9c25f6e5685a..a6c95da50830e 100644 --- a/projects/cdk/date-time/month.ts +++ b/projects/cdk/date-time/month.ts @@ -1,9 +1,9 @@ import {tuiAssert} from '@taiga-ui/cdk/classes'; import {TuiMonthNumber} from '@taiga-ui/cdk/enums'; import {TuiMonthLike} from '@taiga-ui/cdk/interfaces'; -import {inRange, normalizeToIntNumber} from '@taiga-ui/cdk/utils/math'; +import {tuiInRange, tuiNormalizeToIntNumber} from '@taiga-ui/cdk/utils/math'; -import {DAYS_IN_WEEK, MAX_MONTH, MIN_MONTH, MONTHS_IN_YEAR} from './date-time'; +import {MAX_MONTH, MIN_MONTH, MONTHS_IN_YEAR} from './date-time'; import {TuiYear} from './year'; /** @@ -75,37 +75,20 @@ export class TuiMonth extends TuiYear implements TuiMonthLike { * Normalizes number by clamping it between min and max month */ protected static normalizeMonthPart(month: number): number { - return normalizeToIntNumber(month, MIN_MONTH, MAX_MONTH); + return tuiNormalizeToIntNumber(month, MIN_MONTH, MAX_MONTH); } /** * Tests month for validity */ private static isValidMonthPart(month: number): boolean { - return Number.isInteger(month) && inRange(month, MIN_MONTH, MAX_MONTH + 1); + return Number.isInteger(month) && tuiInRange(month, MIN_MONTH, MAX_MONTH + 1); } get formattedMonthPart(): string { return String(this.month + 1).padStart(2, '0'); } - /** - * @deprecated - * Formatter month and year - */ - get formattedMonth(): string { - return `${this.formattedMonthPart}.${this.formattedYear}`; - } - - /** - * @deprecated DONT USE IT (will be deleted soon) - * - * Calculates number of weeks in a month (counting non-full weeks) - */ - get weeksRowsCount(): number { - return Math.ceil((this.monthStartDaysOffset + this.daysCount) / DAYS_IN_WEEK); - } - /** * Returns days in a month */ @@ -113,21 +96,6 @@ export class TuiMonth extends TuiYear implements TuiMonthLike { return TuiMonth.getMonthDaysCount(this.month, this.isLeapYear); } - /** - * @deprecated DONT USE IT (will be deleted soon) - * - * Computes day of week offset of the beginning of the month - */ - get monthStartDaysOffset(): number { - let result = this.yearStartDaysOffset; - - for (let currentMonth = 0; currentMonth <= this.month - 1; currentMonth++) { - result += TuiMonth.getMonthDaysCount(currentMonth, this.isLeapYear); - } - - return result % DAYS_IN_WEEK; - } - /** * Passed month and year are after current */ @@ -198,7 +166,7 @@ export class TuiMonth extends TuiYear implements TuiMonthLike { } toString(): string { - return this.formattedMonth; + return `${this.formattedMonthPart}.${this.formattedYear}`; } valueOf(): number { diff --git a/projects/cdk/date-time/test/date-fillers.spec.ts b/projects/cdk/date-time/test/date-fillers.spec.ts deleted file mode 100644 index fb1e93cbf144c..0000000000000 --- a/projects/cdk/date-time/test/date-fillers.spec.ts +++ /dev/null @@ -1,22 +0,0 @@ -import {TestBed} from '@angular/core/testing'; - -import {TUI_DATE_FILLER, TUI_DATE_RANGE_FILLER} from '../date-fillers'; -import {RANGE_SEPARATOR_CHAR} from '../date-time'; - -describe(`Date Fillers`, () => { - it(`TUI_DATE_FILLER is a global token with default value`, () => { - TestBed.configureTestingModule({}); - - const result = TestBed.inject(TUI_DATE_FILLER); - - expect(result).toBe(`dd.mm.yyyy`); - }); - - it(`TUI_DATE_RANGE_FILLER is a global token with default value`, () => { - TestBed.configureTestingModule({}); - - const result = TestBed.inject(TUI_DATE_RANGE_FILLER); - - expect(result).toBe(`dd.mm.yyyy${RANGE_SEPARATOR_CHAR}dd.mm.yyyy`); - }); -}); diff --git a/projects/cdk/date-time/test/day.spec.ts b/projects/cdk/date-time/test/day.spec.ts index c8e4bbc81ac65..4987bdd2d7634 100644 --- a/projects/cdk/date-time/test/day.spec.ts +++ b/projects/cdk/date-time/test/day.spec.ts @@ -1,66 +1,65 @@ import {TuiDay} from '../day'; -import {TuiMonth} from '../month'; -import {mockDateInside, pendingIfNotMoscowTimeZone} from './helpers'; - -describe(`TuiDay`, () => { - describe(`static method`, () => { - describe(`isValidDay returns`, () => { - describe(`false if invalid date is passed`, () => { - it(`NaN`, () => { +import {tuiMockDateInside, tuiPendingIfNotMoscowTimeZone} from './helpers'; + +describe('TuiDay', () => { + describe('static method', () => { + describe('isValidDay returns', () => { + describe('false if invalid date is passed', () => { + it('NaN', () => { expect(TuiDay.isValidDay(2000, 6, NaN)).toBe(false); }); - it(`6.1`, () => { + it('6.1', () => { expect(TuiDay.isValidDay(2000, 6, 6.1)).toBe(false); }); - it(`-20`, () => { + it('-20', () => { expect(TuiDay.isValidDay(2000, 6, -20)).toBe(false); }); - it(`100000`, () => { + it('100000', () => { expect(TuiDay.isValidDay(2000, 6, 100000)).toBe(false); }); - it(`2001.02.29`, () => { + it('2001.02.29', () => { expect(TuiDay.isValidDay(2001, 1, 29)).toBe(false); }); }); - describe(`true if valid day is passed`, () => { - it(`10`, () => { + describe('true if valid day is passed', () => { + it('10', () => { expect(TuiDay.isValidDay(2000, 6, 10)).toBe(true); }); - it(`9`, () => { + it('9', () => { expect(TuiDay.isValidDay(2000, 6, 9)).toBe(true); }); - it(`1`, () => { + it('1', () => { expect(TuiDay.isValidDay(2000, 6, 1)).toBe(true); }); - it(`11`, () => { + it('11', () => { expect(TuiDay.isValidDay(2000, 6, 11)).toBe(true); }); - it(`30`, () => { + it('30', () => { expect(TuiDay.isValidDay(2000, 6, 30)).toBe(true); }); - it(`2000.02.29`, () => { + it('2000.02.29', () => { expect(TuiDay.isValidDay(2000, 1, 29)).toBe(true); }); }); }); - describe(`currentLocal returns date`, () => { + describe('currentLocal returns date', () => { beforeEach(() => { - pendingIfNotMoscowTimeZone(); + tuiPendingIfNotMoscowTimeZone(); }); - it(`same as UTC if UTC is the local time zone`, () => { - mockDateInside(Date.UTC(2000, 0, 15, 10), () => { + it('same as UTC if UTC is the local time zone', () => { + tuiMockDateInside(Date.UTC(2000, 0, 15, 10), () => { const currentDate = TuiDay.currentLocal(); expect(currentDate.year).toBe(2000); @@ -69,8 +68,8 @@ describe(`TuiDay`, () => { }); }); - it(`later than UTC if UTC day is earlier than local time zone`, () => { - mockDateInside(Date.UTC(2000, 0, 15, 23), () => { + it('later than UTC if UTC day is earlier than local time zone', () => { + tuiMockDateInside(Date.UTC(2000, 0, 15, 23), () => { const currentDate = TuiDay.currentLocal(); expect(currentDate.year).toBe(2000); @@ -80,13 +79,13 @@ describe(`TuiDay`, () => { }); }); - describe(`currentUtc returns date`, () => { + describe('currentUtc returns date', () => { beforeEach(() => { - pendingIfNotMoscowTimeZone(); + tuiPendingIfNotMoscowTimeZone(); }); - it(`UTC is the same as local`, () => { - mockDateInside(new Date(2000, 0, 31, 10), () => { + it('UTC is the same as local', () => { + tuiMockDateInside(new Date(2000, 0, 31, 10), () => { const currentDate = TuiDay.currentUtc(); expect(currentDate.year).toBe(2000); @@ -95,8 +94,8 @@ describe(`TuiDay`, () => { }); }); - it(`UTC is smaller than local`, () => { - mockDateInside(new Date(2000, 0, 1, 2), () => { + it('UTC is smaller than local', () => { + tuiMockDateInside(new Date(2000, 0, 1, 2), () => { const currentDate = TuiDay.currentUtc(); expect(currentDate.year).toBe(1999); @@ -106,240 +105,152 @@ describe(`TuiDay`, () => { }); }); - describe(`getDayFromMonthRowCol returns`, () => { - describe(`day from adjacent month if these coordinates are outside current month`, () => { - describe(`2016.03`, () => { - let y2016m2: TuiMonth; - - beforeEach(() => { - y2016m2 = new TuiMonth(2016, 2); - }); - - it(`row 0 col 0`, () => { - expect(TuiDay.getDayFromMonthRowCol(y2016m2, 0, 0)).toEqual( - new TuiDay(2016, 1, 29), - ); - }); - - it(`row 4 col 6`, () => { - expect(TuiDay.getDayFromMonthRowCol(y2016m2, 4, 6)).toEqual( - new TuiDay(2016, 3, 3), - ); - }); - - it(`row 5 col 0`, () => { - expect(TuiDay.getDayFromMonthRowCol(y2016m2, 5, 0)).toEqual( - new TuiDay(2016, 3, 4), - ); - }); - }); - - describe(`1995.01`, () => { - let y1995m0: TuiMonth; - - beforeEach(() => { - y1995m0 = new TuiMonth(1995, 0); - }); - - it(`row 0 col 5`, () => { - expect(TuiDay.getDayFromMonthRowCol(y1995m0, 0, 5)).toEqual( - new TuiDay(1994, 11, 31), - ); - }); - - it(`row 5 col 2`, () => { - expect(TuiDay.getDayFromMonthRowCol(y1995m0, 5, 2)).toEqual( - new TuiDay(1995, 1, 1), - ); - }); - }); - }); - - describe(`day by coordinates`, () => { - describe(`for 2018.03 and`, () => { - let y2018m2: TuiMonth; - - beforeEach(() => { - y2018m2 = new TuiMonth(2018, 2); - }); - - it(`row 0 col 3 === 1`, () => { - expect(TuiDay.getDayFromMonthRowCol(y2018m2, 0, 3).day).toBe(1); - }); - - it(`row 3 col 2 === 21`, () => { - expect(TuiDay.getDayFromMonthRowCol(y2018m2, 3, 2).day).toBe(21); - }); - - it(`row 4 col 4 === 30`, () => { - expect(TuiDay.getDayFromMonthRowCol(y2018m2, 4, 4).day).toBe(30); - }); - }); - - describe(`for 1995.01 and`, () => { - let y1995m0: TuiMonth; - - beforeEach(() => { - y1995m0 = new TuiMonth(1995, 0); - }); - - it(`row 1 col 1 === 3`, () => { - expect(TuiDay.getDayFromMonthRowCol(y1995m0, 1, 1).day).toBe(3); - }); - - it(`row 5 col 1 === 31`, () => { - expect(TuiDay.getDayFromMonthRowCol(y1995m0, 5, 1).day).toBe(31); - }); - }); - }); - }); - - describe(`normalizeOf returns`, () => { - describe(`minimal value for`, () => { - describe(`year if it`, () => { - it(`is NaN`, () => { + describe('normalizeOf returns', () => { + describe('minimal value for', () => { + describe('year if it', () => { + it('is NaN', () => { expect(TuiDay.normalizeOf(NaN, 1, 1).year).toBe(0); }); - it(`equals to minimal`, () => { + it('equals to minimal', () => { expect(TuiDay.normalizeOf(0, 1, 1).year).toBe(0); }); - it(`is smaller than minimal`, () => { + it('is smaller than minimal', () => { expect(TuiDay.normalizeOf(-8, 1, 1).year).toBe(0); }); }); - describe(`month if it`, () => { - it(`is NaN`, () => { + describe('month if it', () => { + it('is NaN', () => { expect(TuiDay.normalizeOf(1, NaN, 1).month).toBe(0); }); - it(`equals to minimal`, () => { + it('equals to minimal', () => { expect(TuiDay.normalizeOf(1, 0, 1).month).toBe(0); }); - it(`smaller than minimal`, () => { + it('smaller than minimal', () => { expect(TuiDay.normalizeOf(1, -8, 1).month).toBe(0); }); }); - describe(`day if it`, () => { - it(`is NaN`, () => { + describe('day if it', () => { + it('is NaN', () => { expect(TuiDay.normalizeOf(1, 1, NaN).day).toBe(1); }); - it(`equals to minimal`, () => { + it('equals to minimal', () => { expect(TuiDay.normalizeOf(1, 1, 0).day).toBe(1); }); - it(`smaller than minimal`, () => { + it('smaller than minimal', () => { expect(TuiDay.normalizeOf(1, 1, -8).day).toBe(1); }); }); }); - describe(`rounded`, () => { - it(`year if a floating number was passed`, () => { + describe('rounded', () => { + it('year if a floating number was passed', () => { expect(TuiDay.normalizeOf(2000.1, 1, 1).year).toBe(2000); }); - it(`month if a floating number was passed`, () => { + it('month if a floating number was passed', () => { expect(TuiDay.normalizeOf(1, 8.1, 1).month).toBe(8); }); - it(`day if a floating number was passed`, () => { + it('day if a floating number was passed', () => { expect(TuiDay.normalizeOf(1, 1, 8.1).day).toBe(8); }); }); - describe(`maximum value for`, () => { - describe(`year if it`, () => { - it(`equals to maximum`, () => { + describe('maximum value for', () => { + describe('year if it', () => { + it('equals to maximum', () => { expect(TuiDay.normalizeOf(9999, 1, 1).year).toBe(9999); }); - it(`exceeds maximum`, () => { + it('exceeds maximum', () => { expect(TuiDay.normalizeOf(9999, 1, 1).year).toBe(9999); }); }); - describe(`month if it`, () => { - it(`equals to maximum`, () => { + describe('month if it', () => { + it('equals to maximum', () => { expect(TuiDay.normalizeOf(1, 11, 1).month).toBe(11); }); - it(`exceeds maximum`, () => { + it('exceeds maximum', () => { expect(TuiDay.normalizeOf(1, 99, 1).month).toBe(11); }); }); - describe(`day if it`, () => { - it(`equals to maximum`, () => { + describe('day if it', () => { + it('equals to maximum', () => { expect(TuiDay.normalizeOf(1, 1, 31).day).toBe(28); }); - it(`exceeds maximum`, () => { + it('exceeds maximum', () => { expect(TuiDay.normalizeOf(1, 1, 99).day).toBe(28); }); }); }); }); - describe(`normalizeParse return parsed date`, () => { - describe(`from a valid string (dd.mm.yyyy)`, () => { - it(`'20.10.2018'`, () => { - const result = TuiDay.normalizeParse(`20.10.2018`); + describe('normalizeParse return parsed date', () => { + describe('from a valid string (dd.mm.yyyy)', () => { + it("'20.10.2018'", () => { + const result = TuiDay.normalizeParse('20.10.2018'); expect(result.year).toBe(2018); expect(result.month).toBe(9); expect(result.day).toBe(20); }); - it(`'01.01.0000'`, () => { - const result = TuiDay.normalizeParse(`01.01.0000`); + it("'01.01.0000'", () => { + const result = TuiDay.normalizeParse('01.01.0000'); expect(result.year).toBe(0); expect(result.month).toBe(0); expect(result.day).toBe(1); }); }); - describe(`from non valid string`, () => { - it(`'20.aa.2018'`, () => { - const result = TuiDay.normalizeParse(`20.aa.2018`); + describe('from non valid string', () => { + it("'20.aa.2018'", () => { + const result = TuiDay.normalizeParse('20.aa.2018'); expect(result.year).toBe(2018); expect(result.month).toBe(0); expect(result.day).toBe(20); }); - it(`'20.99.2018'`, () => { - const result = TuiDay.normalizeParse(`20.99.2018`); + it("'20.99.2018'", () => { + const result = TuiDay.normalizeParse('20.99.2018'); expect(result.year).toBe(2018); expect(result.month).toBe(11); expect(result.day).toBe(20); }); - it(`'test'`, () => { - const result = TuiDay.normalizeParse(`test`); + it("'test'", () => { + const result = TuiDay.normalizeParse('test'); expect(result.year).toBe(0); expect(result.month).toBe(0); expect(result.day).toBe(1); }); }); - describe(`from yyyy.mm.dd string`, () => { - it(`'2021/12/22'`, () => { - const result = TuiDay.normalizeParse(`2021/12/22`, `YMD`); + describe('from yyyy.mm.dd string', () => { + it("'2021/12/22'", () => { + const result = TuiDay.normalizeParse('2021/12/22', 'YMD'); expect(result.year).toBe(2021); expect(result.month).toBe(11); expect(result.day).toBe(22); }); - it(`'1900.05.01'`, () => { - const result = TuiDay.normalizeParse(`1900.05.01`, `YMD`); + it("'1900.05.01'", () => { + const result = TuiDay.normalizeParse('1900.05.01', 'YMD'); expect(result.year).toBe(1900); expect(result.month).toBe(4); @@ -347,17 +258,17 @@ describe(`TuiDay`, () => { }); }); - describe(`from mm.dd.yyyy string`, () => { - it(`'03/10/1956'`, () => { - const result = TuiDay.normalizeParse(`03/10/1956`, `MDY`); + describe('from mm.dd.yyyy string', () => { + it("'03/10/1956'", () => { + const result = TuiDay.normalizeParse('03/10/1956', 'MDY'); expect(result.year).toBe(1956); expect(result.month).toBe(2); expect(result.day).toBe(10); }); - it(`'01.02.0988'`, () => { - const result = TuiDay.normalizeParse(`01.02.0988`, `MDY`); + it("'01.02.0988'", () => { + const result = TuiDay.normalizeParse('01.02.0988', 'MDY'); expect(result.year).toBe(988); expect(result.month).toBe(0); @@ -366,53 +277,53 @@ describe(`TuiDay`, () => { }); }); - describe(`jsonParse`, () => { - describe(`returns parsed date from a valid string`, () => { - it(`'2018-10-20'`, () => { - const result = TuiDay.jsonParse(`2018-10-20`); + describe('jsonParse', () => { + describe('returns parsed date from a valid string', () => { + it("'2018-10-20'", () => { + const result = TuiDay.jsonParse('2018-10-20'); expect(result.year).toBe(2018); expect(result.month).toBe(9); expect(result.day).toBe(20); }); - it(`'0000-01-01'`, () => { - const result = TuiDay.jsonParse(`0000-01-01`); + it("'0000-01-01'", () => { + const result = TuiDay.jsonParse('0000-01-01'); expect(result.year).toBe(0); expect(result.month).toBe(0); expect(result.day).toBe(1); }); }); - describe(`throws an exception`, () => { - it(`'2018-aa-20'`, () => { - expect(() => TuiDay.jsonParse(`2018-aa-20`)).toThrowError( - `Invalid month: NaN`, + describe('throws an exception', () => { + it("'2018-aa-20'", () => { + expect(() => TuiDay.jsonParse('2018-aa-20')).toThrowError( + 'Invalid month: NaN', ); }); - it(`'2018-99-20'`, () => { - expect(() => TuiDay.jsonParse(`2018-99-20`)).toThrowError( - `Invalid month: 98`, + it("'2018-99-20'", () => { + expect(() => TuiDay.jsonParse('2018-99-20')).toThrowError( + 'Invalid month: 98', ); }); - it(`'2001-02-29'`, () => { - expect(() => TuiDay.jsonParse(`2001-02-29`)).toThrowError( - `Invalid day: 29`, + it("'2001-02-29'", () => { + expect(() => TuiDay.jsonParse('2001-02-29')).toThrowError( + 'Invalid day: 29', ); }); - it(`'test'`, () => { - expect(() => TuiDay.jsonParse(`test`)).toThrowError( - `Invalid year: NaN`, + it("'test'", () => { + expect(() => TuiDay.jsonParse('test')).toThrowError( + 'Invalid year: NaN', ); }); }); }); - describe(`fromUtcNativeDate returns`, () => { - it(`1970.01.01 for UTC(1970, 0, 0)`, () => { + describe('fromUtcNativeDate returns', () => { + it('1970.01.01 for UTC(1970, 0, 0)', () => { const year = 1970; const month = 0; const day = 1; @@ -426,7 +337,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(day); }); - it(`2000.01.01 for UTC(2000, 0, 0, 23, 59, 59, 999)`, () => { + it('2000.01.01 for UTC(2000, 0, 0, 23, 59, 59, 999)', () => { const year = 2000; const month = 0; const day = 1; @@ -441,8 +352,8 @@ describe(`TuiDay`, () => { }); }); - describe(`fromLocalNativeDate returns`, () => { - it(`1970.01.01 for Date(1970, 0, 0)`, () => { + describe('fromLocalNativeDate returns', () => { + it('1970.01.01 for Date(1970, 0, 0)', () => { const year = 1970; const month = 0; const day = 1; @@ -454,7 +365,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(day); }); - it(`2000.01.01 for Date(2000, 0, 0, 23, 59, 59, 999)`, () => { + it('2000.01.01 for Date(2000, 0, 0, 23, 59, 59, 999)', () => { const year = 2000; const month = 0; const day = 1; @@ -470,57 +381,57 @@ describe(`TuiDay`, () => { }); }); - describe(`prototype`, () => { - describe(`getter`, () => { - describe(`formattedDayPart returns`, () => { - describe(`day padded with '0' if it's a single digit day`, () => { - it(`'01' for 1`, () => { - expect(new TuiDay(2000, 0, 1).formattedDayPart).toBe(`01`); + describe('prototype', () => { + describe('getter', () => { + describe('formattedDayPart returns', () => { + describe("day padded with '0' if it's a single digit day", () => { + it("'01' for 1", () => { + expect(new TuiDay(2000, 0, 1).formattedDayPart).toBe('01'); }); - it(`'05' for 5`, () => { - expect(new TuiDay(2000, 4, 5).formattedDayPart).toBe(`05`); + it("'05' for 5", () => { + expect(new TuiDay(2000, 4, 5).formattedDayPart).toBe('05'); }); }); - describe(`without padded '0' for 2 digit days`, () => { - it(`'10' for 10`, () => { - expect(new TuiDay(2000, 9, 10).formattedDayPart).toBe(`10`); + describe("without padded '0' for 2 digit days", () => { + it("'10' for 10", () => { + expect(new TuiDay(2000, 9, 10).formattedDayPart).toBe('10'); }); - it(`'12' for 12`, () => { - expect(new TuiDay(2000, 11, 12).formattedDayPart).toBe(`12`); + it("'12' for 12", () => { + expect(new TuiDay(2000, 11, 12).formattedDayPart).toBe('12'); }); }); }); - describe(`formattedDay returns`, () => { - it(`'01.01.2000' for TuiMonth {year: 2000, month: 0, day: 1}`, () => { - expect(new TuiDay(2000, 0, 1).getFormattedDay(`DMY`, `.`)).toBe( - `01.01.2000`, + describe('formattedDay returns', () => { + it("'01.01.2000' for TuiMonth {year: 2000, month: 0, day: 1}", () => { + expect(new TuiDay(2000, 0, 1).getFormattedDay('DMY', '.')).toBe( + '01.01.2000', ); }); - it(`'05.01.2000' for TuiMonth {year: 2000, month: 0, day: 5}`, () => { - expect(new TuiDay(2000, 0, 5).getFormattedDay(`DMY`, `.`)).toBe( - `05.01.2000`, + it("'05.01.2000' for TuiMonth {year: 2000, month: 0, day: 5}", () => { + expect(new TuiDay(2000, 0, 5).getFormattedDay('DMY', '.')).toBe( + '05.01.2000', ); }); - it(`'10.01.0000' for TuiMonth {year: 0, month: 0, day: 10}`, () => { - expect(new TuiDay(0, 0, 10).getFormattedDay(`DMY`, `.`)).toBe( - `10.01.0000`, + it("'10.01.0000' for TuiMonth {year: 0, month: 0, day: 10}", () => { + expect(new TuiDay(0, 0, 10).getFormattedDay('DMY', '.')).toBe( + '10.01.0000', ); }); - it(`'12.01.1995' for TuiMonth {year: 1995, month: 0, day: 12}`, () => { - expect(new TuiDay(1995, 0, 12).getFormattedDay(`DMY`, `.`)).toBe( - `12.01.1995`, + it("'12.01.1995' for TuiMonth {year: 1995, month: 0, day: 12}", () => { + expect(new TuiDay(1995, 0, 12).getFormattedDay('DMY', '.')).toBe( + '12.01.1995', ); }); }); }); - describe(`method`, () => { + describe('method', () => { let y1900m6d10: TuiDay; let y2000m4d15: TuiDay; let y2000m6d10: TuiDay; @@ -541,39 +452,39 @@ describe(`TuiDay`, () => { y2100m6d15 = new TuiDay(2100, 6, 15); }); - describe(`dayBefore returns`, () => { - describe(`true if passed year`, () => { - describe(`is the same and month`, () => { - it(`is bigger`, () => { + describe('dayBefore returns', () => { + describe('true if passed year', () => { + describe('is the same and month', () => { + it('is bigger', () => { expect(y2000m6d15.dayBefore(y2000m8d16)).toBe(true); }); - it(`is the same and day is bigger`, () => { + it('is the same and day is bigger', () => { expect(y2000m6d15.dayBefore(y2000m6d20)).toBe(true); }); }); - it(`bigger`, () => { + it('bigger', () => { expect(y2000m6d15.dayBefore(y2100m6d15)).toBe(true); }); }); - describe(`false if passed year`, () => { - it(`is smaller`, () => { + describe('false if passed year', () => { + it('is smaller', () => { expect(y2000m6d15.dayBefore(y1900m6d10)).toBe(false); }); - describe(`is the same and month`, () => { - it(`is smaller`, () => { + describe('is the same and month', () => { + it('is smaller', () => { expect(y2000m6d15.dayBefore(y2000m4d15)).toBe(false); }); - describe(`is the same and day`, () => { - it(`is smaller`, () => { + describe('is the same and day', () => { + it('is smaller', () => { expect(y2000m6d15.dayBefore(y2000m6d10)).toBe(false); }); - it(`is the same`, () => { + it('is the same', () => { expect(y2000m6d15.dayBefore(y2000m6d15v2)).toBe(false); }); }); @@ -581,101 +492,101 @@ describe(`TuiDay`, () => { }); }); - describe(`daySameOrBefore returns`, () => { - describe(`true if passed year`, () => { - describe(`is the same and month`, () => { - describe(`is the same and day`, () => { - it(`is the same`, () => { + describe('daySameOrBefore returns', () => { + describe('true if passed year', () => { + describe('is the same and month', () => { + describe('is the same and day', () => { + it('is the same', () => { expect(y2000m6d15.daySameOrBefore(y2000m6d15v2)).toBe( true, ); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000m6d15.daySameOrBefore(y2000m6d20)).toBe(true); }); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000m6d15.daySameOrBefore(y2000m8d16)).toBe(true); }); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000m6d15.daySameOrBefore(y2100m6d15)).toBe(true); }); }); - describe(`false if passed year`, () => { - it(`is smaller`, () => { + describe('false if passed year', () => { + it('is smaller', () => { expect(y2000m6d15.daySameOrBefore(y1900m6d10)).toBe(false); }); - describe(`is the same and month`, () => { - it(`is smaller`, () => { + describe('is the same and month', () => { + it('is smaller', () => { expect(y2000m6d15.daySameOrBefore(y2000m4d15)).toBe(false); }); - it(`is the same and day is the same`, () => { + it('is the same and day is the same', () => { expect(y2000m6d15.daySameOrBefore(y2000m6d10)).toBe(false); }); }); }); }); - describe(`daySame returns`, () => { - it(`true if passed year is the same, month is the same and day is the same`, () => { + describe('daySame returns', () => { + it('true if passed year is the same, month is the same and day is the same', () => { expect(y2000m6d15.daySame(y2000m6d15v2)).toBe(true); }); - describe(`false if passed year`, () => { - it(`is smaller`, () => { + describe('false if passed year', () => { + it('is smaller', () => { expect(y2000m6d15.daySame(y1900m6d10)).toBe(false); }); - describe(`is the same and month`, () => { - it(`is smaller`, () => { + describe('is the same and month', () => { + it('is smaller', () => { expect(y2000m6d15.daySame(y2000m4d15)).toBe(false); }); - describe(`is the same and day`, () => { - it(`is smaller`, () => { + describe('is the same and day', () => { + it('is smaller', () => { expect(y2000m6d15.daySame(y2000m6d10)).toBe(false); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000m6d15.daySame(y2000m6d20)).toBe(false); }); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000m6d15.daySame(y2000m8d16)).toBe(false); }); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000m6d15.daySame(y2100m6d15)).toBe(false); }); }); }); - describe(`daySameOrAfter returns`, () => { - describe(`true if passed year`, () => { - it(`is smaller`, () => { + describe('daySameOrAfter returns', () => { + describe('true if passed year', () => { + it('is smaller', () => { expect(y2000m6d15.daySameOrAfter(y1900m6d10)).toBe(true); }); - describe(`is the same and month`, () => { - it(`is smaller`, () => { + describe('is the same and month', () => { + it('is smaller', () => { expect(y2000m6d15.daySameOrAfter(y2000m4d15)).toBe(true); }); - describe(`is the same and day`, () => { - it(`is smaller`, () => { + describe('is the same and day', () => { + it('is smaller', () => { expect(y2000m6d15.daySameOrAfter(y2000m6d10)).toBe(true); }); - it(`is the same`, () => { + it('is the same', () => { expect(y2000m6d15.daySameOrAfter(y2000m6d15v2)).toBe( true, ); @@ -684,75 +595,75 @@ describe(`TuiDay`, () => { }); }); - describe(`false if passed year`, () => { - describe(`is the same and month`, () => { - it(`is the same and day is smaller`, () => { + describe('false if passed year', () => { + describe('is the same and month', () => { + it('is the same and day is smaller', () => { expect(y2000m6d15.daySameOrAfter(y2000m6d20)).toBe(false); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000m6d15.daySameOrAfter(y2000m8d16)).toBe(false); }); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000m6d15.daySameOrAfter(y2100m6d15)).toBe(false); }); }); }); - describe(`dayAfter returns`, () => { - describe(`true if passed year`, () => { - it(`is smaller`, () => { + describe('dayAfter returns', () => { + describe('true if passed year', () => { + it('is smaller', () => { expect(y2000m6d15.dayAfter(y1900m6d10)).toBe(true); }); - describe(`is the same and month`, () => { - it(`is smaller`, () => { + describe('is the same and month', () => { + it('is smaller', () => { expect(y2000m6d15.dayAfter(y2000m4d15)).toBe(true); }); - it(`is the same and day is smaller`, () => { + it('is the same and day is smaller', () => { expect(y2000m6d15.dayAfter(y2000m6d10)).toBe(true); }); }); }); - describe(`false if passed year`, () => { - describe(`is the same and month`, () => { - describe(`is the same and day`, () => { - it(`is the same`, () => { + describe('false if passed year', () => { + describe('is the same and month', () => { + describe('is the same and day', () => { + it('is the same', () => { expect(y2000m6d15.dayAfter(y2000m6d15v2)).toBe(false); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000m6d15.dayAfter(y2000m6d20)).toBe(false); }); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000m6d15.dayAfter(y2000m8d16)).toBe(false); }); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000m6d15.dayAfter(y2100m6d15)).toBe(false); }); }); }); - describe(`dayOfWeek returns`, () => { - it(`correct day of week when it starts from Monday`, () => { + describe('dayOfWeek returns', () => { + it('correct day of week when it starts from Monday', () => { expect(y2000m6d15.dayOfWeek(true)).toBe(5); }); - it(`correct day of week when it does not start from Monday`, () => { + it('correct day of week when it does not start from Monday', () => { expect(y2000m6d15.dayOfWeek(false)).toBe(6); }); }); - describe(`append returns`, () => { - it(`TuiDay {year: 2000, month: 6, day: 15} if {} was passed`, () => { + describe('append returns', () => { + it('TuiDay {year: 2000, month: 6, day: 15} if {} was passed', () => { const result = y2000m6d15.append({}); expect(result.year).toBe(2000); @@ -760,7 +671,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(15); }); - it(`TuiDay {year: 2000, month: 6, day: 15} if {year: 0} was passed`, () => { + it('TuiDay {year: 2000, month: 6, day: 15} if {year: 0} was passed', () => { const result = y2000m6d15.append({year: 0}); expect(result.year).toBe(2000); @@ -768,7 +679,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(15); }); - it(`TuiDay {year: 2000, month: 6, day: 15} if {year: 0, month: 0} was passed`, () => { + it('TuiDay {year: 2000, month: 6, day: 15} if {year: 0, month: 0} was passed', () => { const result = y2000m6d15.append({year: 0, month: 0}); expect(result.year).toBe(2000); @@ -776,7 +687,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(15); }); - it(`TuiDay {year: 2000, month: 6, day: 15} if {year: 0, month: 0, day: 0} was passed`, () => { + it('TuiDay {year: 2000, month: 6, day: 15} if {year: 0, month: 0, day: 0} was passed', () => { const result = y2000m6d15.append({ year: 0, month: 0, @@ -788,7 +699,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(15); }); - it(`TuiDay {year: 2005, month: 6, day: 15} if {year: 5} was passed`, () => { + it('TuiDay {year: 2005, month: 6, day: 15} if {year: 5} was passed', () => { const result = y2000m6d15.append({year: 5}); expect(result.year).toBe(2005); @@ -796,7 +707,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(15); }); - it(`TuiDay {year: 2005, month: 6, day: 15} if {year: -5} was passed`, () => { + it('TuiDay {year: 2005, month: 6, day: 15} if {year: -5} was passed', () => { const result = y2000m6d15.append({year: -5}); expect(result.year).toBe(1995); @@ -804,7 +715,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(15); }); - it(`TuiDay {year: 1995, month: 6, day: 15} if {year: 5}, true was passed`, () => { + it('TuiDay {year: 1995, month: 6, day: 15} if {year: 5}, true was passed', () => { const result = y2000m6d15.append({year: 5}, true); expect(result.year).toBe(1995); @@ -812,7 +723,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(15); }); - it(`TuiDay {year: 2000, month: 11, day: 15} if {month: 5} was passed`, () => { + it('TuiDay {year: 2000, month: 11, day: 15} if {month: 5} was passed', () => { const result = y2000m6d15.append({month: 5}); expect(result.year).toBe(2000); @@ -820,7 +731,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(15); }); - it(`TuiDay {year: 2000, month: 1, day: 15} if {month: -5} was passed`, () => { + it('TuiDay {year: 2000, month: 1, day: 15} if {month: -5} was passed', () => { const result = y2000m6d15.append({month: -5}); expect(result.year).toBe(2000); @@ -828,7 +739,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(15); }); - it(`TuiDay {year: 2000, month: 1, day: 15} if {month: 5}, true was passed`, () => { + it('TuiDay {year: 2000, month: 1, day: 15} if {month: 5}, true was passed', () => { const result = y2000m6d15.append({month: 5}, true); expect(result.year).toBe(2000); @@ -836,7 +747,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(15); }); - it(`TuiDay {year: 2000, month: 6, day: 20} if {day: 5} was passed`, () => { + it('TuiDay {year: 2000, month: 6, day: 20} if {day: 5} was passed', () => { const result = y2000m6d15.append({day: 5}); expect(result.year).toBe(2000); @@ -844,7 +755,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(20); }); - it(`TuiDay {year: 2000, month: 6, day: 10} if {day: -5} was passed`, () => { + it('TuiDay {year: 2000, month: 6, day: 10} if {day: -5} was passed', () => { const result = y2000m6d15.append({day: -5}); expect(result.year).toBe(2000); @@ -852,7 +763,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(10); }); - it(`TuiDay {year: 2000, month: 6, day: 10} if {day: 5}, true was passed`, () => { + it('TuiDay {year: 2000, month: 6, day: 10} if {day: 5}, true was passed', () => { const result = y2000m6d15.append({day: 5}, true); expect(result.year).toBe(2000); @@ -860,7 +771,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(10); }); - it(`TuiDay {year: 2000, month: 7, day: 1} if {day: 17} was passed`, () => { + it('TuiDay {year: 2000, month: 7, day: 1} if {day: 17} was passed', () => { const result = y2000m6d15.append({day: 17}); expect(result.year).toBe(2000); @@ -868,7 +779,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(1); }); - it(`TuiDay {year: 2000, month: 11, day: 31} if {day: 169} was passed`, () => { + it('TuiDay {year: 2000, month: 11, day: 31} if {day: 169} was passed', () => { const result = y2000m6d15.append({day: 169}); expect(result.year).toBe(2000); @@ -876,7 +787,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(31); }); - it(`TuiDay {year: 2001, month: 0, day: 1} if {day: 170} was passed`, () => { + it('TuiDay {year: 2001, month: 0, day: 1} if {day: 170} was passed', () => { const result = y2000m6d15.append({day: 170}); expect(result.year).toBe(2001); @@ -884,7 +795,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(1); }); - it(`TuiDay {year: 1999, month: 11, day: 31} if {day: -197} was passed`, () => { + it('TuiDay {year: 1999, month: 11, day: 31} if {day: -197} was passed', () => { const result = y2000m6d15.append({day: -197}); expect(result.year).toBe(1999); @@ -892,7 +803,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(31); }); - it(`TuiDay {year: 2000, month: 5, day: 30} if {day: -15} was passed`, () => { + it('TuiDay {year: 2000, month: 5, day: 30} if {day: -15} was passed', () => { const result = y2000m6d15.append({day: -15}); expect(result.year).toBe(2000); @@ -900,7 +811,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(30); }); - it(`TuiDay {year: 2000, month: 2, day: 29} if {month: -4, day: 14} was passed`, () => { + it('TuiDay {year: 2000, month: 2, day: 29} if {month: -4, day: 14} was passed', () => { const result = y2000m6d15.append({month: -4, day: 14}); expect(result.year).toBe(2000); @@ -908,7 +819,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(29); }); - it(`TuiDay {year: 1999, month: 11, day: 31} if {month: -6, day: -15} was passed`, () => { + it('TuiDay {year: 1999, month: 11, day: 31} if {month: -6, day: -15} was passed', () => { const result = y2000m6d15.append({month: -6, day: -15}); expect(result.year).toBe(1999); @@ -916,7 +827,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(31); }); - it(`TuiDay {year: 1999, month: 11, day: 31} if {month: 6, day: 15}, true was passed`, () => { + it('TuiDay {year: 1999, month: 11, day: 31} if {month: 6, day: 15}, true was passed', () => { const result = y2000m6d15.append({month: 6, day: 15}, true); expect(result.year).toBe(1999); @@ -924,7 +835,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(31); }); - it(`capped day when moving forward`, () => { + it('capped day when moving forward', () => { const result = new TuiDay(2018, 2, 30).append({ month: -1, }); @@ -934,7 +845,7 @@ describe(`TuiDay`, () => { expect(result.day).toBe(28); }); - it(`capped day when moving backward`, () => { + it('capped day when moving backward', () => { const result = new TuiDay(2018, 0, 31).append({month: 1}); expect(result.year).toBe(2018); @@ -943,112 +854,112 @@ describe(`TuiDay`, () => { }); }); - describe(`toJSON returns`, () => { - it(`'2000-01-01' for TuiMonth {year: 2000, month: 0, day: 1}`, () => { - expect(new TuiDay(2000, 0, 1).toJSON()).toBe(`2000-01-01`); + describe('toJSON returns', () => { + it("'2000-01-01' for TuiMonth {year: 2000, month: 0, day: 1}", () => { + expect(new TuiDay(2000, 0, 1).toJSON()).toBe('2000-01-01'); }); - it(`'2000-01-10' for TuiMonth {year: 2000, month: 0, day: 10}`, () => { - expect(new TuiDay(2000, 0, 10).toJSON()).toBe(`2000-01-10`); + it("'2000-01-10' for TuiMonth {year: 2000, month: 0, day: 10}", () => { + expect(new TuiDay(2000, 0, 10).toJSON()).toBe('2000-01-10'); }); - it(`'0200-01-01' for TuiMonth {year: 200, month: 0, day: 1}`, () => { - expect(new TuiDay(200, 0, 1).toJSON()).toBe(`0200-01-01`); + it("'0200-01-01' for TuiMonth {year: 200, month: 0, day: 1}", () => { + expect(new TuiDay(200, 0, 1).toJSON()).toBe('0200-01-01'); }); - it(`'0200-01-10' for TuiMonth {year: 200, month: 0, day: 10}`, () => { - expect(new TuiDay(200, 0, 10).toJSON()).toBe(`0200-01-10`); + it("'0200-01-10' for TuiMonth {year: 200, month: 0, day: 10}", () => { + expect(new TuiDay(200, 0, 10).toJSON()).toBe('0200-01-10'); }); }); - it(`toLocalNativeDate returns native Date with time zone offset`, () => { - pendingIfNotMoscowTimeZone(); + it('toLocalNativeDate returns native Date with time zone offset', () => { + tuiPendingIfNotMoscowTimeZone(); const result = new TuiDay(2000, 0, 1); expect(result.toLocalNativeDate()).toEqual(new Date(2000, 0, 1)); }); - it(`toUtcNativeDate returns native Date without time zone offset`, () => { - pendingIfNotMoscowTimeZone(); + it('toUtcNativeDate returns native Date without time zone offset', () => { + tuiPendingIfNotMoscowTimeZone(); const result = new TuiDay(2000, 0, 1); expect(result.toUtcNativeDate()).toEqual(new Date(Date.UTC(2000, 0, 1))); }); - describe(`dayLimit returns`, () => { - it(`minimal date if it is bigger than current`, () => { + describe('dayLimit returns', () => { + it('minimal date if it is bigger than current', () => { expect(y2000m6d15.dayLimit(y2100m6d15, null)).toBe(y2100m6d15); }); - it(`current date if it is within the limits`, () => { + it('current date if it is within the limits', () => { expect(y2000m6d15.dayLimit(y1900m6d10, y2100m6d15)).toBe(y2000m6d15); }); - it(`maximum date if it is smaller than current`, () => { + it('maximum date if it is smaller than current', () => { expect(y2000m6d15.dayLimit(null, y1900m6d10)).toBe(y1900m6d10); }); }); - describe(`toString returns`, () => { - describe(`(DMY mode, default)`, () => { - it(`'10.07.1900' for TuiMonth {year: 1900, month: 6, day: 10}`, () => { - expect(y1900m6d10.toString()).toBe(`10.07.1900`); + describe('toString returns', () => { + describe('(DMY mode, default)', () => { + it("'10.07.1900' for TuiMonth {year: 1900, month: 6, day: 10}", () => { + expect(y1900m6d10.toString()).toBe('10.07.1900'); }); - it(`'15.05.2000' for TuiMonth {year: 2000, month: 4, day: 15}`, () => { - expect(y2000m4d15.toString()).toBe(`15.05.2000`); + it("'15.05.2000' for TuiMonth {year: 2000, month: 4, day: 15}", () => { + expect(y2000m4d15.toString()).toBe('15.05.2000'); }); - it(`'16.09.2000' for TuiMonth {year: 2000, month: 8, day: 16}`, () => { - expect(y2000m8d16.toString()).toBe(`16.09.2000`); + it("'16.09.2000' for TuiMonth {year: 2000, month: 8, day: 16}", () => { + expect(y2000m8d16.toString()).toBe('16.09.2000'); }); - it(`'15.07.2100' for TuiMonth {year: 2100, month: 6, day: 15}`, () => { - expect(y2100m6d15.toString()).toBe(`15.07.2100`); + it("'15.07.2100' for TuiMonth {year: 2100, month: 6, day: 15}", () => { + expect(y2100m6d15.toString()).toBe('15.07.2100'); }); }); - describe(`(MDY mode, '/' as separator)`, () => { - it(`'07/10/1900' for TuiMonth {year: 1900, month: 6, day: 10}`, () => { - expect(y1900m6d10.toString(`MDY`, `/`)).toBe(`07/10/1900`); + describe("(MDY mode, '/' as separator)", () => { + it("'07/10/1900' for TuiMonth {year: 1900, month: 6, day: 10}", () => { + expect(y1900m6d10.toString('MDY', '/')).toBe('07/10/1900'); }); - it(`'05/15/2000' for TuiMonth {year: 2000, month: 4, day: 15}`, () => { - expect(y2000m4d15.toString(`MDY`, `/`)).toBe(`05/15/2000`); + it("'05/15/2000' for TuiMonth {year: 2000, month: 4, day: 15}", () => { + expect(y2000m4d15.toString('MDY', '/')).toBe('05/15/2000'); }); - it(`'09/16/2000' for TuiMonth {year: 2000, month: 8, day: 16}`, () => { - expect(y2000m8d16.toString(`MDY`, `/`)).toBe(`09/16/2000`); + it("'09/16/2000' for TuiMonth {year: 2000, month: 8, day: 16}", () => { + expect(y2000m8d16.toString('MDY', '/')).toBe('09/16/2000'); }); - it(`'07/15/2100' for TuiMonth {year: 2100, month: 6, day: 15}`, () => { - expect(y2100m6d15.toString(`MDY`, `/`)).toBe(`07/15/2100`); + it("'07/15/2100' for TuiMonth {year: 2100, month: 6, day: 15}", () => { + expect(y2100m6d15.toString('MDY', '/')).toBe('07/15/2100'); }); }); - describe(`(YMD mode, '-' as separator)`, () => { - it(`'1900-07-10' for TuiMonth {year: 1900, month: 6, day: 10}`, () => { - expect(y1900m6d10.toString(`YMD`, `-`)).toBe(`1900-07-10`); + describe("(YMD mode, '-' as separator)", () => { + it("'1900-07-10' for TuiMonth {year: 1900, month: 6, day: 10}", () => { + expect(y1900m6d10.toString('YMD', '-')).toBe('1900-07-10'); }); - it(`'2000-05-15' for TuiMonth {year: 2000, month: 4, day: 15}`, () => { - expect(y2000m4d15.toString(`YMD`, `-`)).toBe(`2000-05-15`); + it("'2000-05-15' for TuiMonth {year: 2000, month: 4, day: 15}", () => { + expect(y2000m4d15.toString('YMD', '-')).toBe('2000-05-15'); }); - it(`'2000-09-16' for TuiMonth {year: 2000, month: 8, day: 16}`, () => { - expect(y2000m8d16.toString(`YMD`, `-`)).toBe(`2000-09-16`); + it("'2000-09-16' for TuiMonth {year: 2000, month: 8, day: 16}", () => { + expect(y2000m8d16.toString('YMD', '-')).toBe('2000-09-16'); }); - it(`'2100-07-15' for TuiMonth {year: 2100, month: 6, day: 15}`, () => { - expect(y2100m6d15.toString(`YMD`, `-`)).toBe(`2100-07-15`); + it("'2100-07-15' for TuiMonth {year: 2100, month: 6, day: 15}", () => { + expect(y2100m6d15.toString('YMD', '-')).toBe('2100-07-15'); }); }); }); - describe(`valueOf returns`, () => { - it(`the primitive value of a TuiDay object`, () => { + describe('valueOf returns', () => { + it('the primitive value of a TuiDay object', () => { const day = new TuiDay(2000, 5, 13); expect(Number(day)).toBeInstanceOf(Number); @@ -1058,28 +969,28 @@ describe(`TuiDay`, () => { }); }); - describe(`Symbol.toPrimitive returns`, () => { - it(`a number if the hint is number`, () => { + describe('Symbol.toPrimitive returns', () => { + it('a number if the hint is number', () => { const day = new TuiDay(2009, 2, 28); expect(Number(day)).toBeInstanceOf(Number); expect(day.valueOf()).toBeInstanceOf(Number); - expect(day[Symbol.toPrimitive](`number`)).toBeInstanceOf(Number); + expect(day[Symbol.toPrimitive]('number')).toBeInstanceOf(Number); }); - it(`a string if the hint is string`, () => { + it('a string if the hint is string', () => { const day = new TuiDay(2004, 3, 22); expect(String(day)).toBeInstanceOf(String); expect(day.toString()).toBeInstanceOf(String); - expect(day[Symbol.toPrimitive](`string`)).toBeInstanceOf(String); + expect(day[Symbol.toPrimitive]('string')).toBeInstanceOf(String); }); - it(`a string if the hint is default`, () => { + it('a string if the hint is default', () => { const day = new TuiDay(2012, 7, 18); expect(`${day}`).toBeInstanceOf(String); - expect(day[Symbol.toPrimitive](`default`)).toBeInstanceOf(String); + expect(day[Symbol.toPrimitive]('default')).toBeInstanceOf(String); }); }); }); diff --git a/projects/cdk/date-time/test/helpers.ts b/projects/cdk/date-time/test/helpers.ts index 3077831bb21a2..7171eab067183 100644 --- a/projects/cdk/date-time/test/helpers.ts +++ b/projects/cdk/date-time/test/helpers.ts @@ -2,13 +2,9 @@ declare const global: {Date: typeof Date}; const OriginalDate = global.Date; -/** - * @deprecated: use {@link tuiMockCurrentDate} instead - */ -// eslint-disable-next-line @typescript-eslint/naming-convention -export function mockCurrentDate(dateOrNumber: Date | number): void { +export function tuiMockCurrentDate(dateOrNumber: Date | number): void { const date: Date = - typeof dateOrNumber === `number` ? new OriginalDate(dateOrNumber) : dateOrNumber; + typeof dateOrNumber === 'number' ? new OriginalDate(dateOrNumber) : dateOrNumber; class MockDate extends OriginalDate { constructor() { @@ -21,40 +17,19 @@ export function mockCurrentDate(dateOrNumber: Date | number): void { global.Date = MockDate as typeof Date; } -export const tuiMockCurrentDate = mockCurrentDate; - -/** - * @deprecated: use {@link tuiRestoreRealDate} instead - */ -// eslint-disable-next-line @typescript-eslint/naming-convention -export function restoreRealDate(): void { +export function tuiRestoreRealDate(): void { global.Date = OriginalDate; } -export const tuiRestoreRealDate = restoreRealDate; - -/** - * @deprecated: use {@link tuiMockDateInside} instead - */ -// eslint-disable-next-line @typescript-eslint/naming-convention -export function mockDateInside(dateMock: Date | number, callback: () => void): void { - mockCurrentDate(dateMock); +export function tuiMockDateInside(dateMock: Date | number, callback: () => void): void { + tuiMockCurrentDate(dateMock); callback(); - restoreRealDate(); + tuiRestoreRealDate(); } -export const tuiMockDateInside = mockDateInside; - // @bad TODO: find a legal way to spoof time zone on windows -/** - * @deprecated: use {@link tuiPendingIfNotMoscowTimeZone} instead - * Skips the test on time zones other than `'Europe/Moscow'`. - */ -// eslint-disable-next-line @typescript-eslint/naming-convention -export function pendingIfNotMoscowTimeZone(): void { - if (Intl.DateTimeFormat().resolvedOptions().timeZone !== `Europe/Moscow`) { +export function tuiPendingIfNotMoscowTimeZone(): void { + if (Intl.DateTimeFormat().resolvedOptions().timeZone !== 'Europe/Moscow') { pending(); } } - -export const tuiPendingIfNotMoscowTimeZone = pendingIfNotMoscowTimeZone; diff --git a/projects/cdk/date-time/test/month-range.spec.ts b/projects/cdk/date-time/test/month-range.spec.ts index acd0761ffa0c2..bf59905bb1327 100644 --- a/projects/cdk/date-time/test/month-range.spec.ts +++ b/projects/cdk/date-time/test/month-range.spec.ts @@ -2,9 +2,9 @@ import {RANGE_SEPARATOR_CHAR} from '../date-time'; import {TuiMonth} from '../month'; import {TuiMonthRange} from '../month-range'; -describe(`TuiMonthRange`, () => { - describe(`static method`, () => { - describe(`sort returns`, () => { +describe('TuiMonthRange', () => { + describe('static method', () => { + describe('sort returns', () => { let y2000m0: TuiMonth; let y2000m0v2: TuiMonth; let y3000m0: TuiMonth; @@ -15,21 +15,21 @@ describe(`TuiMonthRange`, () => { y3000m0 = new TuiMonth(3000, 0); }); - it(`dates in original order if they are already sorted`, () => { + it('dates in original order if they are already sorted', () => { const result = TuiMonthRange.sort(y2000m0, y3000m0); expect(result.from).toBe(y2000m0); expect(result.to).toBe(y3000m0); }); - it(`dates in reversed order if they are not sorted`, () => { + it('dates in reversed order if they are not sorted', () => { const result = TuiMonthRange.sort(y3000m0, y2000m0); expect(result.from).toBe(y2000m0); expect(result.to).toBe(y3000m0); }); - it(`dates in original order if they are already identical`, () => { + it('dates in original order if they are already identical', () => { const result = TuiMonthRange.sort(y2000m0, y2000m0v2); expect(result.from).toBe(y2000m0); @@ -38,40 +38,33 @@ describe(`TuiMonthRange`, () => { }); }); - describe(`prototype`, () => { - describe(`getter`, () => { - describe(`isSingleMonth returns`, () => { - it(`true if both dates are identical`, () => { + describe('prototype', () => { + describe('getter', () => { + describe('isSingleMonth returns', () => { + it('true if both dates are identical', () => { expect( new TuiMonthRange(new TuiMonth(2000, 0), new TuiMonth(2000, 0)) .isSingleMonth, ).toBe(true); }); - it(`false if dates are different`, () => { + it('false if dates are different', () => { expect( new TuiMonthRange(new TuiMonth(2000, 0), new TuiMonth(3000, 0)) .isSingleMonth, ).toBe(false); }); }); - - it(`formattedMonthRange returns formatted string`, () => { - expect( - new TuiMonthRange(new TuiMonth(2000, 0), new TuiMonth(3000, 0)) - .formattedMonthRange, - ).toBe(`01.2000${RANGE_SEPARATOR_CHAR}01.3000`); - }); }); - describe(`method monthSame returns`, () => { + describe('method monthSame returns', () => { let range: TuiMonthRange; beforeEach(() => { range = new TuiMonthRange(new TuiMonth(2000, 0), new TuiMonth(2000, 0)); }); - it(`true if ranges are identical`, () => { + it('true if ranges are identical', () => { expect( range.monthSame( new TuiMonthRange(new TuiMonth(2000, 0), new TuiMonth(2000, 0)), @@ -79,7 +72,7 @@ describe(`TuiMonthRange`, () => { ).toBe(true); }); - it(`false if ranges are different`, () => { + it('false if ranges are different', () => { expect( range.monthSame( new TuiMonthRange(new TuiMonth(2000, 0), new TuiMonth(3000, 0)), @@ -89,8 +82,8 @@ describe(`TuiMonthRange`, () => { }); }); - describe(`toString`, () => { - it(`returns stringified value in correct format`, () => { + describe('toString', () => { + it('returns stringified value in correct format', () => { const range = new TuiMonthRange(new TuiMonth(2000, 0), new TuiMonth(3000, 0)); expect(range.toString()).toBe(`01.2000${RANGE_SEPARATOR_CHAR}01.3000`); diff --git a/projects/cdk/date-time/test/month.spec.ts b/projects/cdk/date-time/test/month.spec.ts index 70384e0f0b2b9..cc1ce8ff28c05 100644 --- a/projects/cdk/date-time/test/month.spec.ts +++ b/projects/cdk/date-time/test/month.spec.ts @@ -1,130 +1,130 @@ import {TuiMonthNumber} from '../../enums/month-number'; import {TuiMonth} from '../month'; -import {mockDateInside, pendingIfNotMoscowTimeZone} from './helpers'; +import {tuiMockDateInside, tuiPendingIfNotMoscowTimeZone} from './helpers'; -describe(`TuiMonth`, () => { - describe(`static method`, () => { - describe(`isValidMonth`, () => { - describe(`invalid month`, () => { - it(`NaN`, () => { +describe('TuiMonth', () => { + describe('static method', () => { + describe('isValidMonth', () => { + describe('invalid month', () => { + it('NaN', () => { expect(TuiMonth.isValidMonth(2000, NaN)).toBe(false); }); - it(`6.1`, () => { + it('6.1', () => { expect(TuiMonth.isValidMonth(2000, 6.1)).toBe(false); }); - it(`-20`, () => { + it('-20', () => { expect(TuiMonth.isValidMonth(2000, -20)).toBe(false); }); - it(`100000`, () => { + it('100000', () => { expect(TuiMonth.isValidMonth(2000, 100000)).toBe(false); }); }); - describe(`valid month`, () => { - it(`10`, () => { + describe('valid month', () => { + it('10', () => { expect(TuiMonth.isValidMonth(2000, 10)).toBe(true); }); - it(`9`, () => { + it('9', () => { expect(TuiMonth.isValidMonth(2000, 9)).toBe(true); }); - it(`0`, () => { + it('0', () => { expect(TuiMonth.isValidMonth(2000, 0)).toBe(true); }); - it(`11`, () => { + it('11', () => { expect(TuiMonth.isValidMonth(2000, 11)).toBe(true); }); }); }); - describe(`getMonthDaysCount returns`, () => { - describe(`31 if month is`, () => { - it(`January`, () => { + describe('getMonthDaysCount returns', () => { + describe('31 if month is', () => { + it('January', () => { expect(TuiMonth.getMonthDaysCount(TuiMonthNumber.January, true)).toBe( 31, ); }); - it(`May`, () => { + it('May', () => { expect(TuiMonth.getMonthDaysCount(TuiMonthNumber.May, true)).toBe(31); }); - it(`July`, () => { + it('July', () => { expect(TuiMonth.getMonthDaysCount(TuiMonthNumber.July, true)).toBe( 31, ); }); - it(`August`, () => { + it('August', () => { expect(TuiMonth.getMonthDaysCount(TuiMonthNumber.August, true)).toBe( 31, ); }); - it(`October`, () => { + it('October', () => { expect(TuiMonth.getMonthDaysCount(TuiMonthNumber.October, true)).toBe( 31, ); }); - it(`December`, () => { + it('December', () => { expect( TuiMonth.getMonthDaysCount(TuiMonthNumber.December, true), ).toBe(31); }); }); - describe(`30 if month is`, () => { - it(`April`, () => { + describe('30 if month is', () => { + it('April', () => { expect(TuiMonth.getMonthDaysCount(TuiMonthNumber.April, true)).toBe( 30, ); }); - it(`June`, () => { + it('June', () => { expect(TuiMonth.getMonthDaysCount(TuiMonthNumber.June, true)).toBe( 30, ); }); - it(`September`, () => { + it('September', () => { expect( TuiMonth.getMonthDaysCount(TuiMonthNumber.September, true), ).toBe(30); }); - it(`November`, () => { + it('November', () => { expect( TuiMonth.getMonthDaysCount(TuiMonthNumber.November, true), ).toBe(30); }); }); - it(`29 if month is February and the year is a leap year`, () => { + it('29 if month is February and the year is a leap year', () => { expect(TuiMonth.getMonthDaysCount(TuiMonthNumber.February, true)).toBe( 29, ); }); - it(`28 if month is February and the year is not a leap year`, () => { + it('28 if month is February and the year is not a leap year', () => { expect(TuiMonth.getMonthDaysCount(TuiMonthNumber.February, false)).toBe( 28, ); }); }); - describe(`currentLocal`, () => { + describe('currentLocal', () => { beforeEach(() => { - pendingIfNotMoscowTimeZone(); + tuiPendingIfNotMoscowTimeZone(); }); - it(`UTC month is the same as local`, () => { - mockDateInside(Date.UTC(2000, 0, 31, 10), () => { + it('UTC month is the same as local', () => { + tuiMockDateInside(Date.UTC(2000, 0, 31, 10), () => { const currentDate = TuiMonth.currentLocal(); expect(currentDate.year).toBe(2000); @@ -132,8 +132,8 @@ describe(`TuiMonth`, () => { }); }); - it(`UTC month is smaller than local`, () => { - mockDateInside(Date.UTC(2000, 0, 31, 23), () => { + it('UTC month is smaller than local', () => { + tuiMockDateInside(Date.UTC(2000, 0, 31, 23), () => { const currentDate = TuiMonth.currentLocal(); expect(currentDate.year).toBe(2000); @@ -142,13 +142,13 @@ describe(`TuiMonth`, () => { }); }); - describe(`currentUtc`, () => { + describe('currentUtc', () => { beforeEach(() => { - pendingIfNotMoscowTimeZone(); + tuiPendingIfNotMoscowTimeZone(); }); - it(`UTC is the same as local`, () => { - mockDateInside(new Date(2000, 0, 31, 10), () => { + it('UTC is the same as local', () => { + tuiMockDateInside(new Date(2000, 0, 31, 10), () => { const currentDate = TuiMonth.currentUtc(); expect(currentDate.year).toBe(2000); @@ -156,8 +156,8 @@ describe(`TuiMonth`, () => { }); }); - it(`UTC is smaller than local`, () => { - mockDateInside(new Date(2000, 0, 1, 2), () => { + it('UTC is smaller than local', () => { + tuiMockDateInside(new Date(2000, 0, 1, 2), () => { const currentDate = TuiMonth.currentUtc(); expect(currentDate.year).toBe(1999); @@ -166,22 +166,22 @@ describe(`TuiMonth`, () => { }); }); - describe(`lengthBetween`, () => { - it(`one month`, () => { + describe('lengthBetween', () => { + it('one month', () => { const first = new TuiMonth(2020, 4); const second = new TuiMonth(2020, 5); expect(TuiMonth.lengthBetween(first, second)).toBe(1); }); - it(`13 months`, () => { + it('13 months', () => { const first = new TuiMonth(2020, 4); const second = new TuiMonth(2021, 5); expect(TuiMonth.lengthBetween(first, second)).toBe(13); }); - it(`second less than first`, () => { + it('second less than first', () => { const first = new TuiMonth(2020, 4); const second = new TuiMonth(2020, 2); @@ -190,153 +190,107 @@ describe(`TuiMonth`, () => { }); }); - describe(`prototype`, () => { - describe(`getter`, () => { - describe(`formattedMonthPart returns`, () => { - describe(`month with padded '0' if it is a single digit month`, () => { - it(`'01' if month is 0`, () => { - expect(new TuiMonth(2000, 0).formattedMonthPart).toBe(`01`); + describe('prototype', () => { + describe('getter', () => { + describe('formattedMonthPart returns', () => { + describe("month with padded '0' if it is a single digit month", () => { + it("'01' if month is 0", () => { + expect(new TuiMonth(2000, 0).formattedMonthPart).toBe('01'); }); - it(`'05' if month is 4`, () => { - expect(new TuiMonth(2000, 4).formattedMonthPart).toBe(`05`); + it("'05' if month is 4", () => { + expect(new TuiMonth(2000, 4).formattedMonthPart).toBe('05'); }); }); - describe(`month withouth padded '0' if it is a two digit month`, () => { - it(`'10' if month is 9`, () => { - expect(new TuiMonth(2000, 9).formattedMonthPart).toBe(`10`); + describe("month withouth padded '0' if it is a two digit month", () => { + it("'10' if month is 9", () => { + expect(new TuiMonth(2000, 9).formattedMonthPart).toBe('10'); }); - it(`'12' if month is 11`, () => { - expect(new TuiMonth(2000, 11).formattedMonthPart).toBe(`12`); + it("'12' if month is 11", () => { + expect(new TuiMonth(2000, 11).formattedMonthPart).toBe('12'); }); }); }); - describe(`formattedMonth returns`, () => { - it(`'01.2000' for TuiMonth {year: 2000, month: 0}`, () => { - expect(new TuiMonth(2000, 0).formattedMonth).toBe(`01.2000`); - }); - - it(`'05.2000' for TuiMonth {year: 2000, month: 4}`, () => { - expect(new TuiMonth(2000, 4).formattedMonth).toBe(`05.2000`); - }); - - it(`'10.0000' for TuiMonth {year: 0, month: 9}`, () => { - expect(new TuiMonth(0, 9).formattedMonth).toBe(`10.0000`); - }); - - it(`'12.1995' for TuiMonth {year: 1995, month: 11}`, () => { - expect(new TuiMonth(1995, 11).formattedMonth).toBe(`12.1995`); - }); - }); - - describe(`weeksRowsCount`, () => { - it(`2018.02`, () => { - expect(new TuiMonth(2018, 1).weeksRowsCount).toBe(5); - }); - - it(`2018.04`, () => { - expect(new TuiMonth(2018, 3).weeksRowsCount).toBe(6); - }); - - it(`2021.02`, () => { - expect(new TuiMonth(2010, 1).weeksRowsCount).toBe(4); - }); - }); - - describe(`daysCount`, () => { - describe(`31 if month is`, () => { - it(`January`, () => { + describe('daysCount', () => { + describe('31 if month is', () => { + it('January', () => { expect(new TuiMonth(2000, TuiMonthNumber.January).daysCount).toBe( 31, ); }); - it(`May`, () => { + it('May', () => { expect(new TuiMonth(2000, TuiMonthNumber.May).daysCount).toBe(31); }); - it(`July`, () => { + it('July', () => { expect(new TuiMonth(2000, TuiMonthNumber.July).daysCount).toBe( 31, ); }); - it(`August`, () => { + it('August', () => { expect(new TuiMonth(2000, TuiMonthNumber.August).daysCount).toBe( 31, ); }); - it(`October`, () => { + it('October', () => { expect(new TuiMonth(2000, TuiMonthNumber.October).daysCount).toBe( 31, ); }); - it(`December`, () => { + it('December', () => { expect( new TuiMonth(2000, TuiMonthNumber.December).daysCount, ).toBe(31); }); }); - describe(`30 if month is`, () => { - it(`April`, () => { + describe('30 if month is', () => { + it('April', () => { expect(new TuiMonth(2000, TuiMonthNumber.April).daysCount).toBe( 30, ); }); - it(`June`, () => { + it('June', () => { expect(new TuiMonth(2000, TuiMonthNumber.June).daysCount).toBe( 30, ); }); - it(`September`, () => { + it('September', () => { expect( new TuiMonth(2000, TuiMonthNumber.September).daysCount, ).toBe(30); }); - it(`November`, () => { + it('November', () => { expect( new TuiMonth(2000, TuiMonthNumber.November).daysCount, ).toBe(30); }); }); - it(`29 if month is February and the year is a leap year`, () => { + it('29 if month is February and the year is a leap year', () => { expect(new TuiMonth(2000, TuiMonthNumber.February).daysCount).toBe( 29, ); }); - it(`28 if month is February and the year is not a leap year`, () => { + it('28 if month is February and the year is not a leap year', () => { expect(new TuiMonth(2001, TuiMonthNumber.February).daysCount).toBe( 28, ); }); }); - - describe(`monthStartDaysOffset`, () => { - it(`2018.02`, () => { - expect(new TuiMonth(2018, 1).monthStartDaysOffset).toBe(3); - }); - - it(`1995.04`, () => { - expect(new TuiMonth(1995, 3).monthStartDaysOffset).toBe(5); - }); - - it(`3011.10`, () => { - expect(new TuiMonth(3011, 9).monthStartDaysOffset).toBe(1); - }); - }); }); - describe(`method`, () => { + describe('method', () => { let y1900m6: TuiMonth; let y2000m4: TuiMonth; let y2000m6: TuiMonth; @@ -353,162 +307,162 @@ describe(`TuiMonth`, () => { y2100m6 = new TuiMonth(2100, 6); }); - describe(`monthBefore returns`, () => { - describe(`true if passed year`, () => { - describe(`is the same and month`, () => { - it(`is bigger`, () => { + describe('monthBefore returns', () => { + describe('true if passed year', () => { + describe('is the same and month', () => { + it('is bigger', () => { expect(y2000m6.monthBefore(y2000m8)).toBe(true); }); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000m6.monthBefore(y2100m6)).toBe(true); }); }); - describe(`false if passed year`, () => { - it(`is smaller`, () => { + describe('false if passed year', () => { + it('is smaller', () => { expect(y2000m6.monthBefore(y1900m6)).toBe(false); }); - describe(`is the same and month`, () => { - it(`is smaller`, () => { + describe('is the same and month', () => { + it('is smaller', () => { expect(y2000m6.monthBefore(y2000m4)).toBe(false); }); - it(`is the same`, () => { + it('is the same', () => { expect(y2000m6.monthBefore(y2000m6v2)).toBe(false); }); }); }); }); - describe(`monthSameOrBefore returns`, () => { - describe(`true if passed year`, () => { - describe(`is the same and month`, () => { - it(`is the same`, () => { + describe('monthSameOrBefore returns', () => { + describe('true if passed year', () => { + describe('is the same and month', () => { + it('is the same', () => { expect(y2000m6.monthSameOrBefore(y2000m6v2)).toBe(true); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000m6.monthSameOrBefore(y2000m8)).toBe(true); }); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000m6.monthSameOrBefore(y2100m6)).toBe(true); }); }); - describe(`false if passed year`, () => { - it(`is smaller`, () => { + describe('false if passed year', () => { + it('is smaller', () => { expect(y2000m6.monthSameOrBefore(y1900m6)).toBe(false); }); - describe(`is the same and month`, () => { - it(`is smaller`, () => { + describe('is the same and month', () => { + it('is smaller', () => { expect(y2000m6.monthSameOrBefore(y2000m4)).toBe(false); }); }); }); }); - describe(`monthSame returns`, () => { - describe(`true if passed year`, () => { - describe(`is the same and month`, () => { - it(`is the same`, () => { + describe('monthSame returns', () => { + describe('true if passed year', () => { + describe('is the same and month', () => { + it('is the same', () => { expect(y2000m6.monthSame(y2000m6v2)).toBe(true); }); }); }); - describe(`false if passed year`, () => { - it(`is smaller`, () => { + describe('false if passed year', () => { + it('is smaller', () => { expect(y2000m6.monthSame(y1900m6)).toBe(false); }); - describe(`is the same and month`, () => { - it(`is smaller`, () => { + describe('is the same and month', () => { + it('is smaller', () => { expect(y2000m6.monthSame(y2000m4)).toBe(false); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000m6.monthSame(y2000m8)).toBe(false); }); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000m6.monthSame(y2100m6)).toBe(false); }); }); }); - describe(`monthSameOrAfter returns`, () => { - describe(`true if passed year`, () => { - it(`is smaller`, () => { + describe('monthSameOrAfter returns', () => { + describe('true if passed year', () => { + it('is smaller', () => { expect(y2000m6.monthSameOrAfter(y1900m6)).toBe(true); }); - describe(`is the same and month`, () => { - it(`is smaller`, () => { + describe('is the same and month', () => { + it('is smaller', () => { expect(y2000m6.monthSameOrAfter(y2000m4)).toBe(true); }); - it(`is the same`, () => { + it('is the same', () => { expect(y2000m6.monthSameOrAfter(y2000m6v2)).toBe(true); }); }); }); - describe(`false if passed year`, () => { - describe(`is the same and month`, () => { - it(`is bigger`, () => { + describe('false if passed year', () => { + describe('is the same and month', () => { + it('is bigger', () => { expect(y2000m6.monthSameOrAfter(y2000m8)).toBe(false); }); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000m6.monthSameOrAfter(y2100m6)).toBe(false); }); }); }); - describe(`monthAfter returns`, () => { - describe(`true if passed year`, () => { - it(`is smaller`, () => { + describe('monthAfter returns', () => { + describe('true if passed year', () => { + it('is smaller', () => { expect(y2000m6.monthAfter(y1900m6)).toBe(true); }); - describe(`is the same and month`, () => { - it(`is smaller`, () => { + describe('is the same and month', () => { + it('is smaller', () => { expect(y2000m6.monthAfter(y2000m4)).toBe(true); }); }); }); - describe(`false if passed year`, () => { - describe(`is the same and month`, () => { - it(`is the same`, () => { + describe('false if passed year', () => { + describe('is the same and month', () => { + it('is the same', () => { expect(y2000m6.monthAfter(y2000m6v2)).toBe(false); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000m6.monthAfter(y2000m8)).toBe(false); }); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000m6.monthAfter(y2100m6)).toBe(false); }); }); }); - describe(`append returns`, () => { - it(`TuiMonth {year: 2000, month: 6} if passed value was {}`, () => { + describe('append returns', () => { + it('TuiMonth {year: 2000, month: 6} if passed value was {}', () => { const result: TuiMonth = y2000m6.append({}); expect(result.year).toBe(2000); expect(result.month).toBe(6); }); - it(`TuiMonth {year: 2000, month: 6} if passed value was {year: 0, month: 0}`, () => { + it('TuiMonth {year: 2000, month: 6} if passed value was {year: 0, month: 0}', () => { const result: TuiMonth = y2000m6.append({ year: 0, month: 0, @@ -518,49 +472,49 @@ describe(`TuiMonth`, () => { expect(result.month).toBe(6); }); - it(`TuiMonth {year: 2001, month: 6} if passed value was {year: 1}`, () => { + it('TuiMonth {year: 2001, month: 6} if passed value was {year: 1}', () => { const result: TuiMonth = y2000m6.append({year: 1}); expect(result.year).toBe(2001); expect(result.month).toBe(6); }); - it(`TuiMonth {year: 1999 month: 6} if passed value was {year: -1}`, () => { + it('TuiMonth {year: 1999 month: 6} if passed value was {year: -1}', () => { const result: TuiMonth = y2000m6.append({year: -1}); expect(result.year).toBe(1999); expect(result.month).toBe(6); }); - it(`TuiMonth {year: 1999 month: 6} if passed value was {year: 1}, true`, () => { + it('TuiMonth {year: 1999 month: 6} if passed value was {year: 1}, true', () => { const result: TuiMonth = y2000m6.append({year: 1}, true); expect(result.year).toBe(1999); expect(result.month).toBe(6); }); - it(`TuiMonth {year: 2001, month: 6} if passed value was {month: 12}`, () => { + it('TuiMonth {year: 2001, month: 6} if passed value was {month: 12}', () => { const result: TuiMonth = y2000m6.append({month: 12}); expect(result.year).toBe(2001); expect(result.month).toBe(6); }); - it(`TuiMonth {year: 1999, month: 6} if passed value was {month: -12}`, () => { + it('TuiMonth {year: 1999, month: 6} if passed value was {month: -12}', () => { const result: TuiMonth = y2000m6.append({month: -12}); expect(result.year).toBe(1999); expect(result.month).toBe(6); }); - it(`TuiMonth {year: 1999, month: 6} if passed value was {month: 12}, true`, () => { + it('TuiMonth {year: 1999, month: 6} if passed value was {month: 12}, true', () => { const result: TuiMonth = y2000m6.append({month: 12}, true); expect(result.year).toBe(1999); expect(result.month).toBe(6); }); - it(`TuiMonth {year: 2001, month: 7} if passed value was {year: 1, month: 1}`, () => { + it('TuiMonth {year: 2001, month: 7} if passed value was {year: 1, month: 1}', () => { const result: TuiMonth = y2000m6.append({ year: 1, month: 1, @@ -570,7 +524,7 @@ describe(`TuiMonth`, () => { expect(result.month).toBe(7); }); - it(`TuiMonth {year: 1999, month: 5} if passed value was {year: -1, month: -1}`, () => { + it('TuiMonth {year: 1999, month: 5} if passed value was {year: -1, month: -1}', () => { const result: TuiMonth = y2000m6.append({ year: -1, month: -1, @@ -580,7 +534,7 @@ describe(`TuiMonth`, () => { expect(result.month).toBe(5); }); - it(`TuiMonth {year: 1999, month: 5} if passed value was {year: 1, month: 1}, true`, () => { + it('TuiMonth {year: 1999, month: 5} if passed value was {year: 1, month: 1}, true', () => { const result: TuiMonth = y2000m6.append({year: 1, month: 1}, true); expect(result.year).toBe(1999); @@ -588,38 +542,38 @@ describe(`TuiMonth`, () => { }); }); - describe(`toJSON returns`, () => { - it(`'2000-01' for TuiMonth {year: 2000, month: 0}`, () => { - expect(new TuiMonth(2000, 0).toJSON()).toBe(`2000-01`); + describe('toJSON returns', () => { + it("'2000-01' for TuiMonth {year: 2000, month: 0}", () => { + expect(new TuiMonth(2000, 0).toJSON()).toBe('2000-01'); }); - it(`'2000-10' for TuiMonth {year: 2000, month: 9}`, () => { - expect(new TuiMonth(2000, 9).toJSON()).toBe(`2000-10`); + it("'2000-10' for TuiMonth {year: 2000, month: 9}", () => { + expect(new TuiMonth(2000, 9).toJSON()).toBe('2000-10'); }); - it(`'0200-01' for TuiMonth {year: 200, month: 0}`, () => { - expect(new TuiMonth(200, 0).toJSON()).toBe(`0200-01`); + it("'0200-01' for TuiMonth {year: 200, month: 0}", () => { + expect(new TuiMonth(200, 0).toJSON()).toBe('0200-01'); }); - it(`'0200-10' for TuiMonth {year: 200, month: 9}`, () => { - expect(new TuiMonth(200, 9).toJSON()).toBe(`0200-10`); + it("'0200-10' for TuiMonth {year: 200, month: 9}", () => { + expect(new TuiMonth(200, 9).toJSON()).toBe('0200-10'); }); }); - it(`toLocalNativeDate returns Date(2000, 0) for TuiMonth {year: 2000, month: 0}`, () => { + it('toLocalNativeDate returns Date(2000, 0) for TuiMonth {year: 2000, month: 0}', () => { expect(new TuiMonth(2000, 0).toLocalNativeDate().toString()).toEqual( new Date(2000, 0).toString(), ); }); - it(`toUtcNativeDate returns Date(Date.UTC(2000, 0)) for TuiMonth {year: 2000, month: 0}`, () => { + it('toUtcNativeDate returns Date(Date.UTC(2000, 0)) for TuiMonth {year: 2000, month: 0}', () => { expect(new TuiMonth(2000, 0).toUtcNativeDate().toString()).toEqual( new Date(Date.UTC(2000, 0)).toString(), ); }); - describe(`valueOf returns`, () => { - it(`the primitive value of a TuiMonth object`, () => { + describe('valueOf returns', () => { + it('the primitive value of a TuiMonth object', () => { const month = new TuiMonth(2000, 5); expect(Number(month)).toBeInstanceOf(Number); @@ -629,36 +583,30 @@ describe(`TuiMonth`, () => { }); }); - describe(`Symbol.toPrimitive returns`, () => { - it(`a number if the hint is number`, () => { + describe('Symbol.toPrimitive returns', () => { + it('a number if the hint is number', () => { const month = new TuiMonth(1998, 7); expect(Number(month)).toBeInstanceOf(Number); expect(month.valueOf()).toBeInstanceOf(Number); - expect(month[Symbol.toPrimitive](`number`)).toBeInstanceOf(Number); + expect(month[Symbol.toPrimitive]('number')).toBeInstanceOf(Number); }); - it(`a string if the hint is string`, () => { + it('a string if the hint is string', () => { const month = new TuiMonth(2030, 1); expect(String(month)).toBeInstanceOf(String); expect(month.toString()).toBeInstanceOf(String); - expect(month[Symbol.toPrimitive](`string`)).toBeInstanceOf(String); + expect(month[Symbol.toPrimitive]('string')).toBeInstanceOf(String); }); - it(`a string if the hint is default`, () => { + it('a string if the hint is default', () => { const month = new TuiMonth(1905, 2); expect(`${month}`).toBeInstanceOf(String); - expect(month[Symbol.toPrimitive](`default`)).toBeInstanceOf(String); + expect(month[Symbol.toPrimitive]('default')).toBeInstanceOf(String); }); }); }); }); - - it(`stringified value equals formatted`, () => { - const month = new TuiMonth(2000, 0); - - expect(month.toString()).toBe(month.formattedMonth); - }); }); diff --git a/projects/cdk/date-time/test/year.spec.ts b/projects/cdk/date-time/test/year.spec.ts index 900d6ce6104a3..4a7b151b75f0b 100644 --- a/projects/cdk/date-time/test/year.spec.ts +++ b/projects/cdk/date-time/test/year.spec.ts @@ -1,536 +1,332 @@ import {TuiYear} from '../year'; -describe(`TuiYear`, () => { - describe(`static method`, () => { - describe(`isValidYear returns`, () => { - describe(`false if passed year is invalid`, () => { - it(`NaN`, () => { +describe('TuiYear', () => { + describe('static method', () => { + describe('isValidYear returns', () => { + describe('false if passed year is invalid', () => { + it('NaN', () => { expect(TuiYear.isValidYear(NaN)).toBe(false); }); - it(`-200`, () => { + it('-200', () => { expect(TuiYear.isValidYear(-200)).toBe(false); }); - it(`2000.1`, () => { + it('2000.1', () => { expect(TuiYear.isValidYear(2000.1)).toBe(false); }); - it(`100000`, () => { + it('100000', () => { expect(TuiYear.isValidYear(100000)).toBe(false); }); }); - describe(`true if passed year is valid`, () => { - it(`0`, () => { + describe('true if passed year is valid', () => { + it('0', () => { expect(TuiYear.isValidYear(0)).toBe(true); }); - it(`1`, () => { + it('1', () => { expect(TuiYear.isValidYear(1)).toBe(true); }); - it(`1990`, () => { + it('1990', () => { expect(TuiYear.isValidYear(1990)).toBe(true); }); - it(`2000`, () => { + it('2000', () => { expect(TuiYear.isValidYear(2000)).toBe(true); }); - it(`9999`, () => { + it('9999', () => { expect(TuiYear.isValidYear(9999)).toBe(true); }); }); }); - describe(`isLeapYear returns`, () => { - describe(`false if passed year is not a leap year`, () => { - it(`1`, () => { + describe('isLeapYear returns', () => { + describe('false if passed year is not a leap year', () => { + it('1', () => { expect(TuiYear.isLeapYear(1)).toBe(false); }); - it(`2`, () => { + it('2', () => { expect(TuiYear.isLeapYear(2)).toBe(false); }); - it(`3`, () => { + it('3', () => { expect(TuiYear.isLeapYear(3)).toBe(false); }); - it(`5`, () => { + it('5', () => { expect(TuiYear.isLeapYear(5)).toBe(false); }); - it(`2001`, () => { + it('2001', () => { expect(TuiYear.isLeapYear(2001)).toBe(false); }); - it(`2018`, () => { + it('2018', () => { expect(TuiYear.isLeapYear(2018)).toBe(false); }); - it(`2100`, () => { + it('2100', () => { expect(TuiYear.isLeapYear(2100)).toBe(false); }); - it(`1995`, () => { + it('1995', () => { expect(TuiYear.isLeapYear(1995)).toBe(false); }); - it(`1334`, () => { + it('1334', () => { expect(TuiYear.isLeapYear(1334)).toBe(false); }); - it(`3421`, () => { + it('3421', () => { expect(TuiYear.isLeapYear(3421)).toBe(false); }); }); - describe(`true if passed year is a leap year`, () => { - it(`0`, () => { + describe('true if passed year is a leap year', () => { + it('0', () => { expect(TuiYear.isLeapYear(0)).toBe(true); }); - it(`4`, () => { + it('4', () => { expect(TuiYear.isLeapYear(4)).toBe(true); }); - it(`20`, () => { + it('20', () => { expect(TuiYear.isLeapYear(20)).toBe(true); }); - it(`1200`, () => { + it('1200', () => { expect(TuiYear.isLeapYear(1200)).toBe(true); }); - it(`2000`, () => { + it('2000', () => { expect(TuiYear.isLeapYear(2000)).toBe(true); }); - it(`2020`, () => { + it('2020', () => { expect(TuiYear.isLeapYear(2020)).toBe(true); }); - it(`2104`, () => { + it('2104', () => { expect(TuiYear.isLeapYear(2104)).toBe(true); }); }); }); - describe(`getAbsoluteLeapYears returns`, () => { - it(`0 if passed value was 0`, () => { + describe('getAbsoluteLeapYears returns', () => { + it('0 if passed value was 0', () => { expect(TuiYear.getAbsoluteLeapYears(0)).toBe(0); }); - it(`1 if passed value was 1`, () => { + it('1 if passed value was 1', () => { expect(TuiYear.getAbsoluteLeapYears(1)).toBe(1); }); - it(`1 if passed value was 2`, () => { + it('1 if passed value was 2', () => { expect(TuiYear.getAbsoluteLeapYears(2)).toBe(1); }); - it(`1 if passed value was 3`, () => { + it('1 if passed value was 3', () => { expect(TuiYear.getAbsoluteLeapYears(3)).toBe(1); }); - it(`1 if passed value was 4`, () => { + it('1 if passed value was 4', () => { expect(TuiYear.getAbsoluteLeapYears(4)).toBe(1); }); - it(`2 if passed value was 5`, () => { + it('2 if passed value was 5', () => { expect(TuiYear.getAbsoluteLeapYears(5)).toBe(2); }); - it(`2 if passed value was 6`, () => { + it('2 if passed value was 6', () => { expect(TuiYear.getAbsoluteLeapYears(6)).toBe(2); }); - it(`2 if passed value was 7`, () => { + it('2 if passed value was 7', () => { expect(TuiYear.getAbsoluteLeapYears(7)).toBe(2); }); - it(`2 if passed value was 8`, () => { + it('2 if passed value was 8', () => { expect(TuiYear.getAbsoluteLeapYears(8)).toBe(2); }); - it(`3 if passed value was 9`, () => { + it('3 if passed value was 9', () => { expect(TuiYear.getAbsoluteLeapYears(9)).toBe(3); }); - it(`3 if passed value was 10`, () => { + it('3 if passed value was 10', () => { expect(TuiYear.getAbsoluteLeapYears(10)).toBe(3); }); - it(`485 if passed value was 2000`, () => { + it('485 if passed value was 2000', () => { expect(TuiYear.getAbsoluteLeapYears(2000)).toBe(485); }); - it(`2425 if passed value was 9999`, () => { + it('2425 if passed value was 9999', () => { expect(TuiYear.getAbsoluteLeapYears(9999)).toBe(2425); }); }); - - describe(`getYearStartDaysOffset returns`, () => { - it(`5 if passed value was 0`, () => { - expect( - TuiYear.getYearStartDaysOffset(0, TuiYear.getAbsoluteLeapYears(0)), - ).toBe(5); - }); - - it(`0 if passed value was 1`, () => { - expect( - TuiYear.getYearStartDaysOffset(1, TuiYear.getAbsoluteLeapYears(1)), - ).toBe(0); - }); - - it(`1 if passed value was 2`, () => { - expect( - TuiYear.getYearStartDaysOffset(2, TuiYear.getAbsoluteLeapYears(2)), - ).toBe(1); - }); - - it(`2 if passed value was 3`, () => { - expect( - TuiYear.getYearStartDaysOffset(3, TuiYear.getAbsoluteLeapYears(3)), - ).toBe(2); - }); - - it(`3 if passed value was 4`, () => { - expect( - TuiYear.getYearStartDaysOffset(4, TuiYear.getAbsoluteLeapYears(4)), - ).toBe(3); - }); - - it(`5 if passed value was 5`, () => { - expect( - TuiYear.getYearStartDaysOffset(5, TuiYear.getAbsoluteLeapYears(5)), - ).toBe(5); - }); - - it(`2 if passed value was 20`, () => { - expect( - TuiYear.getYearStartDaysOffset(20, TuiYear.getAbsoluteLeapYears(20)), - ).toBe(2); - }); - - it(`5 if passed value was 1200`, () => { - expect( - TuiYear.getYearStartDaysOffset( - 1200, - TuiYear.getAbsoluteLeapYears(1200), - ), - ).toBe(5); - }); - - it(`5 if passed value was 2000`, () => { - expect( - TuiYear.getYearStartDaysOffset( - 2000, - TuiYear.getAbsoluteLeapYears(2000), - ), - ).toBe(5); - }); - - it(`0 if passed value was 2001`, () => { - expect( - TuiYear.getYearStartDaysOffset( - 2001, - TuiYear.getAbsoluteLeapYears(2001), - ), - ).toBe(0); - }); - - it(`0 if passed value was 2018`, () => { - expect( - TuiYear.getYearStartDaysOffset( - 2018, - TuiYear.getAbsoluteLeapYears(2018), - ), - ).toBe(0); - }); - - it(`2 if passed value was 2020`, () => { - expect( - TuiYear.getYearStartDaysOffset( - 2020, - TuiYear.getAbsoluteLeapYears(2020), - ), - ).toBe(2); - }); - - it(`4 if passed value was 2100`, () => { - expect( - TuiYear.getYearStartDaysOffset( - 2100, - TuiYear.getAbsoluteLeapYears(2100), - ), - ).toBe(4); - }); - - it(`1 if passed value was 2104`, () => { - expect( - TuiYear.getYearStartDaysOffset( - 2104, - TuiYear.getAbsoluteLeapYears(2104), - ), - ).toBe(1); - }); - - it(`6 if passed value was 1995`, () => { - expect( - TuiYear.getYearStartDaysOffset( - 1995, - TuiYear.getAbsoluteLeapYears(1995), - ), - ).toBe(6); - }); - - it(`4 if passed value was 1334`, () => { - expect( - TuiYear.getYearStartDaysOffset( - 1334, - TuiYear.getAbsoluteLeapYears(1334), - ), - ).toBe(4); - }); - - it(`0 if passed value was 3421`, () => { - expect( - TuiYear.getYearStartDaysOffset( - 3421, - TuiYear.getAbsoluteLeapYears(3421), - ), - ).toBe(0); - }); - }); }); - describe(`prototype`, () => { - describe(`getter`, () => { - describe(`formattedYear returns`, () => { - it(`'0000' if year is 0`, () => { - expect(new TuiYear(0).formattedYear).toBe(`0000`); + describe('prototype', () => { + describe('getter', () => { + describe('formattedYear returns', () => { + it("'0000' if year is 0", () => { + expect(new TuiYear(0).formattedYear).toBe('0000'); }); - it(`'0001' if year is 1`, () => { - expect(new TuiYear(0).formattedYear).toBe(`0000`); + it("'0001' if year is 1", () => { + expect(new TuiYear(0).formattedYear).toBe('0000'); }); - it(`'0020' if year is 20`, () => { - expect(new TuiYear(20).formattedYear).toBe(`0020`); + it("'0020' if year is 20", () => { + expect(new TuiYear(20).formattedYear).toBe('0020'); }); - it(`'2000' if year is 2000`, () => { - expect(new TuiYear(2000).formattedYear).toBe(`2000`); + it("'2000' if year is 2000", () => { + expect(new TuiYear(2000).formattedYear).toBe('2000'); }); - it(`'9999' if year is 9999`, () => { - expect(new TuiYear(9999).formattedYear).toBe(`9999`); + it("'9999' if year is 9999", () => { + expect(new TuiYear(9999).formattedYear).toBe('9999'); }); }); - describe(`absoluteLeapYears returns`, () => { - it(`1 if year is 0`, () => { + describe('absoluteLeapYears returns', () => { + it('1 if year is 0', () => { expect(new TuiYear(0).absoluteLeapYears).toBe(0); }); - it(`1 if year is 1`, () => { + it('1 if year is 1', () => { expect(new TuiYear(1).absoluteLeapYears).toBe(1); }); - it(`1 if year is 2`, () => { + it('1 if year is 2', () => { expect(new TuiYear(2).absoluteLeapYears).toBe(1); }); - it(`1 if year is 3`, () => { + it('1 if year is 3', () => { expect(new TuiYear(3).absoluteLeapYears).toBe(1); }); - it(`1 if year is 4`, () => { + it('1 if year is 4', () => { expect(new TuiYear(4).absoluteLeapYears).toBe(1); }); - it(`2 if year is 5`, () => { + it('2 if year is 5', () => { expect(new TuiYear(5).absoluteLeapYears).toBe(2); }); - it(`2 if year is 6`, () => { + it('2 if year is 6', () => { expect(new TuiYear(6).absoluteLeapYears).toBe(2); }); - it(`2 if year is 7`, () => { + it('2 if year is 7', () => { expect(new TuiYear(7).absoluteLeapYears).toBe(2); }); - it(`2 if year is 8`, () => { + it('2 if year is 8', () => { expect(new TuiYear(8).absoluteLeapYears).toBe(2); }); - it(`3 if year is 9`, () => { + it('3 if year is 9', () => { expect(new TuiYear(9).absoluteLeapYears).toBe(3); }); - it(`3 if year is 10`, () => { + it('3 if year is 10', () => { expect(new TuiYear(10).absoluteLeapYears).toBe(3); }); - it(`485 if year is 2000`, () => { + it('485 if year is 2000', () => { expect(new TuiYear(2000).absoluteLeapYears).toBe(485); }); - it(`2425 if year is 9999`, () => { + it('2425 if year is 9999', () => { expect(new TuiYear(9999).absoluteLeapYears).toBe(2425); }); }); - describe(`isLeapYear returns`, () => { - describe(`false if it is not a leap year`, () => { - it(`1`, () => { + describe('isLeapYear returns', () => { + describe('false if it is not a leap year', () => { + it('1', () => { expect(new TuiYear(1).isLeapYear).toBe(false); }); - it(`2`, () => { + it('2', () => { expect(new TuiYear(2).isLeapYear).toBe(false); }); - it(`3`, () => { + it('3', () => { expect(new TuiYear(3).isLeapYear).toBe(false); }); - it(`5`, () => { + it('5', () => { expect(new TuiYear(5).isLeapYear).toBe(false); }); - it(`2001`, () => { + it('2001', () => { expect(new TuiYear(2001).isLeapYear).toBe(false); }); - it(`2018`, () => { + it('2018', () => { expect(new TuiYear(2018).isLeapYear).toBe(false); }); - it(`2100`, () => { + it('2100', () => { expect(new TuiYear(2100).isLeapYear).toBe(false); }); - it(`1995`, () => { + it('1995', () => { expect(new TuiYear(1995).isLeapYear).toBe(false); }); - it(`1334`, () => { + it('1334', () => { expect(new TuiYear(1334).isLeapYear).toBe(false); }); - it(`3421`, () => { + it('3421', () => { expect(new TuiYear(3421).isLeapYear).toBe(false); }); }); - describe(`true if it is a leap year`, () => { - it(`0`, () => { + describe('true if it is a leap year', () => { + it('0', () => { expect(new TuiYear(0).isLeapYear).toBe(true); }); - it(`4`, () => { + it('4', () => { expect(new TuiYear(4).isLeapYear).toBe(true); }); - it(`20`, () => { + it('20', () => { expect(new TuiYear(20).isLeapYear).toBe(true); }); - it(`1200`, () => { + it('1200', () => { expect(new TuiYear(1200).isLeapYear).toBe(true); }); - it(`2000`, () => { + it('2000', () => { expect(new TuiYear(2000).isLeapYear).toBe(true); }); - it(`2020`, () => { + it('2020', () => { expect(new TuiYear(2020).isLeapYear).toBe(true); }); - it(`2104`, () => { + it('2104', () => { expect(new TuiYear(2104).isLeapYear).toBe(true); }); }); }); - - describe(`yearStartDaysOffset returns`, () => { - it(`5 if year is 0`, () => { - expect(new TuiYear(0).yearStartDaysOffset).toBe(5); - }); - - it(`0 if year is 1`, () => { - expect(new TuiYear(1).yearStartDaysOffset).toBe(0); - }); - - it(`1 if year is 2`, () => { - expect(new TuiYear(2).yearStartDaysOffset).toBe(1); - }); - - it(`2 if year is 3`, () => { - expect(new TuiYear(3).yearStartDaysOffset).toBe(2); - }); - - it(`3 if year is 4`, () => { - expect(new TuiYear(4).yearStartDaysOffset).toBe(3); - }); - - it(`5 if year is 5`, () => { - expect(new TuiYear(5).yearStartDaysOffset).toBe(5); - }); - - it(`2 if year is 20`, () => { - expect(new TuiYear(20).yearStartDaysOffset).toBe(2); - }); - - it(`5 if year is 1200`, () => { - expect(new TuiYear(1200).yearStartDaysOffset).toBe(5); - }); - - it(`5 if year is 2000`, () => { - expect(new TuiYear(2000).yearStartDaysOffset).toBe(5); - }); - - it(`0 if year is 2001`, () => { - expect(new TuiYear(2001).yearStartDaysOffset).toBe(0); - }); - - it(`0 if year is 2018`, () => { - expect(new TuiYear(2018).yearStartDaysOffset).toBe(0); - }); - - it(`2 if year is 2020`, () => { - expect(new TuiYear(2020).yearStartDaysOffset).toBe(2); - }); - - it(`4 if year is 2100`, () => { - expect(new TuiYear(2100).yearStartDaysOffset).toBe(4); - }); - - it(`1 if year is 2104`, () => { - expect(new TuiYear(2104).yearStartDaysOffset).toBe(1); - }); - - it(`6 if year is 1995`, () => { - expect(new TuiYear(1995).yearStartDaysOffset).toBe(6); - }); - - it(`4 if year is 1334`, () => { - expect(new TuiYear(1334).yearStartDaysOffset).toBe(4); - }); - - it(`0 if year is 3421`, () => { - expect(new TuiYear(3421).yearStartDaysOffset).toBe(0); - }); - }); }); - describe(`method`, () => { + describe('method', () => { let y2000: TuiYear; let y1900: TuiYear; let y2000v2: TuiYear; @@ -543,128 +339,128 @@ describe(`TuiYear`, () => { y2100 = new TuiYear(2100); }); - describe(`yearBefore returns`, () => { - describe(`true if passed year`, () => { - it(`is bigger`, () => { + describe('yearBefore returns', () => { + describe('true if passed year', () => { + it('is bigger', () => { expect(y2000.yearBefore(y2100)).toBe(true); }); }); - describe(`false if passed year`, () => { - it(`is smaller`, () => { + describe('false if passed year', () => { + it('is smaller', () => { expect(y2000.yearBefore(y1900)).toBe(false); }); - it(`is the same`, () => { + it('is the same', () => { expect(y2000.yearBefore(y2000v2)).toBe(false); }); }); }); - describe(`yearSameOrBefore returns`, () => { - describe(`true if passed year`, () => { - it(`is the same`, () => { + describe('yearSameOrBefore returns', () => { + describe('true if passed year', () => { + it('is the same', () => { expect(y2000.yearSameOrBefore(y2000v2)).toBe(true); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000.yearSameOrBefore(y2100)).toBe(true); }); }); - describe(`false if passed year`, () => { - it(`is smaller`, () => { + describe('false if passed year', () => { + it('is smaller', () => { expect(y2000.yearSameOrBefore(y1900)).toBe(false); }); }); }); - describe(`yearSame returns`, () => { - describe(`true if passed year`, () => { - it(`is the same`, () => { + describe('yearSame returns', () => { + describe('true if passed year', () => { + it('is the same', () => { expect(y2000.yearSame(y2000v2)).toBe(true); }); }); - describe(`false if passed year`, () => { - it(`is smaller`, () => { + describe('false if passed year', () => { + it('is smaller', () => { expect(y2000.yearSame(y1900)).toBe(false); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000.yearSame(y2100)).toBe(false); }); }); }); - describe(`yearSameOrAfter returns`, () => { - describe(`true if passed year`, () => { - it(`is smaller`, () => { + describe('yearSameOrAfter returns', () => { + describe('true if passed year', () => { + it('is smaller', () => { expect(y2000.yearSameOrAfter(y1900)).toBe(true); }); - it(`is the same`, () => { + it('is the same', () => { expect(y2000.yearSameOrAfter(y2000v2)).toBe(true); }); }); - describe(`false if passed year`, () => { - it(`is bigger`, () => { + describe('false if passed year', () => { + it('is bigger', () => { expect(y2000.yearSameOrAfter(y2100)).toBe(false); }); }); }); - describe(`yearAfter returns`, () => { - describe(`true if passed year`, () => { - it(`is smaller`, () => { + describe('yearAfter returns', () => { + describe('true if passed year', () => { + it('is smaller', () => { expect(y2000.yearAfter(y1900)).toBe(true); }); }); - describe(`false if passed year`, () => { - it(`is the same`, () => { + describe('false if passed year', () => { + it('is the same', () => { expect(y2000.yearAfter(y2000v2)).toBe(false); }); - it(`is bigger`, () => { + it('is bigger', () => { expect(y2000.yearAfter(y2100)).toBe(false); }); }); }); - describe(`append returns`, () => { - it(`TuiYear {year: 2000} if passed value was {}`, () => { + describe('append returns', () => { + it('TuiYear {year: 2000} if passed value was {}', () => { expect(y2000.append({}).year).toBe(2000); }); - it(`TuiYear {year: 2000} if passed value was {year: 0}`, () => { + it('TuiYear {year: 2000} if passed value was {year: 0}', () => { expect(y2000.append({year: 0}).year).toBe(2000); }); - it(`TuiYear {year: 2001} if passed value was {year: 1}`, () => { + it('TuiYear {year: 2001} if passed value was {year: 1}', () => { expect(y2000.append({year: 1}).year).toBe(2001); }); - it(`TuiYear {year: 1999} if passed value was {year: -1}`, () => { + it('TuiYear {year: 1999} if passed value was {year: -1}', () => { expect(y2000.append({year: -1}).year).toBe(1999); }); - it(`TuiYear {year: 2100} if passed value was {year: 100}`, () => { + it('TuiYear {year: 2100} if passed value was {year: 100}', () => { expect(y2000.append({year: 100}).year).toBe(2100); }); - it(`TuiYear {year: 1900} if passed value was {year: -100}`, () => { + it('TuiYear {year: 1900} if passed value was {year: -100}', () => { expect(y2000.append({year: -100}).year).toBe(1900); }); - it(`TuiYear {year: 1900} if passed value was {year: 100}, true`, () => { + it('TuiYear {year: 1900} if passed value was {year: 100}, true', () => { expect(y2000.append({year: 100}, true).year).toBe(1900); }); }); - describe(`valueOf returns`, () => { - it(`the primitive value of a TuiYear object`, () => { + describe('valueOf returns', () => { + it('the primitive value of a TuiYear object', () => { const year = new TuiYear(2000); expect(Number(year)).toBeInstanceOf(Number); @@ -674,34 +470,34 @@ describe(`TuiYear`, () => { }); }); - describe(`Symbol.toPrimitive returns`, () => { - it(`a number if the hint is number`, () => { + describe('Symbol.toPrimitive returns', () => { + it('a number if the hint is number', () => { const year = new TuiYear(1701); expect(Number(year)).toBeInstanceOf(Number); expect(year.valueOf()).toBeInstanceOf(Number); - expect(year[Symbol.toPrimitive](`number`)).toBeInstanceOf(Number); + expect(year[Symbol.toPrimitive]('number')).toBeInstanceOf(Number); }); - it(`a string if the hint is string`, () => { + it('a string if the hint is string', () => { const year = new TuiYear(2201); expect(String(year)).toBeInstanceOf(String); expect(year.toString()).toBeInstanceOf(String); - expect(year[Symbol.toPrimitive](`string`)).toBeInstanceOf(String); + expect(year[Symbol.toPrimitive]('string')).toBeInstanceOf(String); }); - it(`a string if the hint is default`, () => { + it('a string if the hint is default', () => { const year = new TuiYear(2002); expect(`${year}`).toBeInstanceOf(String); - expect(year[Symbol.toPrimitive](`default`)).toBeInstanceOf(String); + expect(year[Symbol.toPrimitive]('default')).toBeInstanceOf(String); }); }); }); }); - it(`stringified value equals formatted`, () => { + it('stringified value equals formatted', () => { const month = new TuiYear(2000); expect(month.toString()).toBe(month.formattedYear); diff --git a/projects/cdk/date-time/time.ts b/projects/cdk/date-time/time.ts index 21f7231f305f6..faeee44fc5bbe 100644 --- a/projects/cdk/date-time/time.ts +++ b/projects/cdk/date-time/time.ts @@ -1,7 +1,7 @@ import {tuiAssert} from '@taiga-ui/cdk/classes'; import {TuiTimeLike} from '@taiga-ui/cdk/interfaces'; import {TuiTimeMode} from '@taiga-ui/cdk/types'; -import {inRange} from '@taiga-ui/cdk/utils/math'; +import {tuiInRange} from '@taiga-ui/cdk/utils/math'; import { HOURS_IN_DAY, @@ -43,13 +43,13 @@ export class TuiTime implements TuiTimeLike { ): boolean { return ( Number.isInteger(hours) && - inRange(hours, 0, HOURS_IN_DAY) && + tuiInRange(hours, 0, HOURS_IN_DAY) && Number.isInteger(minutes) && - inRange(minutes, 0, MINUTES_IN_HOUR) && + tuiInRange(minutes, 0, MINUTES_IN_HOUR) && Number.isInteger(seconds) && - inRange(seconds, 0, SECONDS_IN_MINUTE) && + tuiInRange(seconds, 0, SECONDS_IN_MINUTE) && Number.isInteger(ms) && - inRange(ms, 0, 1000) + tuiInRange(ms, 0, 1000) ); } @@ -78,7 +78,7 @@ export class TuiTime implements TuiTimeLike { static fromAbsoluteMilliseconds(milliseconds: number): TuiTime { tuiAssert.assert(Number.isInteger(milliseconds)); tuiAssert.assert( - inRange(milliseconds, 0, MILLISECONDS_IN_DAY), + tuiInRange(milliseconds, 0, MILLISECONDS_IN_DAY), `Milliseconds must be below ${MILLISECONDS_IN_DAY} (milliseconds in a day).`, ); diff --git a/projects/cdk/date-time/year.ts b/projects/cdk/date-time/year.ts index 1eb81831bcef8..2b8eea3291e5b 100644 --- a/projects/cdk/date-time/year.ts +++ b/projects/cdk/date-time/year.ts @@ -1,14 +1,8 @@ import {tuiAssert} from '@taiga-ui/cdk/classes'; import {TuiYearLike} from '@taiga-ui/cdk/interfaces'; -import {inRange, normalizeToIntNumber} from '@taiga-ui/cdk/utils/math'; +import {tuiInRange, tuiNormalizeToIntNumber} from '@taiga-ui/cdk/utils/math'; -import { - DAYS_IN_LEAP_YEAR, - DAYS_IN_NORMAL_YEAR, - DAYS_IN_WEEK, - MAX_YEAR, - MIN_YEAR, -} from './date-time'; +import {MAX_YEAR, MIN_YEAR} from './date-time'; /** * Immutable year object @@ -23,7 +17,7 @@ export class TuiYear implements TuiYearLike { * Checks year for validity */ static isValidYear(year: number): boolean { - return Number.isInteger(year) && inRange(year, MIN_YEAR, MAX_YEAR + 1); + return Number.isInteger(year) && tuiInRange(year, MIN_YEAR, MAX_YEAR + 1); } /** @@ -44,29 +38,6 @@ export class TuiYear implements TuiYearLike { return Math.ceil(year / 400) + (Math.ceil(year / 4) - Math.ceil(year / 100)); } - /** - * @deprecated DONT USE IT (will be deleted soon) - * - * Returns day of week offset of the beginning of the passed year - * - * @param year - * @param absoluteLeapYears amount of leap years prior to the passed one - * @return offset in days - */ - static getYearStartDaysOffset(year: number, absoluteLeapYears: number): number { - tuiAssert.assert(TuiYear.isValidYear(year)); - tuiAssert.assert(Number.isInteger(absoluteLeapYears)); - tuiAssert.assert(year >= absoluteLeapYears); - tuiAssert.assert(absoluteLeapYears >= 0); - - return ( - (absoluteLeapYears * DAYS_IN_LEAP_YEAR + - (year - absoluteLeapYears) * DAYS_IN_NORMAL_YEAR + - 5) % - DAYS_IN_WEEK - ); - } - static lengthBetween(from: TuiYear, to: TuiYear): number { return to.year - from.year; } @@ -75,7 +46,7 @@ export class TuiYear implements TuiYearLike { * Normalizes year by clamping it between min and max years */ protected static normalizeYearPart(year: number): number { - return normalizeToIntNumber(year, MIN_YEAR, MAX_YEAR); + return tuiNormalizeToIntNumber(year, MIN_YEAR, MAX_YEAR); } get formattedYear(): string { @@ -93,15 +64,6 @@ export class TuiYear implements TuiYearLike { return TuiYear.getAbsoluteLeapYears(this.year); } - /** - * @deprecated DONT USE IT (will be deleted soon) - * - * Returns day of week offset of the beginning of the current year - */ - get yearStartDaysOffset(): number { - return TuiYear.getYearStartDaysOffset(this.year, this.absoluteLeapYears); - } - /** * Passed year is after current */ diff --git a/projects/cdk/directives/focus-trap/focus-trap.directive.ts b/projects/cdk/directives/focus-trap/focus-trap.directive.ts index e9043fabd3606..329f8f45792c3 100644 --- a/projects/cdk/directives/focus-trap/focus-trap.directive.ts +++ b/projects/cdk/directives/focus-trap/focus-trap.directive.ts @@ -10,8 +10,8 @@ import { import {containsOrAfter} from '@taiga-ui/cdk/utils/dom'; import { blurNativeFocused, - getClosestFocusable, setNativeFocused, + tuiGetClosestFocusable, tuiGetNativeFocused, } from '@taiga-ui/cdk/utils/focus'; @@ -53,7 +53,7 @@ export class TuiFocusTrapDirective implements OnDestroy { return; } - const focusable = getClosestFocusable( + const focusable = tuiGetClosestFocusable( this.elementRef.nativeElement, false, this.elementRef.nativeElement, diff --git a/projects/cdk/exceptions/invalid-day.exception.ts b/projects/cdk/exceptions/invalid-day.exception.ts index 1edb9d92ffb71..c89c7718ec147 100644 --- a/projects/cdk/exceptions/invalid-day.exception.ts +++ b/projects/cdk/exceptions/invalid-day.exception.ts @@ -1,12 +1,5 @@ -/** - * @deprecated: use {@link TuiInvalidDayException} - * TODO: remove in v3.0 - */ -// eslint-disable-next-line @typescript-eslint/naming-convention -export class InvalidDayException extends Error { +export class TuiInvalidDayException extends Error { constructor(day: number) { super(`Invalid day: ${day}`); } } - -export class TuiInvalidDayException extends InvalidDayException {} diff --git a/projects/cdk/exceptions/invalid-month.exception.ts b/projects/cdk/exceptions/invalid-month.exception.ts index 54f197f68d886..b2c402299c6b6 100644 --- a/projects/cdk/exceptions/invalid-month.exception.ts +++ b/projects/cdk/exceptions/invalid-month.exception.ts @@ -1,12 +1,5 @@ -/** - * @deprecated: use {@link TuiInvalidMonthException} - * TODO: remove in v3.0 - */ -// eslint-disable-next-line @typescript-eslint/naming-convention -export class InvalidMonthException extends Error { +export class TuiInvalidMonthException extends Error { constructor(month: number) { super(`Invalid month: ${month}`); } } - -export class TuiInvalidMonthException extends InvalidMonthException {} diff --git a/projects/cdk/exceptions/invalid-year.exception.ts b/projects/cdk/exceptions/invalid-year.exception.ts index 4555b07cf45de..135af1140de5d 100644 --- a/projects/cdk/exceptions/invalid-year.exception.ts +++ b/projects/cdk/exceptions/invalid-year.exception.ts @@ -1,12 +1,5 @@ -/** - * @deprecated: use {@link TuiInvalidYearException} - * TODO: remove in v3.0 - */ -// eslint-disable-next-line @typescript-eslint/naming-convention -export class InvalidYearException extends Error { +export class TuiInvalidYearException extends Error { constructor(year: number) { super(`Invalid year: ${year}`); } } - -export class TuiInvalidYearException extends InvalidYearException {} diff --git a/projects/cdk/schematics/ng-update/tests/schematic-rename-types.spec.ts b/projects/cdk/schematics/ng-update/tests/schematic-rename-types.spec.ts index 6b6008c1dc44d..09a33806cecce 100644 --- a/projects/cdk/schematics/ng-update/tests/schematic-rename-types.spec.ts +++ b/projects/cdk/schematics/ng-update/tests/schematic-rename-types.spec.ts @@ -23,7 +23,7 @@ import { import { InputCountOptions } from '@taiga-ui/kit/components'; import { ScrollIntoViewDirective, CodeComponent } from '@taiga-ui/addon-doc'; import { TableBar } from '@taiga-ui/addon-tablebars'; -import { InvalidDayException, InvalidMonthException, InvalidYearException } from '@taiga-ui/cdk/exceptions'; +import { TuiInvalidDayException, TuiInvalidMonthException, TuiInvalidYearException } from '@taiga-ui/cdk/exceptions'; import { ButtonOptions, some, InputCountOptions, WithDateMaskPipeConfig } from '@taiga-ui/core/types'; import { InputPasswordOptions } from '@taiga-ui/kit/components/input-password'; import { TUI_INPUT_TIME_OPTIONS, InputTimeOptions, Country, RadioOptions } from '@taiga-ui/kit'; diff --git a/projects/cdk/utils/focus/get-closest-keyboard-focusable.ts b/projects/cdk/utils/focus/get-closest-keyboard-focusable.ts index 78f1487db5ea3..884ec2222ef47 100644 --- a/projects/cdk/utils/focus/get-closest-keyboard-focusable.ts +++ b/projects/cdk/utils/focus/get-closest-keyboard-focusable.ts @@ -1,10 +1,9 @@ import {svgNodeFilter} from '@taiga-ui/cdk/constants'; -import {isNativeKeyboardFocusable} from './is-native-keyboard-focusable'; -import {isNativeMouseFocusable} from './is-native-mouse-focusable'; +import {tuiIsNativeKeyboardFocusable} from './is-native-keyboard-focusable'; +import {tuiIsNativeMouseFocusable} from './is-native-mouse-focusable'; /** - * @deprecated: use {@link tuiGetClosestFocusable} instead * Finds the closest element that can be focused with a keyboard or mouse in theory * * @param initial current HTML element @@ -13,8 +12,7 @@ import {isNativeMouseFocusable} from './is-native-mouse-focusable'; * @param keyboard determine if only keyboard focus is of interest * */ -// eslint-disable-next-line @typescript-eslint/naming-convention -export function getClosestFocusable( +export function tuiGetClosestFocusable( initial: Element, prev: boolean = false, root: Node, @@ -24,7 +22,7 @@ export function getClosestFocusable( return null; } - const check = keyboard ? isNativeKeyboardFocusable : isNativeMouseFocusable; + const check = keyboard ? tuiIsNativeKeyboardFocusable : tuiIsNativeMouseFocusable; // Deprecated but ony this overload works in IE // Filter must be a function in IE, other modern browsers are compliant to this format @@ -51,10 +49,3 @@ export function getClosestFocusable( return null; } - -/** - * @deprecated: use {@link tuiGetClosestFocusable} instead - */ -export const getClosestKeyboardFocusable = getClosestFocusable; - -export const tuiGetClosestFocusable = getClosestFocusable; diff --git a/projects/cdk/utils/focus/is-native-keyboard-focusable.ts b/projects/cdk/utils/focus/is-native-keyboard-focusable.ts index 175990e9d1244..2c059c3afa8fa 100644 --- a/projects/cdk/utils/focus/is-native-keyboard-focusable.ts +++ b/projects/cdk/utils/focus/is-native-keyboard-focusable.ts @@ -1,40 +1,36 @@ /** - * @deprecated: use {@link tuiIsNativeKeyboardFocusable} instead * Checks for signs that element can be focused with keyboard. tabIndex above 0 is ignored to * only target natural focus order. Not checking the possibility of an element to * be focused, for example element can have display: none applied to it or any other * circumstances could prevent actual focus. */ -// eslint-disable-next-line @typescript-eslint/naming-convention -export function isNativeKeyboardFocusable(element: Element): boolean { - if (element.hasAttribute(`disabled`) || element.getAttribute(`tabIndex`) === `-1`) { +export function tuiIsNativeKeyboardFocusable(element: Element): boolean { + if (element.hasAttribute('disabled') || element.getAttribute('tabIndex') === '-1') { return false; } // TODO: iframe warning if ( (element instanceof HTMLElement && element.isContentEditable) || - element.getAttribute(`tabIndex`) === `0` + element.getAttribute('tabIndex') === '0' ) { return true; } switch (element.tagName) { - case `BUTTON`: - case `SELECT`: - case `TEXTAREA`: + case 'BUTTON': + case 'SELECT': + case 'TEXTAREA': return true; - case `VIDEO`: - case `AUDIO`: - return element.hasAttribute(`controls`); - case `INPUT`: - return element.getAttribute(`type`) !== `hidden`; - case `A`: - case `LINK`: - return element.hasAttribute(`href`); + case 'VIDEO': + case 'AUDIO': + return element.hasAttribute('controls'); + case 'INPUT': + return element.getAttribute('type') !== 'hidden'; + case 'A': + case 'LINK': + return element.hasAttribute('href'); default: return false; } } - -export const tuiIsNativeKeyboardFocusable = isNativeKeyboardFocusable; diff --git a/projects/cdk/utils/focus/is-native-mouse-focusable.ts b/projects/cdk/utils/focus/is-native-mouse-focusable.ts index cb10c085d9eb3..382d6e9283c68 100644 --- a/projects/cdk/utils/focus/is-native-mouse-focusable.ts +++ b/projects/cdk/utils/focus/is-native-mouse-focusable.ts @@ -1,14 +1,12 @@ -import {isNativeKeyboardFocusable} from './is-native-keyboard-focusable'; +import {tuiIsNativeKeyboardFocusable} from './is-native-keyboard-focusable'; /** - * @deprecated: use {@link tuiIsNativeMouseFocusable} instead */ // eslint-disable-next-line @typescript-eslint/naming-convention -export function isNativeMouseFocusable(element: Element): boolean { +export function tuiIsNativeMouseFocusable(element: Element): boolean { return ( - !element.hasAttribute(`disabled`) && - (element.getAttribute(`tabIndex`) === `-1` || isNativeKeyboardFocusable(element)) + !element.hasAttribute('disabled') && + (element.getAttribute('tabIndex') === '-1' || + tuiIsNativeKeyboardFocusable(element)) ); } - -export const tuiIsNativeMouseFocusable = isNativeMouseFocusable; diff --git a/projects/cdk/utils/focus/tests/get-closest-keyboard-focusable.spec.ts b/projects/cdk/utils/focus/tests/get-closest-keyboard-focusable.spec.ts index b1741a468f0f9..715cf936900c1 100644 --- a/projects/cdk/utils/focus/tests/get-closest-keyboard-focusable.spec.ts +++ b/projects/cdk/utils/focus/tests/get-closest-keyboard-focusable.spec.ts @@ -1,11 +1,11 @@ -import {getClosestKeyboardFocusable} from '../get-closest-keyboard-focusable'; +import {tuiGetClosestFocusable} from '../get-closest-keyboard-focusable'; describe(`getClosestKeyboardFocusable`, () => { it(`returns null if root has no document`, () => { const root: Node = {} as unknown as Node; const divElement = document.createElement(`div`); - expect(getClosestKeyboardFocusable(divElement, true, root)).toBe(null); + expect(tuiGetClosestFocusable(divElement, true, root)).toBe(null); }); it(`returns closest focusable if there is backwords`, () => { @@ -17,7 +17,7 @@ describe(`getClosestKeyboardFocusable`, () => { root.appendChild(divElement); document.body.appendChild(root); - expect(getClosestKeyboardFocusable(divElement, true, root)).toBe(buttonElement); + expect(tuiGetClosestFocusable(divElement, true, root)).toBe(buttonElement); document.body.removeChild(root); }); @@ -31,7 +31,7 @@ describe(`getClosestKeyboardFocusable`, () => { root.appendChild(buttonElement); document.body.appendChild(root); - expect(getClosestKeyboardFocusable(divElement, false, root)).toBe(buttonElement); + expect(tuiGetClosestFocusable(divElement, false, root)).toBe(buttonElement); document.body.removeChild(root); }); @@ -43,7 +43,7 @@ describe(`getClosestKeyboardFocusable`, () => { root.appendChild(divElement); document.body.appendChild(root); - expect(getClosestKeyboardFocusable(divElement, undefined, root)).toBe(null); + expect(tuiGetClosestFocusable(divElement, undefined, root)).toBe(null); document.body.removeChild(root); }); diff --git a/projects/cdk/utils/focus/tests/is-native-focusable.spec.ts b/projects/cdk/utils/focus/tests/is-native-focusable.spec.ts index abbb52bdadefc..bbe22fd0e2e21 100644 --- a/projects/cdk/utils/focus/tests/is-native-focusable.spec.ts +++ b/projects/cdk/utils/focus/tests/is-native-focusable.spec.ts @@ -1,10 +1,10 @@ -import {isNativeKeyboardFocusable} from '../is-native-keyboard-focusable'; +import {tuiIsNativeKeyboardFocusable} from '../is-native-keyboard-focusable'; describe(`isNativeKeyboardFocusable`, () => { it(`DIV not focusable`, () => { const element = document.createElement(`DIV`); - expect(isNativeKeyboardFocusable(element)).toBe(false); + expect(tuiIsNativeKeyboardFocusable(element)).toBe(false); }); it(`DIV with tabindex = 0 is focusable`, () => { @@ -12,25 +12,25 @@ describe(`isNativeKeyboardFocusable`, () => { element.setAttribute(`tabindex`, `0`); - expect(isNativeKeyboardFocusable(element)).toBe(true); + expect(tuiIsNativeKeyboardFocusable(element)).toBe(true); }); it(`BUTTON is focusable`, () => { const element = document.createElement(`BUTTON`); - expect(isNativeKeyboardFocusable(element)).toBe(true); + expect(tuiIsNativeKeyboardFocusable(element)).toBe(true); }); it(`SELECT is focusable`, () => { const element = document.createElement(`SELECT`); - expect(isNativeKeyboardFocusable(element)).toBe(true); + expect(tuiIsNativeKeyboardFocusable(element)).toBe(true); }); it(`TEXTAREA is focusable`, () => { const element = document.createElement(`TEXTAREA`); - expect(isNativeKeyboardFocusable(element)).toBe(true); + expect(tuiIsNativeKeyboardFocusable(element)).toBe(true); }); it(`disabled BUTTON is not focusable`, () => { @@ -38,19 +38,19 @@ describe(`isNativeKeyboardFocusable`, () => { element.setAttribute(`disabled`, ``); - expect(isNativeKeyboardFocusable(element)).toBe(false); + expect(tuiIsNativeKeyboardFocusable(element)).toBe(false); }); it(`VIDEO is not focusable`, () => { const element = document.createElement(`VIDEO`); - expect(isNativeKeyboardFocusable(element)).toBe(false); + expect(tuiIsNativeKeyboardFocusable(element)).toBe(false); }); it(`AUDIO is not focusable`, () => { const element = document.createElement(`AUDIO`); - expect(isNativeKeyboardFocusable(element)).toBe(false); + expect(tuiIsNativeKeyboardFocusable(element)).toBe(false); }); it(`VIDEO with controls is focusable`, () => { @@ -58,7 +58,7 @@ describe(`isNativeKeyboardFocusable`, () => { element.setAttribute(`controls`, ``); - expect(isNativeKeyboardFocusable(element)).toBe(true); + expect(tuiIsNativeKeyboardFocusable(element)).toBe(true); }); it(`AUDIO with controls is focusable`, () => { @@ -66,19 +66,19 @@ describe(`isNativeKeyboardFocusable`, () => { element.setAttribute(`controls`, ``); - expect(isNativeKeyboardFocusable(element)).toBe(true); + expect(tuiIsNativeKeyboardFocusable(element)).toBe(true); }); it(`A is not focusable`, () => { const element = document.createElement(`A`); - expect(isNativeKeyboardFocusable(element)).toBe(false); + expect(tuiIsNativeKeyboardFocusable(element)).toBe(false); }); it(`LINK is not focusable`, () => { const element = document.createElement(`LINK`); - expect(isNativeKeyboardFocusable(element)).toBe(false); + expect(tuiIsNativeKeyboardFocusable(element)).toBe(false); }); it(`A with href is focusable`, () => { @@ -86,7 +86,7 @@ describe(`isNativeKeyboardFocusable`, () => { element.setAttribute(`href`, ``); - expect(isNativeKeyboardFocusable(element)).toBe(true); + expect(tuiIsNativeKeyboardFocusable(element)).toBe(true); }); it(`LINK with href is focusable`, () => { @@ -94,13 +94,13 @@ describe(`isNativeKeyboardFocusable`, () => { element.setAttribute(`href`, ``); - expect(isNativeKeyboardFocusable(element)).toBe(true); + expect(tuiIsNativeKeyboardFocusable(element)).toBe(true); }); it(`INPUT is focusable`, () => { const element = document.createElement(`INPUT`); - expect(isNativeKeyboardFocusable(element)).toBe(true); + expect(tuiIsNativeKeyboardFocusable(element)).toBe(true); }); it(`INPUT type="hidden" is not focusable`, () => { @@ -108,6 +108,6 @@ describe(`isNativeKeyboardFocusable`, () => { element.setAttribute(`type`, `hidden`); - expect(isNativeKeyboardFocusable(element)).toBe(false); + expect(tuiIsNativeKeyboardFocusable(element)).toBe(false); }); }); diff --git a/projects/cdk/utils/focus/tests/is-native-mouse-focusable.spec.ts b/projects/cdk/utils/focus/tests/is-native-mouse-focusable.spec.ts index f24f310c316be..6cff6f390922e 100644 --- a/projects/cdk/utils/focus/tests/is-native-mouse-focusable.spec.ts +++ b/projects/cdk/utils/focus/tests/is-native-mouse-focusable.spec.ts @@ -1,16 +1,16 @@ -import {isNativeMouseFocusable} from '../is-native-mouse-focusable'; +import {tuiIsNativeMouseFocusable} from '../is-native-mouse-focusable'; describe(`isNativeMouseFocusable`, () => { it(`DIV is not mouse focusable`, () => { const element = document.createElement(`div`); - expect(isNativeMouseFocusable(element)).toEqual(false); + expect(tuiIsNativeMouseFocusable(element)).toEqual(false); }); it(`BUTTON is mouse focusable`, () => { const element = document.createElement(`button`); - expect(isNativeMouseFocusable(element)).toEqual(true); + expect(tuiIsNativeMouseFocusable(element)).toEqual(true); }); it(`disabled BUTTON is not mouse focusable`, () => { @@ -18,7 +18,7 @@ describe(`isNativeMouseFocusable`, () => { element.setAttribute(`disabled`, ``); - expect(isNativeMouseFocusable(element)).toEqual(false); + expect(tuiIsNativeMouseFocusable(element)).toEqual(false); }); it(`BUTTON with tabIndex === -1 is not mouse focusable`, () => { @@ -26,6 +26,6 @@ describe(`isNativeMouseFocusable`, () => { element.setAttribute(`disabled`, ``); - expect(isNativeMouseFocusable(element)).toEqual(false); + expect(tuiIsNativeMouseFocusable(element)).toEqual(false); }); }); diff --git a/projects/cdk/utils/math/in-range.ts b/projects/cdk/utils/math/in-range.ts index c7e4a3e6bd6bb..111611a128192 100644 --- a/projects/cdk/utils/math/in-range.ts +++ b/projects/cdk/utils/math/in-range.ts @@ -1,15 +1,10 @@ import {tuiAssert} from '@taiga-ui/cdk/classes'; -/** - * @deprecated: use {@link tuiInRange} instead - * Checks if the value is in range - * - * @param value - * @param fromInclude lower inclusive limit - * @param toExclude upper exclusive limit - */ -// eslint-disable-next-line @typescript-eslint/naming-convention -export function inRange(value: number, fromInclude: number, toExclude: number): boolean { +export function tuiInRange( + value: number, + fromInclude: number, + toExclude: number, +): boolean { tuiAssert.assert(!isNaN(value)); tuiAssert.assert(!isNaN(fromInclude)); tuiAssert.assert(!isNaN(toExclude)); @@ -17,5 +12,3 @@ export function inRange(value: number, fromInclude: number, toExclude: number): return value >= fromInclude && value < toExclude; } - -export const tuiInRange = inRange; diff --git a/projects/cdk/utils/math/normalize-to-int-number.ts b/projects/cdk/utils/math/normalize-to-int-number.ts index 9da6930e9ad0a..d395ad225d41e 100644 --- a/projects/cdk/utils/math/normalize-to-int-number.ts +++ b/projects/cdk/utils/math/normalize-to-int-number.ts @@ -1,7 +1,6 @@ import {tuiAssert} from '@taiga-ui/cdk/classes'; /** - * @deprecated: use {@link tuiNormalizeToIntNumber} instead * Normalizes any number to an integer within inclusive range * * @param value @@ -9,8 +8,7 @@ import {tuiAssert} from '@taiga-ui/cdk/classes'; * @param max upper inclusive integer * @return an integer between min and max inclusive */ -// eslint-disable-next-line @typescript-eslint/naming-convention -export function normalizeToIntNumber(value: number, min: number, max: number): number { +export function tuiNormalizeToIntNumber(value: number, min: number, max: number): number { tuiAssert.assert(Number.isInteger(min)); tuiAssert.assert(Number.isInteger(max)); tuiAssert.assert(min <= max); @@ -25,5 +23,3 @@ export function normalizeToIntNumber(value: number, min: number, max: number): n return Math.round(value); } - -export const tuiNormalizeToIntNumber = normalizeToIntNumber; diff --git a/projects/cdk/utils/math/test/in-range.spec.ts b/projects/cdk/utils/math/test/in-range.spec.ts index 0bf271f347dec..372a4e35ee856 100644 --- a/projects/cdk/utils/math/test/in-range.spec.ts +++ b/projects/cdk/utils/math/test/in-range.spec.ts @@ -1,27 +1,27 @@ -import {inRange} from '../in-range'; +import {tuiInRange} from '../in-range'; -describe(`inRange returns`, () => { - describe(`false if value`, () => { - it(`is smaller than fromInclude`, () => { - expect(inRange(2, 3, 5)).toBe(false); +describe('inRange returns', () => { + describe('false if value', () => { + it('is smaller than fromInclude', () => { + expect(tuiInRange(2, 3, 5)).toBe(false); }); - it(`equals to toExclude`, () => { - expect(inRange(5, 3, 5)).toBe(false); + it('equals to toExclude', () => { + expect(tuiInRange(5, 3, 5)).toBe(false); }); - it(`is bigger than toExclude`, () => { - expect(inRange(6, 3, 5)).toBe(false); + it('is bigger than toExclude', () => { + expect(tuiInRange(6, 3, 5)).toBe(false); }); }); - describe(`true if value`, () => { - it(`equals to fromInclude`, () => { - expect(inRange(3, 3, 5)).toBe(true); + describe('true if value', () => { + it('equals to fromInclude', () => { + expect(tuiInRange(3, 3, 5)).toBe(true); }); - it(`is bigger than fromInclude but smaller than toExclude`, () => { - expect(inRange(4, 3, 5)).toBe(true); + it('is bigger than fromInclude but smaller than toExclude', () => { + expect(tuiInRange(4, 3, 5)).toBe(true); }); }); }); diff --git a/projects/cdk/utils/math/test/normalize-to-int-number.spec.ts b/projects/cdk/utils/math/test/normalize-to-int-number.spec.ts index 9f8f080c7758e..37d05dfb849ea 100644 --- a/projects/cdk/utils/math/test/normalize-to-int-number.spec.ts +++ b/projects/cdk/utils/math/test/normalize-to-int-number.spec.ts @@ -1,30 +1,30 @@ -import {normalizeToIntNumber} from '../normalize-to-int-number'; +import {tuiNormalizeToIntNumber} from '../normalize-to-int-number'; -describe(`normalizeToIntNumber`, () => { +describe('normalizeToIntNumber', () => { const min = -10; const max = 10; - it(`NaN`, () => { - expect(normalizeToIntNumber(NaN, min, max)).toBe(min); + it('NaN', () => { + expect(tuiNormalizeToIntNumber(NaN, min, max)).toBe(min); }); - it(`0.1`, () => { - expect(normalizeToIntNumber(0.1, min, max)).toBe(0); + it('0.1', () => { + expect(tuiNormalizeToIntNumber(0.1, min, max)).toBe(0); }); - it(`5.7`, () => { - expect(normalizeToIntNumber(5.7, min, max)).toBe(6); + it('5.7', () => { + expect(tuiNormalizeToIntNumber(5.7, min, max)).toBe(6); }); - it(`0.1`, () => { - expect(normalizeToIntNumber(0.1, min, max)).toBe(0); + it('0.1', () => { + expect(tuiNormalizeToIntNumber(0.1, min, max)).toBe(0); }); - it(`Infinity`, () => { - expect(normalizeToIntNumber(Infinity, min, max)).toBe(max); + it('Infinity', () => { + expect(tuiNormalizeToIntNumber(Infinity, min, max)).toBe(max); }); - it(`-Infinity`, () => { - expect(normalizeToIntNumber(-Infinity, min, max)).toBe(min); + it('-Infinity', () => { + expect(tuiNormalizeToIntNumber(-Infinity, min, max)).toBe(min); }); }); diff --git a/projects/core/components/data-list/data-list-dropdown-manager.directive.ts b/projects/core/components/data-list/data-list-dropdown-manager.directive.ts index 938afb2de4af6..4ddacf470d5ef 100644 --- a/projects/core/components/data-list/data-list-dropdown-manager.directive.ts +++ b/projects/core/components/data-list/data-list-dropdown-manager.directive.ts @@ -7,10 +7,10 @@ import { } from '@angular/core'; import { EMPTY_QUERY, - getClosestKeyboardFocusable, itemsQueryListObservable, preventDefault, setNativeFocused, + tuiGetClosestFocusable, tuiPure, typedFromEvent, } from '@taiga-ui/cdk'; @@ -160,7 +160,7 @@ export class TuiDataListDropdownManagerDirective implements AfterViewInit { return; } - const item = getClosestKeyboardFocusable( + const item = tuiGetClosestFocusable( content.nativeElement, false, content.nativeElement, diff --git a/projects/core/components/dropdown-box/dropdown-box.component.ts b/projects/core/components/dropdown-box/dropdown-box.component.ts index 3b38bcbec8753..6d15c9ef2d1df 100644 --- a/projects/core/components/dropdown-box/dropdown-box.component.ts +++ b/projects/core/components/dropdown-box/dropdown-box.component.ts @@ -12,13 +12,13 @@ import { import {ANIMATION_FRAME, WINDOW} from '@ng-web-apis/common'; import { AbstractTuiPortalHostComponent, - getClosestFocusable, - inRange, POLLING_TIME, TuiActiveZoneDirective, tuiAssertIsElement, TuiDestroyService, TuiDropdownHostComponent, + tuiGetClosestFocusable, + tuiInRange, TuiOverscrollMode, tuiPure, tuiPx, @@ -211,7 +211,7 @@ export class TuiDropdownBoxComponent implements AfterViewChecked { case 'left': if ( right + DEFAULT_MARGIN > viewportWidth || - inRange(left + DEFAULT_MARGIN, 0, viewportWidth) + tuiInRange(left + DEFAULT_MARGIN, 0, viewportWidth) ) { style.left = tuiPx(left); style.right = 'auto'; @@ -223,7 +223,7 @@ export class TuiDropdownBoxComponent implements AfterViewChecked { break; case 'right': if ( - inRange(right + DEFAULT_MARGIN, 0, viewportWidth) || + tuiInRange(right + DEFAULT_MARGIN, 0, viewportWidth) || left + DEFAULT_MARGIN > viewportWidth ) { style.left = 'auto'; @@ -382,10 +382,10 @@ export class TuiDropdownBoxComponent implements AfterViewChecked { tuiAssertIsElement(host); - let focusable = getClosestFocusable(host, previous, root); + let focusable = tuiGetClosestFocusable(host, previous, root); while (focusable !== null && host.contains(focusable)) { - focusable = getClosestFocusable(focusable, previous, root); + focusable = tuiGetClosestFocusable(focusable, previous, root); } focusable?.focus(); diff --git a/projects/core/components/hosted-dropdown/hosted-dropdown.component.ts b/projects/core/components/hosted-dropdown/hosted-dropdown.component.ts index 729c6a678f513..73e6860793618 100644 --- a/projects/core/components/hosted-dropdown/hosted-dropdown.component.ts +++ b/projects/core/components/hosted-dropdown/hosted-dropdown.component.ts @@ -13,16 +13,16 @@ import { ViewChild, } from '@angular/core'; import { - getClosestFocusable, isElementEditable, - isNativeKeyboardFocusable, setNativeFocused, TUI_FOCUSABLE_ITEM_ACCESSOR, TuiActiveZoneDirective, TuiContextWithImplicit, tuiDefaultProp, TuiFocusableElementAccessor, + tuiGetClosestFocusable, tuiIsNativeFocusedIn, + tuiIsNativeKeyboardFocusable, TuiNativeFocusableElement, } from '@taiga-ui/cdk'; import {TuiDropdownDirective} from '@taiga-ui/core/directives/dropdown'; @@ -96,9 +96,9 @@ export class TuiHostedDropdownComponent implements TuiFocusableElementAccessor { } get nativeFocusableElement(): TuiNativeFocusableElement | null { - return isNativeKeyboardFocusable(this.host) + return tuiIsNativeKeyboardFocusable(this.host) ? this.host - : getClosestFocusable(this.host, false, this.elementRef.nativeElement); + : tuiGetClosestFocusable(this.host, false, this.elementRef.nativeElement); } @HostBinding(`class._hosted_dropdown_focused`) @@ -223,7 +223,7 @@ export class TuiHostedDropdownComponent implements TuiFocusableElementAccessor { const initial = first ? this.wrapper.nativeElement : this.wrapper.nativeElement.nextElementSibling; - const focusable = getClosestFocusable( + const focusable = tuiGetClosestFocusable( initial, !first, this.wrapper.nativeElement, diff --git a/projects/core/components/primitive-year-picker/primitive-year-picker.component.ts b/projects/core/components/primitive-year-picker/primitive-year-picker.component.ts index 51c407cad47bf..176b5cac2028a 100644 --- a/projects/core/components/primitive-year-picker/primitive-year-picker.component.ts +++ b/projects/core/components/primitive-year-picker/primitive-year-picker.component.ts @@ -8,12 +8,12 @@ import { } from '@angular/core'; import { ALWAYS_FALSE_HANDLER, - inRange, TUI_FIRST_DAY, TUI_LAST_DAY, TuiBooleanHandler, TuiDayRange, tuiDefaultProp, + tuiInRange, TuiMonth, TuiMonthRange, TuiYear, @@ -176,7 +176,7 @@ export class TuiPrimitiveYearPickerComponent { return false; } - return inRange( + return tuiInRange( item, Math.min(value.from.year, hoveredItem), Math.max(value.from.year, hoveredItem), diff --git a/projects/core/pipes/calendar-sheet/utils.ts b/projects/core/pipes/calendar-sheet/utils.ts index dec6dbba98cd6..2e83071f919d5 100644 --- a/projects/core/pipes/calendar-sheet/utils.ts +++ b/projects/core/pipes/calendar-sheet/utils.ts @@ -1,9 +1,9 @@ import { DAYS_IN_WEEK, - inRange, tuiAssert, TuiDay, TuiDayOfWeek, + tuiInRange, TuiMonth, } from '@taiga-ui/cdk'; @@ -55,9 +55,9 @@ export const getDayFromMonthRowCol = ({ firstDayOfWeek: TuiDayOfWeek; }): TuiDay => { tuiAssert.assert(Number.isInteger(rowIndex)); - tuiAssert.assert(inRange(rowIndex, 0, 6)); + tuiAssert.assert(tuiInRange(rowIndex, 0, 6)); tuiAssert.assert(Number.isInteger(colIndex)); - tuiAssert.assert(inRange(colIndex, 0, DAYS_IN_WEEK)); + tuiAssert.assert(tuiInRange(colIndex, 0, DAYS_IN_WEEK)); let day = rowIndex * DAYS_IN_WEEK + diff --git a/projects/demo/src/modules/utils/math/examples/2/index.ts b/projects/demo/src/modules/utils/math/examples/2/index.ts index 6c287e39a2618..d6dbe3408d60a 100644 --- a/projects/demo/src/modules/utils/math/examples/2/index.ts +++ b/projects/demo/src/modules/utils/math/examples/2/index.ts @@ -2,7 +2,7 @@ import {Component} from '@angular/core'; import {FormControl, FormGroup} from '@angular/forms'; import {changeDetection} from '@demo/emulate/change-detection'; import {encapsulation} from '@demo/emulate/encapsulation'; -import {inRange} from '@taiga-ui/cdk'; +import {tuiInRange} from '@taiga-ui/cdk'; @Component({ selector: `tui-math-example-2`, @@ -21,6 +21,6 @@ export class TuiMathExample2 { get ranged(): boolean { const {value, fromInclude, toExclude} = this.parametersForm.value; - return inRange(value, fromInclude, toExclude); + return tuiInRange(value, fromInclude, toExclude); } } diff --git a/projects/demo/src/modules/utils/math/examples/3/index.ts b/projects/demo/src/modules/utils/math/examples/3/index.ts index 067d929862a3f..bf83593ca45e7 100644 --- a/projects/demo/src/modules/utils/math/examples/3/index.ts +++ b/projects/demo/src/modules/utils/math/examples/3/index.ts @@ -2,7 +2,7 @@ import {Component} from '@angular/core'; import {FormControl, FormGroup} from '@angular/forms'; import {changeDetection} from '@demo/emulate/change-detection'; import {encapsulation} from '@demo/emulate/encapsulation'; -import {normalizeToIntNumber} from '@taiga-ui/cdk'; +import {tuiNormalizeToIntNumber} from '@taiga-ui/cdk'; @Component({ selector: `tui-math-example-3`, @@ -21,6 +21,6 @@ export class TuiMathExample3 { get normalized(): number { const {value, min, max} = this.parametersForm.value; - return normalizeToIntNumber(value, min, max); + return tuiNormalizeToIntNumber(value, min, max); } } diff --git a/projects/kit/components/tabs/tabs-with-more/tabs-with-more.component.ts b/projects/kit/components/tabs/tabs-with-more/tabs-with-more.component.ts index dbc4278a18f45..bf971a7e0690e 100644 --- a/projects/kit/components/tabs/tabs-with-more/tabs-with-more.component.ts +++ b/projects/kit/components/tabs/tabs-with-more/tabs-with-more.component.ts @@ -16,7 +16,6 @@ import { } from '@angular/core'; import { EMPTY_QUERY, - getClosestFocusable, setNativeFocused, toInt, TuiActiveZoneDirective, @@ -24,6 +23,7 @@ import { tuiClamp, TuiContextWithImplicit, tuiDefaultProp, + tuiGetClosestFocusable, tuiIsNativeFocused, TuiItemDirective, } from '@taiga-ui/cdk'; @@ -181,7 +181,7 @@ export class TuiTabsWithMoreComponent implements AfterViewInit { onWrapperArrow(event: Event, wrapper: HTMLElement, prev: boolean): void { const button: HTMLButtonElement = event.target as HTMLButtonElement; - const target = getClosestFocusable(button, prev, wrapper); + const target = tuiGetClosestFocusable(button, prev, wrapper); if (target) { setNativeFocused(target); diff --git a/projects/kit/directives/dropdown-context/dropdown-context.directive.ts b/projects/kit/directives/dropdown-context/dropdown-context.directive.ts index 5284558600cdb..4820eccfdb65c 100644 --- a/projects/kit/directives/dropdown-context/dropdown-context.directive.ts +++ b/projects/kit/directives/dropdown-context/dropdown-context.directive.ts @@ -11,12 +11,12 @@ import { } from '@angular/core'; import { EMPTY_CLIENT_RECT, - getClosestFocusable, setNativeFocused, TuiActiveZoneDirective, tuiDefaultProp, TuiDestroyService, TuiDropdownPortalService, + tuiGetClosestFocusable, tuiGetNativeFocused, tuiPointToClientRect, } from '@taiga-ui/cdk'; @@ -118,7 +118,7 @@ export class TuiDropdownContextDirective const nextEl = this.dropdownContent.nextElementSibling; const initial = down || !this.checkIsFocusableElement(nextEl) ? this.dropdownContent : nextEl; - const focusable = getClosestFocusable(initial, !down, this.dropdownContent); + const focusable = tuiGetClosestFocusable(initial, !down, this.dropdownContent); if (focusable === null) { return; diff --git a/projects/kit/directives/dropdown-hover/dropdown-hover.directive.ts b/projects/kit/directives/dropdown-hover/dropdown-hover.directive.ts index cc700f599bb28..066393681ada9 100644 --- a/projects/kit/directives/dropdown-hover/dropdown-hover.directive.ts +++ b/projects/kit/directives/dropdown-hover/dropdown-hover.directive.ts @@ -1,9 +1,9 @@ import {Directive, ElementRef, HostListener, Inject} from '@angular/core'; import { - getClosestFocusable, isPresent, setNativeMouseFocused, TuiDestroyService, + tuiGetClosestFocusable, tuiIsNativeFocusedIn, typedFromEvent, } from '@taiga-ui/cdk'; @@ -86,7 +86,7 @@ export class TuiDropdownHoverDirective { return; } - const focusable = getClosestFocusable(host, false, host, false); + const focusable = tuiGetClosestFocusable(host, false, host, false); if (focusable) { setNativeMouseFocused(focusable); diff --git a/projects/kit/internal/primitive-calendar-range/test/primitive-calendar-range.component.spec.ts b/projects/kit/internal/primitive-calendar-range/test/primitive-calendar-range.component.spec.ts index f7c80232cc3eb..2928a306de448 100644 --- a/projects/kit/internal/primitive-calendar-range/test/primitive-calendar-range.component.spec.ts +++ b/projects/kit/internal/primitive-calendar-range/test/primitive-calendar-range.component.spec.ts @@ -7,7 +7,7 @@ import {configureTestSuite} from '@taiga-ui/testing'; import {TuiPrimitiveCalendarRangeComponent} from '../primitive-calendar-range.component'; import {TuiPrimitiveCalendarRangeModule} from '../primitive-calendar-range.module'; -describe(`PrimitiveRangeCalendar component`, () => { +describe('PrimitiveRangeCalendar component', () => { @Component({ template: ` @@ -36,20 +36,20 @@ describe(`PrimitiveRangeCalendar component`, () => { component = testComponent.component; }); - describe(`viewedMonthFirst`, () => { - it(`When initialized without value, sets defaultViewedMonthFirst`, () => { + describe('viewedMonthFirst', () => { + it('When initialized without value, sets defaultViewedMonthFirst', () => { expect(component.userViewedMonthFirst).toBe( component.defaultViewedMonthFirst, ); }); - it(`When initialized without value and defaultViewedMonthSecond shows the month of the local date`, () => { - expect(component.userViewedMonthFirst.formattedMonth).toBe( - TuiMonth.currentLocal().formattedMonth, + it('When initialized without value and defaultViewedMonthSecond shows the month of the local date', () => { + expect(component.userViewedMonthFirst.toString()).toBe( + TuiMonth.currentLocal().toString(), ); }); - it(`Returns max when initialized with max less than default`, () => { + it('Returns max when initialized with max less than default', () => { const maxDate = new TuiDay(2000, 1, 1); component.max = maxDate; @@ -57,7 +57,7 @@ describe(`PrimitiveRangeCalendar component`, () => { expect(component.userViewedMonthFirst).toEqual(maxDate.append({month: -1})); }); - it(`Returns min when initialized with default less than min`, () => { + it('Returns min when initialized with default less than min', () => { const minDate = new TuiDay(2024, 1, 1); component.min = minDate; @@ -66,24 +66,24 @@ describe(`PrimitiveRangeCalendar component`, () => { }); }); - describe(`viewedMonthSecond`, () => { - it(`When initialized without value, sets defaultViewedMonthSecond`, () => { + describe('viewedMonthSecond', () => { + it('When initialized without value, sets defaultViewedMonthSecond', () => { expect(component.userViewedMonthSecond).toBe( component.defaultViewedMonthSecond, ); }); - it(`When initialized without value and defaultViewedMonthSecond shows the next local date after month`, () => { - const formattedNextMonth = TuiMonth.currentLocal().append({ - month: 1, - }).formattedMonth; + it('When initialized without value and defaultViewedMonthSecond shows the next local date after month', () => { + const formattedNextMonth = TuiMonth.currentLocal() + .append({ + month: 1, + }) + .toString(); - expect(component.userViewedMonthSecond.formattedMonth).toBe( - formattedNextMonth, - ); + expect(component.userViewedMonthSecond.toString()).toBe(formattedNextMonth); }); - it(`Returns max when initialized with max less than default`, () => { + it('Returns max when initialized with max less than default', () => { const maxDate = new TuiDay(2000, 1, 1); component.max = maxDate; @@ -91,7 +91,7 @@ describe(`PrimitiveRangeCalendar component`, () => { expect(component.userViewedMonthSecond).toEqual(maxDate); }); - it(`Returns min when initialized with default less than min`, () => { + it('Returns min when initialized with default less than min', () => { const minDate = new TuiDay(2024, 1, 1); component.min = minDate; @@ -100,14 +100,14 @@ describe(`PrimitiveRangeCalendar component`, () => { }); }); - describe(`cappedUserViewedMonthSecond`, () => { - it(`returns userViewedMonthSecond if it is less than max`, () => { + describe('cappedUserViewedMonthSecond', () => { + it('returns userViewedMonthSecond if it is less than max', () => { expect(component.cappedUserViewedMonthSecond).toBe( component.userViewedMonthSecond, ); }); - it(`returns max if it is less than userViewedMonthSecond`, () => { + it('returns max if it is less than userViewedMonthSecond', () => { const day = new TuiDay(2019, 5, 20); component.max = day;