-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34e5c2b
commit 0d2d779
Showing
10 changed files
with
375 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
279 changes: 279 additions & 0 deletions
279
packages/aws-amplify-react/__tests__/Auth/SignOut-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,279 @@ | ||
/* | ||
jest.mock('aws-sdk-mobile-analytics', () => { | ||
const Manager = () => {} | ||
Manager.prototype.recordEvent = () => { | ||
} | ||
Manager.prototype.recordMonetizationEvent = () => { | ||
} | ||
var ret = { | ||
Manager: Manager | ||
} | ||
return ret; | ||
}); | ||
jest.mock('aws-sdk/clients/pinpoint', () => { | ||
const Pinpoint = () => { | ||
var pinpoint = null; | ||
return pinpoint; | ||
} | ||
Pinpoint.prototype.updateEndpoint = (params, callback) => { | ||
callback(null, 'data'); | ||
} | ||
return Pinpoint; | ||
}); | ||
*/ | ||
|
||
import SignOut from '../../src/Auth/SignOut'; | ||
import React from 'react'; | ||
import AmplifyTheme from '../../src/AmplifyTheme'; | ||
import AuthPiece from '../../src/Auth/AuthPiece'; | ||
import { Header, Footer, InputRow, ButtonRow } from '../../src/AmplifyUI'; | ||
import { Auth } from 'aws-amplify'; | ||
|
||
const acceptedStates = [ | ||
'signedIn' | ||
]; | ||
|
||
const deniedStates = [ | ||
'signIn', | ||
'signedUp', | ||
'signedOut', | ||
'forgotPassword', | ||
'signUp', | ||
'confirmSignIn', | ||
'confirmSignUp', | ||
'verifyContact' | ||
]; | ||
|
||
describe('SignOut', () => { | ||
describe('normal case', () => { | ||
test('render correctly with authState signedIn', () => { | ||
const wrapper = shallow(<SignOut/>); | ||
for (var i = 0; i < acceptedStates.length; i += 1){ | ||
wrapper.setProps({ | ||
authState: acceptedStates[i], | ||
theme: 'theme' | ||
}); | ||
expect(wrapper).toMatchSnapshot(); | ||
} | ||
}); | ||
|
||
test('render correctly with hide', () => { | ||
const wrapper = shallow(<SignOut/>); | ||
for (var i = 0; i < acceptedStates.length; i += 1){ | ||
wrapper.setProps({ | ||
authState: acceptedStates[i], | ||
theme: 'theme', | ||
hide: [SignOut] | ||
}); | ||
expect(wrapper).toMatchSnapshot(); | ||
} | ||
}); | ||
|
||
test('render correctly with empty hide', () => { | ||
const wrapper = shallow(<SignOut/>); | ||
for (var i = 0; i < acceptedStates.length; i += 1){ | ||
wrapper.setProps({ | ||
authState: acceptedStates[i], | ||
theme: 'theme', | ||
hide: [] | ||
}); | ||
expect(wrapper).toMatchSnapshot(); | ||
} | ||
}); | ||
|
||
test('render name from attributes', () => { | ||
const wrapper = shallow(<SignOut/>); | ||
wrapper.setProps({ | ||
authState: 'signedIn', | ||
theme: 'theme' | ||
}); | ||
|
||
wrapper.setState({ | ||
authData: { | ||
attributes: { | ||
name: 'name' | ||
} | ||
}, | ||
authState: 'signedIn' | ||
}) | ||
|
||
expect(wrapper).toMatchSnapshot(); | ||
}) | ||
}); | ||
|
||
|
||
test('render correctly with other authStates', () => { | ||
const wrapper = shallow(<SignOut/>); | ||
|
||
for (var i = 0; i < deniedStates.length; i += 1){ | ||
wrapper.setProps({ | ||
authState: deniedStates[i], | ||
theme: 'theme' | ||
}); | ||
|
||
expect(wrapper).toMatchSnapshot(); | ||
} | ||
}); | ||
|
||
describe('signOut test', () => { | ||
test('happy case', async () => { | ||
const wrapper = shallow(<SignOut/>); | ||
const signOut = wrapper.instance(); | ||
|
||
const spyon = jest.spyOn(Auth, 'signOut').mockImplementationOnce(() => { | ||
return Promise.resolve(); | ||
}); | ||
|
||
await signOut.signOut(); | ||
|
||
expect(spyon).toBeCalled(); | ||
spyon.mockClear(); | ||
}); | ||
|
||
test('error case', async () => { | ||
const wrapper = shallow(<SignOut/>); | ||
const signOut = wrapper.instance(); | ||
|
||
const spyon = jest.spyOn(Auth, 'signOut').mockImplementationOnce(() => { | ||
return Promise.reject('error'); | ||
}); | ||
|
||
await signOut.signOut(); | ||
|
||
expect(spyon).toBeCalled(); | ||
spyon.mockClear(); | ||
}); | ||
}); | ||
|
||
describe('google signOut test', () => { | ||
test('happy case', async () => { | ||
const mockFn = jest.fn(); | ||
|
||
window.gapi = { | ||
auth2: { | ||
getAuthInstance() { | ||
return Promise.resolve({ | ||
signOut: mockFn | ||
}) | ||
} | ||
} | ||
}; | ||
|
||
const wrapper = shallow(<SignOut/>); | ||
const signOut = wrapper.instance(); | ||
|
||
await signOut.googleSignOut(); | ||
|
||
expect(mockFn).toBeCalled(); | ||
}); | ||
|
||
test('no auth2', async () => { | ||
window.gapi = null; | ||
const wrapper = shallow(<SignOut/>); | ||
const signOut = wrapper.instance(); | ||
|
||
expect(await signOut.googleSignOut()).toBeNull(); | ||
}); | ||
|
||
test('no googleAuth', async () => { | ||
window.gapi = { | ||
auth2: { | ||
getAuthInstance() { | ||
return Promise.resolve(null); | ||
} | ||
} | ||
}; | ||
|
||
const wrapper = shallow(<SignOut/>); | ||
const signOut = wrapper.instance(); | ||
|
||
await signOut.googleSignOut(); | ||
}); | ||
}); | ||
|
||
describe('facebook signout test', () => { | ||
test('happy case', async () => { | ||
window.FB = { | ||
getLoginStatus(callback) { | ||
callback({ | ||
status: 'connected' | ||
}) | ||
}, | ||
logout(callback) { | ||
callback('response'); | ||
} | ||
} | ||
|
||
const wrapper = shallow(<SignOut/>); | ||
const signOut = wrapper.instance(); | ||
|
||
await signOut.facebookSignOut() | ||
}); | ||
|
||
test('not connected', async () => { | ||
window.FB = { | ||
getLoginStatus(callback) { | ||
callback({ | ||
status: 'not connected' | ||
}) | ||
}, | ||
logout(callback) { | ||
callback('response'); | ||
} | ||
} | ||
const wrapper = shallow(<SignOut/>); | ||
const signOut = wrapper.instance(); | ||
|
||
await signOut.facebookSignOut() | ||
}); | ||
}); | ||
|
||
describe('checkUser test', () => { | ||
test('happy case', async () => { | ||
const wrapper = shallow(<SignOut/>); | ||
const signOut = wrapper.instance(); | ||
|
||
const spyon = jest.spyOn(Auth, 'currentAuthenticatedUser').mockImplementationOnce(() => { | ||
return Promise.resolve('user'); | ||
}) | ||
|
||
await signOut.checkUser(); | ||
|
||
expect(spyon).toBeCalled(); | ||
}); | ||
|
||
test('no user case', async () => { | ||
const wrapper = shallow(<SignOut/>); | ||
const signOut = wrapper.instance(); | ||
|
||
const spyon = jest.spyOn(Auth, 'currentAuthenticatedUser').mockImplementationOnce(() => { | ||
return Promise.reject('no user'); | ||
}) | ||
|
||
await signOut.checkUser(); | ||
|
||
expect(spyon).toBeCalled(); | ||
}); | ||
|
||
test('check user on mount', async () => { | ||
const wrapper = shallow(<SignOut/>); | ||
const signOut = wrapper.instance(); | ||
|
||
const spyon = jest.spyOn(Auth, 'currentAuthenticatedUser').mockImplementationOnce(() => { | ||
return Promise.resolve('user'); | ||
}) | ||
|
||
await signOut.componentDidMount(); | ||
|
||
expect(spyon).toBeCalled(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.