diff --git a/README.md b/README.md
index ec1c2d2..3b514ef 100644
--- a/README.md
+++ b/README.md
@@ -1,34 +1,39 @@
+
- nfd: {nfd ? JSON.stringify(nfd) : 'loading...'}
+ nfd: {nfd ? nfd.name : 'loading...'}
+
+ nfd content: {nfd ? JSON.stringify(nfd) : 'loading...'}
nfds: {nfds ? `Contains ${nfds.length} NFDs` : 'loading...'}
diff --git a/stories/useShortAddress.story.tsx b/stories/useShortAddress.story.tsx
new file mode 100644
index 0000000..c9c9fdf
--- /dev/null
+++ b/stories/useShortAddress.story.tsx
@@ -0,0 +1,21 @@
+import { storiesOf } from '@storybook/react';
+import * as React from 'react';
+import { useShortAddress } from '../src';
+import ShowDocs from './util/ShowDocs';
+
+const Demo = () => {
+ const address = 'NRLA7VZ2YV6WOS2LBS3UK25DB463XRSNG63BYNQI6CSGGROFWVQ2EKBQSI';
+ const shortAddress = useShortAddress(address);
+
+ return (
+
+
shortened address: {shortAddress} for width=6
+
+
original address: {shortAddress}
+
+ );
+};
+
+storiesOf('Helpers/useShortAddress.story', module)
+ .add('Docs', () =>
)
+ .add('Demo', () =>
);
diff --git a/tests/__snapshots__/useShortAddress.test.ts.snap b/tests/__snapshots__/useShortAddress.test.ts.snap
new file mode 100644
index 0000000..b49c795
--- /dev/null
+++ b/tests/__snapshots__/useShortAddress.test.ts.snap
@@ -0,0 +1,13 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`useShortAddress.default 0 1`] = `"192.168.1.5...192.168.1.5"`;
+
+exports[`useShortAddress.default 1 1`] = `"192.168.1.5...192.168.1.5"`;
+
+exports[`useShortAddress.default 2 1`] = `"192.168.1.5...192.168.1.5"`;
+
+exports[`useShortAddress.default 3 1`] = `"0.0.0.0...0.0.0.0"`;
+
+exports[`useShortAddress.default 4 1`] = `"192.168.1.5...192.168.1.5"`;
+
+exports[`useShortAddress.default 5 1`] = `"..."`;
diff --git a/tests/useNFD.test.ts b/tests/useNFD.test.ts
index 636aa2e..79bd4f5 100644
--- a/tests/useNFD.test.ts
+++ b/tests/useNFD.test.ts
@@ -1,4 +1,6 @@
-import { renderHook } from '@testing-library/react-hooks';
+import { Renderer, renderHook, RenderHookResult } from '@testing-library/react-hooks';
+import { act } from 'react-test-renderer';
+import { NFD } from '../src/misc/interfaces';
import useNfd from '../src/useNfd';
describe('useNfd', () => {
@@ -6,11 +8,17 @@ describe('useNfd', () => {
expect(useNfd).toBeDefined();
});
- it('should update document title', () => {
- let hook = null;
+ it('should be defined 2', () => {
+ let hook: RenderHookResult<
+ string,
+ [NFD | null, NFD[] | null, any, () => void],
+ Renderer
+ > | null = null;
- renderHook((props) => useNfd(props), {
- initialProps: 'NRLA7VZ2YV6WOS2LBS3UK25DB463XRSNG63BYNQI6CSGGROFWVQ2EKBQSI',
+ act(() => {
+ hook = renderHook((props) => useNfd(props), {
+ initialProps: 'NRLA7VZ2YV6WOS2LBS3UK25DB463XRSNG63BYNQI6CSGGROFWVQ2EKBQSI',
+ });
});
expect(hook).toBeDefined();
diff --git a/tests/useShortAddress.test.ts b/tests/useShortAddress.test.ts
new file mode 100644
index 0000000..b01b8db
--- /dev/null
+++ b/tests/useShortAddress.test.ts
@@ -0,0 +1,33 @@
+import * as useShortAddress from '../src/useShortAddress';
+// @ponicode
+describe('useShortAddress.default', () => {
+ test('0', () => {
+ let result: any = useShortAddress.default('192.168.1.5', 100);
+ expect(result).toMatchSnapshot();
+ });
+
+ test('1', () => {
+ let result: any = useShortAddress.default('192.168.1.5', 64);
+ expect(result).toMatchSnapshot();
+ });
+
+ test('2', () => {
+ let result: any = useShortAddress.default('192.168.1.5', 24);
+ expect(result).toMatchSnapshot();
+ });
+
+ test('3', () => {
+ let result: any = useShortAddress.default('0.0.0.0', 10);
+ expect(result).toMatchSnapshot();
+ });
+
+ test('4', () => {
+ let result: any = useShortAddress.default('192.168.1.5', 16);
+ expect(result).toMatchSnapshot();
+ });
+
+ test('5', () => {
+ let result: any = useShortAddress.default('', -Infinity);
+ expect(result).toMatchSnapshot();
+ });
+});