summaryrefslogtreecommitdiffstats
path: root/finished-application/frontend/__tests__/PleaseSignIn.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'finished-application/frontend/__tests__/PleaseSignIn.test.js')
-rw-r--r--finished-application/frontend/__tests__/PleaseSignIn.test.js59
1 files changed, 15 insertions, 44 deletions
diff --git a/finished-application/frontend/__tests__/PleaseSignIn.test.js b/finished-application/frontend/__tests__/PleaseSignIn.test.js
index f516ea3..7d476b4 100644
--- a/finished-application/frontend/__tests__/PleaseSignIn.test.js
+++ b/finished-application/frontend/__tests__/PleaseSignIn.test.js
@@ -1,80 +1,51 @@
-import React from 'react';
import { mount } from 'enzyme';
import wait from 'waait';
import PleaseSignIn from '../components/PleaseSignIn';
+import { CURRENT_USER_QUERY } from '../components/User';
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,
- },
- },
+ result: { data: { me: null } },
},
];
const signedInMocks = [
{
request: { query: CURRENT_USER_QUERY },
- result: {
- data: {
- me: {
- ...fakeUser(),
- permissions: ['VIEW_HEY'],
- },
- },
- },
+ result: { data: { me: fakeUser() } },
},
];
-// some dummy child component
-const Hey = () => <p>Hey!</p>;
-describe('<PleaseSignIn />', () => {
- it('renders sign in dialog to logged out users', async () => {
+describe('<PleaseSignIn/>', () => {
+ it('renders the sign in dialog to logged out users', async () => {
const wrapper = mount(
<MockedProvider mocks={notSignedInMocks}>
- <PleaseSignIn allowedPermissions={[]}>
- <Hey />
- </PleaseSignIn>
+ <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();
+ expect(wrapper.text()).toContain('Please Sign In before Continuing');
+ const SignIn = wrapper.find('Signin');
+ expect(SignIn.exists()).toBe(true);
});
- 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 () => {
+ it('renders the child component when the user is signed in', async () => {
+ const Hey = () => <p>Hey!</p>;
const wrapper = mount(
<MockedProvider mocks={signedInMocks}>
- <PleaseSignIn allowedPermissions={['ADMIN']}>
+ <PleaseSignIn>
<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();
+ // expect(wrapper.find('Hey').exists()).toBe(true);
+ expect(wrapper.contains(<Hey />)).toBe(true);
});
});