Skip to content

Commit

Permalink
chore: rename some types
Browse files Browse the repository at this point in the history
  • Loading branch information
Rue-pro committed Mar 19, 2024
1 parent 625c0a3 commit 61d4f47
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/shared/browser/__mocks__/chrome.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { MockedObject, vi } from 'vitest'

type IChrome = typeof chrome
type StoreValue = Record<string, unknown>
type TChrome = typeof chrome
type TStorageValue = Record<string, unknown>

let store: StoreValue = {}
let store: TStorageValue = {}

function getStorageValueByKey(key: string) {
const result: StoreValue = {}
const result: TStorageValue = {}
result[key] = store[key]
return result
}
Expand Down Expand Up @@ -40,4 +40,4 @@ export const chromeMock = {
i18n: {
getMessage: vi.fn((key) => `Translated<${key}>`),
},
} as unknown as MockedObject<IChrome>
} as unknown as MockedObject<TChrome>
19 changes: 10 additions & 9 deletions src/shared/browser/__test__/chrome.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { chromeBrowser } from '../chrome'

describe('browser', () => {
describe('storage', () => {
type StorageValue = object
type TStorageValue = object

const KEY = 'testKey'
const storedValue: StorageValue = { someData: 'value' }
const defaultValue: StorageValue = { defaultData: 'defaultValue' }
const storedValue: TStorageValue = { someData: 'value' }
const defaultValue: TStorageValue = { defaultData: 'defaultValue' }
const circularValue = { prop: 'value', circularRef: {} }
circularValue.circularRef = circularValue
const invalidJSONString = `{"name": "Joe", "age": null]`
Expand Down Expand Up @@ -52,10 +52,11 @@ describe('browser', () => {
})

test('should get previously setted data', async () => {
const setResult = await chromeBrowser.storage.local.set<StorageValue>(
KEY,
storedValue,
)
const setResult =
await chromeBrowser.storage.local.set<TStorageValue>(
KEY,
storedValue,
)

expect(setResult).toEqual(Result.Success(true))

Expand All @@ -68,14 +69,14 @@ describe('browser', () => {
})

test('should not set data to the storage if data is not valid', async () => {
let setResult = await chromeBrowser.storage.local.set<StorageValue>(
let setResult = await chromeBrowser.storage.local.set<TStorageValue>(
KEY,
storedValue,
)

expect(setResult).toEqual(Result.Success(true))

setResult = await chromeBrowser.storage.local.set<StorageValue>(
setResult = await chromeBrowser.storage.local.set<TStorageValue>(
KEY,
circularValue,
)
Expand Down
4 changes: 2 additions & 2 deletions src/shared/ui/Toast/toastStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { useCallback, useRef, useState } from 'preact/hooks'

import { IToast } from './Toast'

export type IAddToastProps = Omit<IToast, 'id'>
export type TAddToastProps = Omit<IToast, 'id'>

export const useToastsStore = () => {
const timersRef = useRef<Record<string, NodeJS.Timeout>>({})
const [toasts, setToasts] = useState<IToast[]>([])

const addToast = useCallback((toast: IAddToastProps) => {
const addToast = useCallback((toast: TAddToastProps) => {
const toastId = new Date().toISOString()
setToasts((prevToasts) => [
{
Expand Down

0 comments on commit 61d4f47

Please sign in to comment.