Skip to content

Commit

Permalink
tests(sdk): for each component define reset function. Reuse it in glo…
Browse files Browse the repository at this point in the history
…bal reset function
  • Loading branch information
heyqbnk committed Oct 4, 2024
1 parent 7091b2e commit 3e12c9a
Show file tree
Hide file tree
Showing 16 changed files with 308 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { resetSignal } from '@test-utils/reset.js';

import { isMounted, isVisible } from './back-button.js';

export function resetBackButton() {
[isVisible, isMounted].forEach(resetSignal);
}
21 changes: 21 additions & 0 deletions packages/sdk/src/scopes/components/biometry/resetBiometry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { resetSignal } from '@test-utils/reset.js';

import {
isMounted,
state,
mountError,
isMounting,
isRequestingAccess,
isAuthenticating,
} from './signals.js';

export function resetBiometry() {
[
isMounted,
state,
mountError,
isMounting,
isRequestingAccess,
isAuthenticating,
].forEach(resetSignal);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { resetSignal } from '@test-utils/reset.js';

import { isMounted, isConfirmationEnabled } from './closing-behavior.js';

export function resetClosingBehavior() {
[isMounted, isConfirmationEnabled].forEach(resetSignal);
}
35 changes: 35 additions & 0 deletions packages/sdk/src/scopes/components/init-data/resetInitData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { resetSignal } from '@test-utils/reset.js';

import {
raw,
state,
authDate,
canSendAfterDate,
canSendAfter,
startParam,
receiver,
queryId,
chat,
chatType,
chatInstance,
hash,
user,
} from './init-data.js';

export function resetInitData() {
[
raw,
state,
authDate,
canSendAfterDate,
canSendAfter,
startParam,
receiver,
queryId,
chat,
chatType,
chatInstance,
hash,
user,
].forEach(resetSignal);
}
7 changes: 7 additions & 0 deletions packages/sdk/src/scopes/components/invoice/resetInvoice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { resetSignal } from '@test-utils/reset.js';

import { isOpened } from './invoice.js';

export function resetInvoice() {
[isOpened].forEach(resetSignal);
}
29 changes: 29 additions & 0 deletions packages/sdk/src/scopes/components/main-button/resetMainButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { resetSignal } from '@test-utils/reset.js';

import {
isMounted,
isVisible,
state,
isLoaderVisible,
isEnabled,
hasShineEffect,
text,
textColor,
backgroundColor,
internalState,
} from './signals.js';

export function resetMainButton() {
[
isMounted,
isVisible,
state,
isLoaderVisible,
isEnabled,
hasShineEffect,
text,
textColor,
backgroundColor,
internalState,
].forEach(resetSignal);
}
29 changes: 29 additions & 0 deletions packages/sdk/src/scopes/components/mini-app/resetMiniApp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { resetSignal } from '@test-utils/reset.js';

import {
isMounted,
state,
backgroundColor,
backgroundColorRGB,
bottomBarColorRGB,
headerColorRGB,
bottomBarColor,
headerColor,
isCssVarsBound,
isDark,
} from './signals.js';

export function resetMiniApp() {
[
isMounted,
state,
backgroundColor,
backgroundColorRGB,
bottomBarColorRGB,
headerColorRGB,
bottomBarColor,
headerColor,
isCssVarsBound,
isDark,
].forEach(resetSignal);
}
7 changes: 7 additions & 0 deletions packages/sdk/src/scopes/components/popup/resetPopup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { resetSignal } from '@test-utils/reset.js';

import { isOpened } from './popup.js';

export function resetPopup() {
[isOpened].forEach(resetSignal);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { resetSignal } from '@test-utils/reset.js';

import { isOpened } from './qr-scanner.js';

export function resetQrScanner() {
[isOpened].forEach(resetSignal);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { resetSignal } from '@test-utils/reset.js';

import {
isMounted,
isVisible,
state,
internalState,
text,
textColor,
backgroundColor,
hasShineEffect,
isEnabled,
isLoaderVisible,
position,
} from './signals.js';

export function resetSecondaryButton() {
[
isMounted,
isVisible,
state,
internalState,
text,
textColor,
backgroundColor,
hasShineEffect,
isEnabled,
isLoaderVisible,
position,
].forEach(resetSignal);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { resetSignal } from '@test-utils/reset.js';

import { isMounted, isVisible } from './settings-button.js';

export function resetSettingsButton() {
[isMounted, isVisible].forEach(resetSignal);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { resetSignal } from '@test-utils/reset.js';

import { isMounted, isVerticalEnabled } from './swipe-behavior.js';

export function resetSwipeBehavior() {
[isMounted, isVerticalEnabled].forEach(resetSignal);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { resetSignal } from '@test-utils/reset.js';

import {
state,
isMounted,
isCssVarsBound,
isDark,
textColor,
backgroundColor,
buttonTextColor,
buttonColor,
secondaryBackgroundColor,
headerBackgroundColor,
linkColor,
destructiveTextColor,
sectionBackgroundColor,
sectionSeparatorColor,
subtitleTextColor,
accentTextColor,
hintColor,
sectionHeaderTextColor,
bottomBarBgColor,
} from './signals.js';

export function resetThemeParams() {
[
state,
isMounted,
isCssVarsBound,
isDark,
textColor,
backgroundColor,
buttonTextColor,
buttonColor,
secondaryBackgroundColor,
headerBackgroundColor,
linkColor,
destructiveTextColor,
sectionBackgroundColor,
sectionSeparatorColor,
subtitleTextColor,
accentTextColor,
hintColor,
sectionHeaderTextColor,
bottomBarBgColor,
].forEach(resetSignal);
}
29 changes: 29 additions & 0 deletions packages/sdk/src/scopes/components/viewport/resetViewport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { resetSignal } from '@test-utils/reset.js';

import {
state,
mountError,
isMounted,
isCssVarsBound,
isMounting,
width,
isExpanded,
height,
stableHeight,
isStable,
} from './signals.js';

export function resetViewport() {
[
state,
mountError,
isMounted,
isCssVarsBound,
isMounting,
width,
isExpanded,
height,
stableHeight,
isStable,
].forEach(resetSignal);
}
7 changes: 7 additions & 0 deletions packages/sdk/src/scopes/utilities/privacy/resetPrivacy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { resetSignal } from '@test-utils/reset.js';

import { isRequestingPhoneAccess, isRequestingWriteAccess } from './privacy.js';

export function resetPrivacy() {
[isRequestingPhoneAccess, isRequestingWriteAccess].forEach(resetSignal);
}
32 changes: 31 additions & 1 deletion packages/sdk/test-utils/reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,43 @@ import { resetPackageState as resetBridgeState } from '@telegram-apps/bridge';
import type { Computed, Signal } from '@telegram-apps/signals';

import { $createRequestId, $postEvent, $version } from '@/scopes/globals.js';
import { resetBackButton } from '@/scopes/components/back-button/resetBackButton.js';
import { resetBiometry } from '@/scopes/components/biometry/resetBiometry.js';
import { resetClosingBehavior } from '@/scopes/components/closing-behavior/resetClosingBehavior.js';
import { resetInitData } from '@/scopes/components/init-data/resetInitData.js';
import { resetInvoice } from '@/scopes/components/invoice/resetInvoice.js';
import { resetMainButton } from '@/scopes/components/main-button/resetMainButton.js';
import { resetMiniApp } from '@/scopes/components/mini-app/resetMiniApp.js';
import { resetPopup } from '@/scopes/components/popup/resetPopup.js';
import { resetQrScanner } from '@/scopes/components/qr-scanner/resetQrScanner.js';
import { resetSecondaryButton } from '@/scopes/components/secondary-button/resetSecondaryButton.js';
import { resetSettingsButton } from '@/scopes/components/settings-button/resetSettingsButton.js';
import { resetSwipeBehavior } from '@/scopes/components/swipe-behavior/resetSwipeBehavior.js';
import { resetThemeParams } from '@/scopes/components/theme-params/resetThemeParams.js';
import { resetViewport } from '@/scopes/components/viewport/resetViewport.js';

export function resetSignal(s: Signal<any> | Computed<any>) {
s.unsubAll();
'reset' in s && s.reset();
}

export function resetPackageState() {
resetBridgeState();
[
resetBridgeState,
resetBackButton,
resetBiometry,
resetClosingBehavior,
resetInitData,
resetInvoice,
resetMainButton,
resetMiniApp,
resetPopup,
resetQrScanner,
resetSecondaryButton,
resetSettingsButton,
resetSwipeBehavior,
resetThemeParams,
resetViewport,
].forEach(reset => reset());
[$postEvent, $version, $createRequestId].forEach(resetSignal);
}

0 comments on commit 3e12c9a

Please sign in to comment.