This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matt Seccafien
committed
Sep 6, 2019
1 parent
0c63c6d
commit fb3aae9
Showing
3 changed files
with
63 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}, | ||
}); |