Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd967c5a

Browse files
committed
Update start folder tests to match final tests
1 parent3cc1a1f commitd967c5a

File tree

14 files changed

+67
-95
lines changed

14 files changed

+67
-95
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import React from 'react';
22

33
import{render,cleanup}from'../../test-utils';
44
importLaunchTilefrom'../launch-tile';
5+
import{renderApollo}from'../../test-utils';
56

67
describe('Launch Tile',()=>{
78
// automatically unmount and cleanup DOM after the test is finished.
89
afterEach(cleanup);
910

1011
it('renders without error',()=>{
11-
render(
12+
renderApollo(
1213
<LaunchTile
1314
launch={{
1415
__typename:'Launch',

‎start/client/src/components/__tests__/menu-item.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import React from 'react';
22

33
import{render,cleanup}from'../../test-utils';
44
importMenuItemfrom'../menu-item';
5+
import{renderApollo}from'../../test-utils';
56

67
describe('Menu Item',()=>{
78
// automatically unmount and cleanup DOM after the test is finished.
89
afterEach(cleanup);
910

1011
it('renders without error',()=>{
11-
render(<MenuItemto="/wow"/>);
12+
renderApollo(<MenuItemto="/wow"/>);
1213
});
1314
});

‎start/client/src/containers/__tests__/action-button.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
importReactfrom'react';
22

3-
import{renderApollo,cleanup}from'../../test-utils';
3+
import{renderApollo,cleanup,waitFor}from'../../test-utils';
44
importActionButtonfrom'../action-button';
55
import{cartItemsVar}from'../../cache';
66

@@ -18,7 +18,7 @@ describe('action button', () => {
1818
getByText(/addtocart/i);
1919

2020
// rerender with different props to same container
21-
cartItemsVar(['1']);
21+
waitFor(()=>cartItemsVar(['1']));
2222
renderApollo(<ActionButtonid="1"/>,{ container});
2323
getByText(/removefromcart/i);
2424
cartItemsVar([]);

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
importReactfrom'react';
22

3-
import{
4-
renderApollo,
5-
cleanup,
6-
fireEvent,
7-
waitForElement,
8-
}from'../../test-utils';
3+
import{renderApollo,cleanup,fireEvent,waitFor}from'../../test-utils';
94
importBookTrips,{BOOK_TRIPS}from'../book-trips';
105
import{GET_LAUNCH}from'../cart-item';
116

@@ -48,18 +43,15 @@ describe('book trips', () => {
4843
result:{data:{launch:mockLaunch}},
4944
},
5045
];
51-
const{ getByTestId}=renderApollo(
52-
<BookTripscartItems={['1']}/>,
53-
{ mocks,addTypename:false},
54-
);
46+
const{ getByTestId}=renderApollo(<BookTripscartItems={['1']}/>,{ mocks,addTypename:false});
5547

5648
fireEvent.click(getByTestId('book-button'));
5749

5850
// Let's wait until our mocked mutation resolves and
5951
// the component re-renders.
6052
// getByTestId throws an error if it cannot find an element with the given ID
61-
// andwaitForElement will wait until the callback doesn't throw an error
62-
awaitwaitForElement(()=>getByTestId('message'));
53+
// andwaitFor will wait until the callback doesn't throw an error
54+
awaitwaitFor(()=>getByTestId('message'));
6355
});
6456

6557
// >>>> TODO

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
importReactfrom'react';
22

3-
import{
4-
renderApollo,
5-
cleanup,
6-
waitForElement,
7-
}from'../../test-utils';
3+
import{renderApollo,cleanup,waitFor}from'../../test-utils';
84
importCartItem,{GET_LAUNCH}from'../cart-item';
95

106
constmockLaunch={
@@ -43,7 +39,7 @@ describe('cart item', () => {
4339
// check the loading state
4440
getByText(/loading/i);
4541

46-
returnwaitForElement(()=>getByText(/testmission/i));
42+
returnwaitFor(()=>getByText(/testmission/i));
4743
});
4844

4945
it('renders with error state',()=>{
@@ -61,6 +57,6 @@ describe('cart item', () => {
6157
addTypename:false,
6258
});
6359

64-
waitForElement(()=>getByText(/error:awshucks/i));
60+
waitFor(()=>getByText(/awshucks/i));
6561
});
66-
});
62+
});

‎start/client/src/containers/__tests__/logout-button.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ describe('logout button', () => {
1414

1515
it('complete logout',async()=>{
1616
isLoggedInVar(true);
17-
localStorage.setItem('token','testTokenValue');
18-
localStorage.setItem('userId','abc123');
17+
localStorage.setItem('token',window.btoa('testTokenValue'));
18+
localStorage.setItem('userId',window.btoa('abc123'));
1919
const{ getByTestId}=renderApollo(<LogoutButton/>,{ cache});
2020
fireEvent.click(getByTestId('logout-button'));
2121
expect(isLoggedInVar()).toBeFalsy();

‎start/client/src/pages/__tests__/cart.tsx‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
importReactfrom'react';
22

3-
import{
4-
renderApollo,
5-
cleanup,
6-
waitForElement,
7-
}from'../../test-utils';
3+
import{renderApollo,cleanup,waitFor}from'../../test-utils';
84
importCartfrom'../cart';
95
import{GET_LAUNCH}from'../../containers/cart-item';
106
import{cache,cartItemsVar}from'../../cache';
@@ -29,7 +25,7 @@ describe('Cart Page', () => {
2925

3026
it('renders with message for empty carts',()=>{
3127
const{ getByTestId}=renderApollo(<Cart/>,{ cache});
32-
returnwaitForElement(()=>getByTestId('empty-message'));
28+
returnwaitFor(()=>getByTestId('empty-message'));
3329
});
3430

3531
it('renders cart',()=>{
@@ -42,6 +38,6 @@ describe('Cart Page', () => {
4238

4339
const{ getByTestId}=renderApollo(<Cart/>,{ cache, mocks});
4440
cartItemsVar(['1']);
45-
returnwaitForElement(()=>getByTestId('book-button'));
41+
returnwaitFor(()=>getByTestId('book-button'));
4642
});
4743
});

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
importReactfrom'react';
22

3-
import{
4-
renderApollo,
5-
cleanup,
6-
waitForElement,
7-
}from'../../test-utils';
3+
import{renderApollo,cleanup,waitFor}from'../../test-utils';
84
importLaunch,{GET_LAUNCH_DETAILS}from'../launch';
5+
import{Route,Routes}from'react-router-dom';
6+
import{createMemoryHistory}from'history';
97

108
constmockLaunch={
119
__typename:'Launch',
@@ -34,14 +32,24 @@ describe('Launch Page', () => {
3432
it('renders launch',async()=>{
3533
constmocks=[
3634
{
37-
request:{query:GET_LAUNCH_DETAILS,variables:{launchId:1}},
35+
request:{query:GET_LAUNCH_DETAILS,variables:{launchId:'1'}},
3836
result:{data:{launch:mockLaunch}},
3937
},
4038
];
41-
const{ getByText}=awaitrenderApollo(<LaunchlaunchId={1}/>,{
42-
mocks,
43-
resolvers:{}
44-
});
45-
awaitwaitForElement(()=>getByText(/testmission/i));
39+
40+
consthistory=['/launch/1'];
41+
42+
const{ getByText}=awaitrenderApollo(
43+
<Routes>
44+
<Routepath="launch/:launchId"element={<Launch/>}/>
45+
</Routes>,
46+
{
47+
mocks,
48+
history,
49+
resolvers:{},
50+
},
51+
);
52+
53+
awaitwaitFor(()=>getByText(/testmission/i));
4654
});
4755
});

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
importReactfrom'react';
22
import{InMemoryCache}from'@apollo/client';
33

4-
import{
5-
renderApollo,
6-
cleanup,
7-
waitForElement,
8-
}from'../../test-utils';
4+
import{renderApollo,cleanup,waitFor}from'../../test-utils';
95
importLaunches,{GET_LAUNCHES}from'../launches';
106

117
constmockLaunch={
@@ -52,6 +48,6 @@ describe('Launches Page', () => {
5248
mocks,
5349
cache,
5450
});
55-
awaitwaitForElement(()=>getByText(/testmission/i));
51+
awaitwaitFor(()=>getByText(/testmission/i));
5652
});
5753
});

‎start/client/src/pages/__tests__/login.tsx‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
importReactfrom'react';
22

3-
import{
4-
renderApollo,
5-
cleanup,
6-
fireEvent,
7-
waitForElement,
8-
}from'../../test-utils';
9-
importLogin,{LOGIN_USER}from'../login';
3+
import{renderApollo,cleanup,fireEvent,waitFor}from'../../test-utils';
4+
importLogin,{LOGIN_USER}from'../login';
105
import{cache,isLoggedInVar}from'../../cache';
116

127
describe('Login Page',()=>{
@@ -22,7 +17,7 @@ describe('Login Page', () => {
2217

2318
constmocks=[
2419
{
25-
request:{query:LOGIN_USER,variables:{email:'a@a.a'}},
20+
request:{query:LOGIN_USER,variables:{email:'a@a.a'}},
2621
result:{
2722
data:{
2823
login:{
@@ -34,19 +29,19 @@ describe('Login Page', () => {
3429
},
3530
];
3631

37-
const{getByText, getByTestId}=awaitrenderApollo(<Login/>,{
32+
const{getByText, getByTestId}=awaitrenderApollo(<Login/>,{
3833
mocks,
3934
cache,
4035
});
4136

4237
fireEvent.change(getByTestId('login-input'),{
43-
target:{value:'a@a.a'},
38+
target:{value:'a@a.a'},
4439
});
4540

4641
fireEvent.click(getByText(/login/i));
4742

4843
// login is done if loader is gone
49-
awaitwaitForElement(()=>getByText(/login/i));
44+
awaitwaitFor(()=>getByText(/login/i));
5045

5146
expect(isLoggedInVar()).toBeTruthy();
5247
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp