Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
move tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Seccafien committed Sep 6, 2019
1 parent 0c63c6d commit fb3aae9
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 46 deletions.
46 changes: 1 addition & 45 deletions packages/react-network/src/test/hooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Header} from '@shopify/network';
import {FirstArgument} from '@shopify/useful-types';
import {NetworkManager} from '../manager';
import {NetworkContext} from '../context';
import {useCookie, useAcceptLanguage} from '../hooks';
import {useAcceptLanguage} from '../hooks';

describe('hooks', () => {
describe('useAcceptLanguage()', () => {
Expand Down Expand Up @@ -48,50 +48,6 @@ describe('hooks', () => {
expect(wrapper).toContainReactText('en');
});
});

describe('useCookie', () => {
function MockComponent({cookie}: {cookie: string}) {
const [value, setCookie] = useCookie(cookie);

return (
<>
<button type="button" onClick={() => setCookie('baz')}>
Set Cookie
</button>
{value}
</>
);
}

it('gets a cookie', async () => {
const key = 'foo';
const value = 'bar';
const cookies = {[key]: value};

const wrapper = await mount(<MockComponent cookie={key} />, {
manager: new NetworkManager({cookies}),
});

expect(wrapper).toContainReactText(value);
});

it('sets a cookie', async () => {
const key = 'foo';
const value = 'bar';
const cookies = {[key]: value};

const wrapper = await mount(<MockComponent cookie={key} />, {
manager: new NetworkManager({cookies}),
});

wrapper
.find(MockComponent)!
.find('button')!
.trigger('onClick');

expect(wrapper).toContainReactText(`baz`);
});
});
});

const mount = createMount<{language?: string}>({
Expand Down
2 changes: 1 addition & 1 deletion packages/react-network/src/test/manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('NetworkManager', () => {
expect(manager.getCookie('foo')).toBeUndefined();
});

it('sets initial cookies when coming the request as a string', () => {
it('sets initial cookies when set as a string', () => {
const manager = new NetworkManager({cookies: 'foo=bar'});

expect(manager.getCookie('foo')).toBe('bar');
Expand Down
61 changes: 61 additions & 0 deletions packages/react-network/src/test/useCookie.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React from 'react';
import {createMount} from '@shopify/react-testing';
import {NetworkManager} from '../manager';
import {NetworkContext} from '../context';
import {useCookie} from '../hooks';

describe('hooks', () => {
describe('useCookie', () => {
function MockComponent({cookie}: {cookie: string}) {
const [value, setCookie] = useCookie(cookie);

return (
<>
<button type="button" onClick={() => setCookie('baz')}>
Set Cookie
</button>
{value}
</>
);
}

it('gets a cookie', async () => {
const key = 'foo';
const value = 'bar';
const cookies = {[key]: value};

const wrapper = await mount(<MockComponent cookie={key} />, {
manager: new NetworkManager({cookies}),
});

expect(wrapper).toContainReactText(value);
});

it('sets a cookie', async () => {
const key = 'foo';
const value = 'bar';
const cookies = {[key]: value};

const wrapper = await mount(<MockComponent cookie={key} />, {
manager: new NetworkManager({cookies}),
});

wrapper
.find(MockComponent)!
.find('button')!
.trigger('onClick');

expect(wrapper).toContainReactText(`baz`);
});
});
});

const mount = createMount<{manager?: NetworkManager}>({
render: (element, _, {manager = new NetworkManager()}) => {
return (
<NetworkContext.Provider value={manager}>
{element}
</NetworkContext.Provider>
);
},
});

0 comments on commit fb3aae9

Please sign in to comment.