From b1600adec47a04f60e1da07d94a3ed3906ff5aee Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Thu, 14 Jun 2018 16:44:21 -0400 Subject: starter files --- .../frontend/__tests__/PleaseSignIn.test.js | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 finished-application/frontend/__tests__/PleaseSignIn.test.js (limited to 'finished-application/frontend/__tests__/PleaseSignIn.test.js') diff --git a/finished-application/frontend/__tests__/PleaseSignIn.test.js b/finished-application/frontend/__tests__/PleaseSignIn.test.js new file mode 100644 index 0000000..f516ea3 --- /dev/null +++ b/finished-application/frontend/__tests__/PleaseSignIn.test.js @@ -0,0 +1,80 @@ +import React from 'react'; +import { mount } from 'enzyme'; +import wait from 'waait'; +import PleaseSignIn from '../components/PleaseSignIn'; +import { MockedProvider } from 'react-apollo/test-utils'; +import { fakeUser } from '../lib/testUtils'; +import { CURRENT_USER_QUERY } from '../components/User'; + +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 = () =>

Hey!

; + +describe('', () => { + it('renders sign in dialog to logged out users', async () => { + const wrapper = mount( + + + + + + ); + 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( + + + + + + ); + await wait(); + wrapper.update(); + expect(wrapper.find('Hey').exists()).toBeTruthy(); + }); + it("renders error when permissions aren't met", async () => { + const wrapper = mount( + + + + + + ); + 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(); + }); +}); -- cgit v1.3