diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-05-02 14:45:20 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-05-02 14:45:20 -0400 |
| commit | f02a5dc73ac4a14c1d641a6ddbfcd2f1bd2ea0b5 (patch) | |
| tree | 514905bb030cb87fbbb686034f49e94b67b88853 /frontend/__tests__/PleaseSignIn.test.js | |
| parent | ae6b07bce815a2dd21741a696eccc64c81587ef4 (diff) | |
TESTS
Diffstat (limited to 'frontend/__tests__/PleaseSignIn.test.js')
| -rw-r--r-- | frontend/__tests__/PleaseSignIn.test.js | 75 |
1 files changed, 73 insertions, 2 deletions
diff --git a/frontend/__tests__/PleaseSignIn.test.js b/frontend/__tests__/PleaseSignIn.test.js index 8dc6124..7a7e275 100644 --- a/frontend/__tests__/PleaseSignIn.test.js +++ b/frontend/__tests__/PleaseSignIn.test.js @@ -2,9 +2,80 @@ import React from 'react'; import { shallow, mount } from 'enzyme'; import toJSON from 'enzyme-to-json'; import PleaseSignIn from '../components/PleaseSignIn'; +import { MockedProvider } from 'react-apollo/test-utils'; +import { fakeUser, fakeOrder } from './mockMang'; +import { CURRENT_USER_QUERY } from '../queries/queries'; +import wait from 'waait'; + +const notSignedInMocks = [ + { + request: { query: CURRENT_USER_QUERY }, + result: { + data: { + me: null, + }, + }, + }, +]; + +const signedInMocks = [ + { + request: { query: CURRENT_USER_QUERY }, + result: { + data: { + me: { + ...fakeUser(), + permissions: ['VIEW_HEY'], + }, + }, + }, + }, +]; +// some dummy child component +const Hey = () => <p>Hey!</p>; describe('<PleaseSignIn />', () => { - it('works', () => { - console.log('heyy'); + it('renders sign in dialog to logged out users', async () => { + const wrapper = mount( + <MockedProvider mocks={notSignedInMocks}> + <PleaseSignIn> + <Hey /> + </PleaseSignIn> + </MockedProvider> + ); + await wait(); + wrapper.update(); + // find the error message + expect(wrapper.text()).toContain('Please sign in before continuing!'); + // show the sign in dialog + expect(wrapper.find('Signin').exists()).toBeTruthy(); + }); + + it('renders child for correct permissions', async () => { + const wrapper = mount( + <MockedProvider mocks={signedInMocks}> + <PleaseSignIn allowedPermissions={['ADMIN', 'VIEW_HEY']}> + <Hey /> + </PleaseSignIn> + </MockedProvider> + ); + await wait(); + wrapper.update(); + expect(wrapper.find('Hey').exists()).toBeTruthy(); + }); + it("renders error when permissions aren't met", async () => { + const wrapper = mount( + <MockedProvider mocks={signedInMocks}> + <PleaseSignIn allowedPermissions={['ADMIN']}> + <Hey /> + </PleaseSignIn> + </MockedProvider> + ); + await wait(); + wrapper.update(); + // should tell you you can't access it + expect(wrapper.text()).toContain('Insufficient Permissions'); + // it should not render the child component + expect(wrapper.find('Hey').exists()).toBeFalsy(); }); }); |
