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__/EditUser.test.js | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 finished-application/frontend/__tests__/EditUser.test.js (limited to 'finished-application/frontend/__tests__/EditUser.test.js') diff --git a/finished-application/frontend/__tests__/EditUser.test.js b/finished-application/frontend/__tests__/EditUser.test.js new file mode 100644 index 0000000..a98cbb5 --- /dev/null +++ b/finished-application/frontend/__tests__/EditUser.test.js @@ -0,0 +1,75 @@ +import React from 'react'; +import { mount } from 'enzyme'; +import toJSON from 'enzyme-to-json'; +import { MockedProvider } from 'react-apollo/test-utils'; +import wait from 'waait'; +import EditUser, { UPDATE_USER_MUTATION } from '../components/EditUser'; +import { fakeUser } from '../lib/testUtils'; +import { CURRENT_USER_QUERY } from '../components/User'; + +const mocks = [ + { + request: { query: CURRENT_USER_QUERY }, + result: { + data: { + me: fakeUser(), + }, + }, + }, + { + request: { + query: UPDATE_USER_MUTATION, + variables: { + name: 'Westopher', + }, + }, + result: { + updateUser: { + name: 'Westopher', + __typename: 'User', + }, + }, + }, +]; + +describe('', () => { + it('renders', async () => { + const wrapper = mount( + + + + ); + await wait(); + wrapper.update(); + expect(toJSON(wrapper.find('form'))).toMatchSnapshot(); + }); + + it('displays changes', async () => { + const wrapper = mount( + + + + ); + await wait(); + wrapper.update(); + const nameInput = wrapper.find('[name="name"]'); + nameInput.simulate('change', { target: { name: 'name', value: 'Scott' } }); + const diff = wrapper.find('pre[data-test="change"]'); + expect(diff.text()).toBe('{"name":"Scott"}'); + }); + + it('calls update user when form is submitted', async () => { + const wrapper = mount( + + + + ); + await wait(); + wrapper.update(); + const nameInput = wrapper.find('[name="name"]'); + nameInput.simulate('change', { target: { name: 'name', value: 'Westopher' } }); + wrapper.find('form').simulate('submit'); + wrapper.update(); + expect(wrapper.find('[data-test="updated"]').text()).toBe('Updated!'); + }); +}); -- cgit v1.3