Skip to content

Commit a17dddb

Browse files
committed
Update all start tests to match new final tests
1 parent 1dcbc74 commit a17dddb

File tree

10 files changed

+82
-77
lines changed

10 files changed

+82
-77
lines changed

start/client/src/components/__tests__/launch-detail.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ describe('Launch Detail View', () => {
1010
it('renders without error', () => {
1111
render(
1212
<LaunchDetail
13-
id={1}
13+
id={'1'}
1414
site={'earth'}
15-
rocket={{ name: 'that one', type: 'big' }}
15+
rocket={{ name: 'that one', type: 'big', __typename: 'Rocket', id: '1' }}
1616
/>,
1717
);
1818
});

start/client/src/components/__tests__/launch-tile.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ describe('Launch Tile', () => {
1111
render(
1212
<LaunchTile
1313
launch={{
14-
id: 1,
15-
mission: { name: 'the first one' },
16-
rocket: { name: 'harambe' },
14+
__typename: 'Launch',
15+
isBooked: false,
16+
id: '1',
17+
mission: { name: 'the first one', __typename: 'Mission', missionPatch: null },
18+
rocket: { name: 'harambe', __typename: 'Rocket', id: '1' },
1719
}}
1820
/>,
1921
);

start/client/src/components/__tests__/login-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ describe('Login Form', () => {
88
afterEach(cleanup);
99

1010
it('renders without error', () => {
11-
render(<LoginForm />);
11+
render(<LoginForm login={() => {}}/>);
1212
});
1313
});

start/client/src/containers/__tests__/book-trips.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ import React from 'react';
33
import {
44
renderApollo,
55
cleanup,
6-
getByTestId,
76
fireEvent,
87
waitForElement,
9-
render,
108
} from '../../test-utils';
11-
import BookTrips, { BOOK_TRIPS, GET_LAUNCH } from '../book-trips';
12-
import { GET_CART_ITEMS } from '../../pages/cart';
9+
import BookTrips, { BOOK_TRIPS } from '../book-trips';
10+
import { GET_LAUNCH } from '../cart-item';
1311

1412
const mockLaunch = {
1513
__typename: 'Launch',
@@ -37,7 +35,7 @@ describe('book trips', () => {
3735
it('completes mutation and shows message', async () => {
3836
let mocks = [
3937
{
40-
request: { query: BOOK_TRIPS, variables: { launchIds: [1] } },
38+
request: { query: BOOK_TRIPS, variables: { launchIds: ['1'] } },
4139
result: {
4240
data: {
4341
bookTrips: [{ success: true, message: 'success!', launches: [] }],
@@ -46,12 +44,12 @@ describe('book trips', () => {
4644
},
4745
{
4846
// we need this query for refetchQueries
49-
request: { query: GET_LAUNCH, variables: { launchId: 1 } },
47+
request: { query: GET_LAUNCH, variables: { launchId: '1' } },
5048
result: { data: { launch: mockLaunch } },
5149
},
5250
];
53-
const { getByText, container, getByTestId } = renderApollo(
54-
<BookTrips cartItems={[1]} />,
51+
const { getByTestId } = renderApollo(
52+
<BookTrips cartItems={['1']} />,
5553
{ mocks, addTypename: false },
5654
);
5755

@@ -61,7 +59,7 @@ describe('book trips', () => {
6159
// the component re-renders.
6260
// getByTestId throws an error if it cannot find an element with the given ID
6361
// and waitForElement will wait until the callback doesn't throw an error
64-
const successText = await waitForElement(() => getByTestId('message'));
62+
await waitForElement(() => getByTestId('message'));
6563
});
6664

6765
// >>>> TODO

start/client/src/containers/__tests__/cart-item.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import React from 'react';
33
import {
44
renderApollo,
55
cleanup,
6-
getByTestId,
7-
fireEvent,
86
waitForElement,
9-
render,
107
} from '../../test-utils';
118
import CartItem, { GET_LAUNCH } from '../cart-item';
129

@@ -24,21 +21,21 @@ const mockLaunch = {
2421
},
2522
};
2623

27-
xdescribe('cart item', () => {
24+
describe('cart item', () => {
2825
// automatically unmount and cleanup DOM after the test is finished.
2926
afterEach(cleanup);
3027

3128
it('queries item and renders without error', () => {
3229
let mocks = [
3330
{
34-
request: { query: GET_LAUNCH, variables: { launchId: 1 } },
31+
request: { query: GET_LAUNCH, variables: { launchId: '1' } },
3532
result: { data: { launch: mockLaunch } },
3633
},
3734
];
3835

3936
// since we know the name of the mission, and know that name
4037
// will be rendered at some point, we can use getByText
41-
const { getByText, debug } = renderApollo(<CartItem launchId={1} />, {
38+
const { getByText } = renderApollo(<CartItem launchId={'1'} />, {
4239
mocks,
4340
addTypename: false,
4441
});
@@ -59,11 +56,11 @@ xdescribe('cart item', () => {
5956

6057
// since we know the error message, we can use getByText
6158
// to recognize the error
62-
const { getByText, debug } = renderApollo(<CartItem launchId={1} />, {
59+
const { getByText } = renderApollo(<CartItem launchId={'1'} />, {
6360
mocks,
6461
addTypename: false,
6562
});
6663

6764
waitForElement(() => getByText(/error: aw shucks/i));
6865
});
69-
});
66+
});
Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
1-
// TODO
2-
it('', () => {});
1+
import React from 'react';
2+
import LogoutButton from '../logout-button';
3+
4+
import { renderApollo, cleanup, fireEvent } from '../../test-utils';
5+
import { cache, isLoggedInVar } from '../../cache';
6+
7+
describe('logout button', () => {
8+
// automatically unmount and cleanup DOM after the test is finished.
9+
afterEach(cleanup);
10+
11+
it('renders logout button', async () => {
12+
renderApollo(<LogoutButton />);
13+
});
14+
15+
it('complete logout', async () => {
16+
isLoggedInVar(true);
17+
localStorage.setItem('token', 'testTokenValue');
18+
localStorage.setItem('userId', 'abc123');
19+
const { getByTestId } = renderApollo(<LogoutButton />, { cache });
20+
fireEvent.click(getByTestId('logout-button'));
21+
expect(isLoggedInVar()).toBeFalsy();
22+
expect(localStorage.getItem('token')).toBeNull();
23+
expect(localStorage.getItem('userId')).toBeNull();
24+
});
25+
});
Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,47 @@
11
import React from 'react';
2-
import { InMemoryCache } from '@apollo/client';
32

43
import {
54
renderApollo,
65
cleanup,
7-
getByTestId,
8-
fireEvent,
96
waitForElement,
10-
render,
117
} from '../../test-utils';
12-
import Cart, { GET_CART_ITEMS } from '../cart';
8+
import Cart from '../cart';
9+
import { GET_LAUNCH } from '../../containers/cart-item';
10+
import { cache, cartItemsVar } from '../../cache';
1311

14-
xdescribe('Cart Page', () => {
12+
const mockLaunch = {
13+
__typename: 'Launch',
14+
id: 1,
15+
isBooked: true,
16+
rocket: {
17+
id: 1,
18+
name: 'tester',
19+
},
20+
mission: {
21+
name: 'test mission',
22+
missionPatch: '/',
23+
},
24+
};
25+
26+
describe('Cart Page', () => {
1527
// automatically unmount and cleanup DOM after the test is finished.
1628
afterEach(cleanup);
1729

1830
it('renders with message for empty carts', () => {
19-
// TODO: why is this necessary
20-
const cache = new InMemoryCache();
21-
cache.writeQuery({
22-
query: GET_CART_ITEMS,
23-
data: { cartItems: [] },
24-
});
25-
26-
let mocks = [
27-
{
28-
request: { query: GET_CART_ITEMS },
29-
result: { data: { cartItems: [] } },
30-
},
31-
];
32-
const { getByTestId } = renderApollo(<Cart />, { mocks, cache });
31+
const { getByTestId } = renderApollo(<Cart />, { cache });
3332
return waitForElement(() => getByTestId('empty-message'));
3433
});
3534

3635
it('renders cart', () => {
37-
// TODO: why is this necessary
38-
const cache = new InMemoryCache();
39-
cache.writeQuery({
40-
query: GET_CART_ITEMS,
41-
data: { cartItems: [1] },
42-
});
43-
4436
let mocks = [
4537
{
46-
request: { query: GET_CART_ITEMS },
47-
result: { data: { cartItems: [1] } },
38+
request: { query: GET_LAUNCH, variables: { launchId: '1' } },
39+
result: { data: { launch: mockLaunch } },
4840
},
4941
];
50-
const { getByTestId } = renderApollo(<Cart />, { mocks, cache: undefined });
51-
return waitForElement(() => getByTestId('empty-message'));
42+
43+
const { getByTestId } = renderApollo(<Cart />, { cache, mocks });
44+
cartItemsVar(['1']);
45+
return waitForElement(() => getByTestId('book-button'));
5246
});
5347
});

start/client/src/pages/__tests__/launch.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import React from 'react';
2-
import { print } from 'graphql';
32

43
import {
54
renderApollo,
65
cleanup,
7-
getByTestId,
8-
fireEvent,
96
waitForElement,
10-
render,
117
} from '../../test-utils';
128
import Launch, { GET_LAUNCH_DETAILS } from '../launch';
139

@@ -31,8 +27,7 @@ const mockLaunch = {
3127
isInCart: false,
3228
};
3329

34-
// TODO: un-skip after local state fixes
35-
xdescribe('Launch Page', () => {
30+
describe('Launch Page', () => {
3631
// automatically unmount and cleanup DOM after the test is finished.
3732
afterEach(cleanup);
3833

start/client/src/pages/__tests__/launches.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import React from 'react';
2-
import { print } from 'graphql';
2+
import { InMemoryCache } from '@apollo/client';
33

44
import {
55
renderApollo,
66
cleanup,
7-
getByTestId,
8-
fireEvent,
97
waitForElement,
10-
render,
118
} from '../../test-utils';
129
import Launches, { GET_LAUNCHES } from '../launches';
1310

@@ -31,25 +28,29 @@ const mockLaunch = {
3128
isInCart: false,
3229
};
3330

34-
// TODO: un-skip after local state fixes
35-
xdescribe('Launches Page', () => {
31+
describe('Launches Page', () => {
3632
// automatically unmount and cleanup DOM after the test is finished.
3733
afterEach(cleanup);
3834

3935
it('renders launches', async () => {
36+
const cache = new InMemoryCache({ addTypename: false });
4037
const mocks = [
4138
{
4239
request: { query: GET_LAUNCHES },
4340
result: {
4441
data: {
45-
isLoggedIn: true,
46-
launches: { cursor: '123', hasMore: true, launches: [mockLaunch] },
42+
launches: {
43+
cursor: '123',
44+
hasMore: true,
45+
launches: [mockLaunch],
46+
},
4747
},
4848
},
4949
},
5050
];
5151
const { getByText } = await renderApollo(<Launches />, {
5252
mocks,
53+
cache,
5354
});
5455
await waitForElement(() => getByText(/test mission/i));
5556
});

start/client/src/pages/__tests__/profile.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import React from 'react';
2-
import { print } from 'graphql';
3-
import { gql, InMemoryCache } from '@apollo/client';
42

53
import {
64
renderApollo,
75
cleanup,
8-
getByTestId,
9-
fireEvent,
106
waitForElement,
11-
render,
127
} from '../../test-utils';
138
import Profile, { GET_MY_TRIPS } from '../profile';
149

@@ -36,7 +31,7 @@ const mockMe = {
3631
trips: [mockLaunch],
3732
};
3833

39-
xdescribe('Profile Page', () => {
34+
describe('Profile Page', () => {
4035
// automatically unmount and cleanup DOM after the test is finished.
4136
afterEach(cleanup);
4237

@@ -48,7 +43,7 @@ xdescribe('Profile Page', () => {
4843
},
4944
];
5045

51-
const { getByText } = renderApollo(<Profile />, { mocks, resolvers: {} });
46+
const { getByText } = renderApollo(<Profile />, { mocks });
5247

5348
// if the profile renders, it will have the list of missions booked
5449
await waitForElement(() => getByText(/test mission/i));

0 commit comments

Comments
 (0)