diff --git a/packages/aws-amplify-react/__tests__/Auth/ConfirmSignUp-test.js b/packages/aws-amplify-react/__tests__/Auth/ConfirmSignUp-test.js
index 0393717a959..8ef134d981c 100644
--- a/packages/aws-amplify-react/__tests__/Auth/ConfirmSignUp-test.js
+++ b/packages/aws-amplify-react/__tests__/Auth/ConfirmSignUp-test.js
@@ -33,6 +33,18 @@ describe('ConfirmSignIn', () => {
}
});
+ test('render correctly with hide', () => {
+ const wrapper = shallow();
+ for (var i = 0; i < acceptedStates.length; i += 1){
+ wrapper.setProps({
+ authState: acceptedStates[i],
+ theme: AmplifyTheme,
+ hide: [ConfirmSignUp]
+ });
+ expect(wrapper).toMatchSnapshot();
+ }
+ });
+
test('simulate clicking confirm button with username already defined in auth data', async () => {
const spyon = jest.spyOn(Auth, 'confirmSignUp')
.mockImplementation((user, code) => {
@@ -131,4 +143,4 @@ describe('ConfirmSignIn', () => {
}
});
});
-})
\ No newline at end of file
+})
diff --git a/packages/aws-amplify-react/__tests__/Auth/Greetings-test.js b/packages/aws-amplify-react/__tests__/Auth/Greetings-test.js
index 927c3249cfb..bde521541c7 100644
--- a/packages/aws-amplify-react/__tests__/Auth/Greetings-test.js
+++ b/packages/aws-amplify-react/__tests__/Auth/Greetings-test.js
@@ -65,6 +65,18 @@ describe('Greetings', () => {
}
});
+ test('render correctly with hide', () => {
+ const wrapper = shallow();
+ for (var i = 0; i < acceptedStates.length; i += 1){
+ wrapper.setProps({
+ authState: acceptedStates[i],
+ theme: 'theme',
+ hide: [Greetings]
+ });
+ expect(wrapper).toMatchSnapshot();
+ }
+ });
+
test('render name from attributes', () => {
const wrapper = shallow();
wrapper.setProps({
@@ -227,4 +239,4 @@ describe('Greetings', () => {
});
});
-});
\ No newline at end of file
+});
diff --git a/packages/aws-amplify-react/__tests__/Auth/SignIn-test.js b/packages/aws-amplify-react/__tests__/Auth/SignIn-test.js
index 3cc913bc3b9..893dc8b029f 100644
--- a/packages/aws-amplify-react/__tests__/Auth/SignIn-test.js
+++ b/packages/aws-amplify-react/__tests__/Auth/SignIn-test.js
@@ -36,6 +36,19 @@ describe('SignIn', () => {
}
});
+ test('render correctly with hide', () => {
+ for (var i = 0; i < acceptedStates.length; i += 1){
+ const wrapper = shallow();
+ wrapper.setProps({
+ authState: acceptedStates[i],
+ theme: AmplifyTheme,
+ hide: [SignIn]
+ });
+
+ expect(wrapper).toMatchSnapshot();
+ }
+ });
+
test('when clicking signIn and new password required', async () => {
const wrapper = shallow();
wrapper.setProps({
@@ -266,4 +279,4 @@ describe('SignIn', () => {
spyon2.mockClear();
})
});
-})
\ No newline at end of file
+})
diff --git a/packages/aws-amplify-react/__tests__/Auth/SignOut-test.js b/packages/aws-amplify-react/__tests__/Auth/SignOut-test.js
new file mode 100644
index 00000000000..af2ac7897eb
--- /dev/null
+++ b/packages/aws-amplify-react/__tests__/Auth/SignOut-test.js
@@ -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();
+ 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();
+ 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();
+ 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();
+ 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();
+
+ 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();
+ 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();
+ 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();
+ const signOut = wrapper.instance();
+
+ await signOut.googleSignOut();
+
+ expect(mockFn).toBeCalled();
+ });
+
+ test('no auth2', async () => {
+ window.gapi = null;
+ const wrapper = shallow();
+ const signOut = wrapper.instance();
+
+ expect(await signOut.googleSignOut()).toBeNull();
+ });
+
+ test('no googleAuth', async () => {
+ window.gapi = {
+ auth2: {
+ getAuthInstance() {
+ return Promise.resolve(null);
+ }
+ }
+ };
+
+ const wrapper = shallow();
+ 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();
+ 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();
+ const signOut = wrapper.instance();
+
+ await signOut.facebookSignOut()
+ });
+ });
+
+ describe('checkUser test', () => {
+ test('happy case', async () => {
+ const wrapper = shallow();
+ 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();
+ 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();
+ const signOut = wrapper.instance();
+
+ const spyon = jest.spyOn(Auth, 'currentAuthenticatedUser').mockImplementationOnce(() => {
+ return Promise.resolve('user');
+ })
+
+ await signOut.componentDidMount();
+
+ expect(spyon).toBeCalled();
+ });
+ });
+});
diff --git a/packages/aws-amplify-react/__tests__/Auth/SignUp-test.js b/packages/aws-amplify-react/__tests__/Auth/SignUp-test.js
index acf15bbaef8..a4ee6e05012 100644
--- a/packages/aws-amplify-react/__tests__/Auth/SignUp-test.js
+++ b/packages/aws-amplify-react/__tests__/Auth/SignUp-test.js
@@ -34,6 +34,17 @@ describe('signUp', () => {
}
});
+ test('render correctly with hide', () => {
+ for (var i = 0; i < acceptedStates.length; i += 1){
+ wrapper.setProps({
+ authState: acceptedStates[i],
+ theme: AmplifyTheme,
+ hide: [SignUp]
+ });
+ expect(wrapper).toMatchSnapshot();
+ }
+ });
+
test('when clicking signUp', async () => {
const wrapper = shallow();
wrapper.setProps({
@@ -108,4 +119,4 @@ describe('signUp', () => {
}
});
});
-})
\ No newline at end of file
+})
diff --git a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/ConfirmSignUp-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/ConfirmSignUp-test.js.snap
index 158e5b85383..657414e76be 100644
--- a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/ConfirmSignUp-test.js.snap
+++ b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/ConfirmSignUp-test.js.snap
@@ -2713,6 +2713,8 @@ exports[`ConfirmSignIn normal case render correctly with Props confirmSignUp 1`]
`;
+exports[`ConfirmSignIn normal case render correctly with hide 1`] = `""`;
+
exports[`ConfirmSignIn null case with other authState render corrently 1`] = `""`;
exports[`ConfirmSignIn null case with other authState render corrently 2`] = `""`;
diff --git a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/Greetings-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/Greetings-test.js.snap
index 9c237be1c86..55248ecf719 100644
--- a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/Greetings-test.js.snap
+++ b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/Greetings-test.js.snap
@@ -2,6 +2,8 @@
exports[`Greetings normal case render correctly with authState signedIn 1`] = `""`;
+exports[`Greetings normal case render correctly with hide 1`] = `""`;
+
exports[`Greetings normal case render name from attributes 1`] = `
`;
+exports[`SignIn normal case render correctly with hide 1`] = `""`;
+
+exports[`SignIn normal case render correctly with hide 2`] = `""`;
+
+exports[`SignIn normal case render correctly with hide 3`] = `""`;
+
exports[`SignIn null case with other authState render corrently 1`] = `""`;
exports[`SignIn null case with other authState render corrently 2`] = `""`;
diff --git a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/SignOut-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/SignOut-test.js.snap
new file mode 100644
index 00000000000..ad099a0cb41
--- /dev/null
+++ b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/SignOut-test.js.snap
@@ -0,0 +1,32 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`SignOut normal case render correctly with authState signedIn 1`] = `""`;
+
+exports[`SignOut normal case render correctly with empty hide 1`] = `""`;
+
+exports[`SignOut normal case render correctly with hide 1`] = `""`;
+
+exports[`SignOut normal case render name from attributes 1`] = `
+
+ Sign Out
+
+`;
+
+exports[`SignOut render correctly with other authStates 1`] = `""`;
+
+exports[`SignOut render correctly with other authStates 2`] = `""`;
+
+exports[`SignOut render correctly with other authStates 3`] = `""`;
+
+exports[`SignOut render correctly with other authStates 4`] = `""`;
+
+exports[`SignOut render correctly with other authStates 5`] = `""`;
+
+exports[`SignOut render correctly with other authStates 6`] = `""`;
+
+exports[`SignOut render correctly with other authStates 7`] = `""`;
+
+exports[`SignOut render correctly with other authStates 8`] = `""`;
diff --git a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/SignUp-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/SignUp-test.js.snap
index 9d2a1b00f8f..043e6f3be66 100644
--- a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/SignUp-test.js.snap
+++ b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/SignUp-test.js.snap
@@ -2738,6 +2738,8 @@ exports[`signUp normal case render correctly with authState signUp 1`] = `
`;
+exports[`signUp normal case render correctly with hide 1`] = `""`;
+
exports[`signUp null case with other authState render corrently 1`] = `""`;
exports[`signUp null case with other authState render corrently 2`] = `""`;