diff --git a/package.json b/package.json index 6395d43..7156375 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "description": "namae saves your time searching around registries and checking if the desired name is ready for use.", "author": "Yasuaki Uechi (https://uechi.io/)", "scripts": { + "dev": " yarn start", "postinstall": "yarn --cwd web && yarn --cwd api", "ship": "now", "start": "now dev", diff --git a/web/src/util/hooks.test.tsx b/web/src/util/hooks.test.tsx new file mode 100644 index 0000000..38a737b --- /dev/null +++ b/web/src/util/hooks.test.tsx @@ -0,0 +1,20 @@ +import React from 'react'; +import {render, waitForDomChange} from '@testing-library/react'; +import {useDeferredState} from './hooks'; + +const App: React.FC = () => { + const [value, setValue] = useDeferredState(500, 0); + React.useEffect(() => { + setValue(1); + setValue(2); + setValue(3); + }, [setValue]); + return
{value}
; +}; + +it('provoke state flow after certain time passed', async () => { + const {container, getByTestId} = render(); + expect(getByTestId('root').textContent).toBe('0'); + await waitForDomChange({container}); + expect(getByTestId('root').textContent).toBe('3'); +}); diff --git a/web/src/util/pwa.test.ts b/web/src/util/pwa.test.ts new file mode 100644 index 0000000..8163448 --- /dev/null +++ b/web/src/util/pwa.test.ts @@ -0,0 +1,5 @@ +import {isStandalone} from './pwa'; + +it('recognize standalone mode', () => { + expect(isStandalone()).toEqual(false); +}); diff --git a/web/src/util/text.test.ts b/web/src/util/text.test.ts new file mode 100644 index 0000000..22899cb --- /dev/null +++ b/web/src/util/text.test.ts @@ -0,0 +1,9 @@ +import {capitalize} from './text'; + +it('capitalize text', () => { + expect(capitalize('test')).toEqual('Test'); + expect(capitalize('Test')).toEqual('Test'); + expect(capitalize('tEST')).toEqual('Test'); + expect(capitalize('TEST')).toEqual('Test'); + expect(capitalize('')).toEqual(''); +}); diff --git a/web/src/util/text.ts b/web/src/util/text.ts index b66512c..84302a4 100644 --- a/web/src/util/text.ts +++ b/web/src/util/text.ts @@ -1,3 +1,4 @@ export function capitalize(text: string) { + if (text.length === 0) return ''; return text[0].toUpperCase() + text.slice(1).toLowerCase(); }