@@ -27,20 +41,37 @@ function SubmitSection({ sections, setCurrentSection, endpoint }) {
Landscapes.
- You still make changes to your survey answers or add anything you've
- missed after uploading, as long as you upload the survey again after you
- have finished making your changes.
+ You will not be able to access or make changes to your survey responses
+ once your survey has been uploaded.
-
+
Uploading Survey Response
{submitState !== SUBMIT_COMPLETE &&
submitState !== SUBMIT_FAILED &&
Please wait...
}
@@ -81,10 +112,10 @@ function SubmitSection({ sections, setCurrentSection, endpoint }) {
submitState === SUBMIT_FAILED) && (
setSubmitState(null)}
- aria-label="Done"
+ onClick={handleCloseDialog}
+ aria-label={submitState === SUBMIT_COMPLETE ? "logout" : "Done"}
>
- Done
+ {submitState === SUBMIT_COMPLETE ? "LOG OUT" : "OK"}
)}
diff --git a/surveyclient/src/components/SubmitSection.test.js b/surveyclient/src/components/SubmitSection.test.js
index c352c2b..167e26a 100644
--- a/surveyclient/src/components/SubmitSection.test.js
+++ b/surveyclient/src/components/SubmitSection.test.js
@@ -10,7 +10,7 @@ import { Provider } from "react-redux";
import { REFRESH_STATE, SET_AUTH_STATE } from "../model/ActionTypes";
import { SUBMIT } from "./FixedSectionTypes";
import { SIGNED_IN, SIGNED_OUT } from "../model/AuthStates";
-import { INPUT_STATE } from "../model/TestUtils";
+import { INPUT_STATE, EMPTY_STATE } from "../model/TestUtils";
import {
SUBMITTING_START,
SUBMITTING_PHOTOS,
@@ -18,9 +18,11 @@ import {
SUBMIT_COMPLETE,
SUBMIT_FAILED,
} from "../model/SubmitStates";
+import { signOut } from "../model/AuthActions";
const TEST_ENDPOINT = "http://localhost:9999/testEndpoint";
+jest.mock("../model/AuthActions");
jest.mock("../model/SubmitAction");
jest.mock("@aws-amplify/auth");
@@ -42,6 +44,9 @@ describe("component SubmitSection", () => {
surveyStore.dispatch({ type: REFRESH_STATE, state: INPUT_STATE });
uploadResults.mockReset();
+
+ signOut.mockReset();
+ signOut.mockImplementation(() => () => "dummy action");
});
afterEach(() => {
@@ -76,14 +81,49 @@ describe("component SubmitSection", () => {
storedSectionId = null;
renderComponent();
- clickPreviousButton();
+ click(previousButton());
expect(storedSectionId).toStrictEqual("section2");
});
+ it("confirm dialog appears", () => {
+ renderComponent();
+ expect(confirmYesButton()).toBeNull();
+
+ click(uploadButton());
+ expect(confirmYesButton()).not.toBeNull();
+ });
+
+ it("confirm upload cancel", () => {
+ renderComponent();
+ click(uploadButton());
+ renderComponent();
+
+ click(confirmNoButton());
+ renderComponent();
+
+ expect(confirmYesButton()).toBeNull();
+ expect(uploadResults).not.toHaveBeenCalled();
+ });
+
+ it("confirm upload cancel click background", () => {
+ renderComponent();
+ click(uploadButton());
+ renderComponent();
+
+ click(backdrop());
+ renderComponent();
+
+ expect(confirmYesButton()).toBeNull();
+ expect(uploadResults).not.toHaveBeenCalled();
+ });
+
it("upload success and close", () => {
renderComponent();
expect(uploadResults).toHaveBeenCalledTimes(0);
- clickUploadButton();
+ click(uploadButton());
+ renderComponent();
+ click(confirmYesButton());
+ renderComponent();
const { setSubmitState, setProgressValue } = checkUploadAndGetCallbacks(
INPUT_STATE,
@@ -97,16 +137,23 @@ describe("component SubmitSection", () => {
checkDialogComplete();
- clickCloseButton();
+ click(closeButton());
renderComponent();
expect(dialog()).toBeNull();
+ expect(surveyStore.getState()).toStrictEqual({
+ ...EMPTY_STATE,
+ initialisingState: false,
+ });
});
it("upload failure and close", () => {
renderComponent();
expect(uploadResults).toHaveBeenCalledTimes(0);
- clickUploadButton();
+ click(uploadButton());
+ renderComponent();
+ click(confirmYesButton());
+ renderComponent();
const { setSubmitState, setProgressValue } = checkUploadAndGetCallbacks(
INPUT_STATE,
@@ -120,16 +167,20 @@ describe("component SubmitSection", () => {
checkDialogFailed("50%");
- clickCloseButton();
+ click(closeButton());
renderComponent();
expect(dialog()).toBeNull();
+ expect(surveyStore.getState()).toStrictEqual(INPUT_STATE);
});
it("progress changes during upload", () => {
renderComponent();
expect(uploadResults).toHaveBeenCalledTimes(0);
- clickUploadButton();
+ click(uploadButton());
+ renderComponent();
+ click(confirmYesButton());
+ renderComponent();
const { setSubmitState, setProgressValue } = checkUploadAndGetCallbacks(
INPUT_STATE,
@@ -215,7 +266,8 @@ describe("component SubmitSection", () => {
expect(closeButton()).not.toBeNull();
}
- const sectionContent = () => container.querySelector(".section .submit-content");
+ const sectionContent = () =>
+ container.querySelector(".section .submit-content");
const previousButton = () =>
container.querySelector(".section .previous-section-button");
const uploadButton = () =>
@@ -227,20 +279,18 @@ describe("component SubmitSection", () => {
const closeButton = () => document.querySelector(".dialog .close-button");
const progressBar = () =>
document.querySelector(".dialog .progress-bar-active");
+ const confirmYesButton = () => document.querySelector(".dialog #yes-button");
+ const confirmNoButton = () => document.querySelector(".dialog #no-button");
+ const backdrop = () =>
+ document.querySelector("#dialog-container div:first-child");
function progressBarValue() {
const styleValue = progressBar().getAttribute("style");
return styleValue.substring(7, styleValue.length - 1);
}
- function clickCloseButton() {
- closeButton().dispatchEvent(new MouseEvent("click", { bubbles: true }));
- }
- function clickPreviousButton() {
- previousButton().dispatchEvent(new MouseEvent("click", { bubbles: true }));
- }
- function clickUploadButton() {
- uploadButton().dispatchEvent(new MouseEvent("click", { bubbles: true }));
+ function click(element) {
+ element.dispatchEvent(new MouseEvent("click", { bubbles: true }));
}
function renderComponent() {
diff --git a/surveyclient/src/components/auth/AuthSignInOut.jsx b/surveyclient/src/components/auth/AuthSignInOut.jsx
deleted file mode 100644
index 2b439b2..0000000
--- a/surveyclient/src/components/auth/AuthSignInOut.jsx
+++ /dev/null
@@ -1,34 +0,0 @@
-import React, { useState, useEffect } from "react";
-import { useDispatch, useSelector } from "react-redux";
-import { SIGN_IN, SIGNED_OUT, SIGNED_IN } from "../../model/AuthStates";
-import { setAuthState, signOut } from "../../model/AuthActions";
-import "../../App.css";
-
-export default function AuthSignInOut() {
- const [signedIn, setSignedIn] = useState(false);
-
- const dispatch = useDispatch();
- const authState = useSelector((state) => state.authentication.state);
-
- useEffect(() => {
- if (authState === SIGNED_IN) {
- setSignedIn(true);
- } else if (authState === SIGNED_OUT) {
- setSignedIn(false);
- }
- }, [authState]);
-
- function handleClick(event) {
- dispatch(signedIn ? signOut() : setAuthState(SIGN_IN));
- }
-
- return (
-
- {signedIn ? "LOG OUT" : "LOG IN"}
-
- );
-}
diff --git a/surveyclient/src/components/auth/AuthSignInOut.test.js b/surveyclient/src/components/auth/AuthSignInOut.test.js
deleted file mode 100644
index b341991..0000000
--- a/surveyclient/src/components/auth/AuthSignInOut.test.js
+++ /dev/null
@@ -1,97 +0,0 @@
-import React from "react";
-import { render, unmountComponentAtNode } from "react-dom";
-import { act } from "react-dom/test-utils";
-import AuthSignInOut from "./AuthSignInOut";
-import surveyStore from "../../model/SurveyModel";
-import { Provider } from "react-redux";
-import { SET_AUTH_STATE } from "../../model/ActionTypes";
-import {
- SIGNED_OUT,
- SIGNED_IN,
- SIGN_IN,
- REGISTER,
-} from "../../model/AuthStates";
-import { signOut, setAuthState } from "../../model/AuthActions";
-
-jest.mock("../../model/AuthActions");
-
-describe("component AuthSignInOut", () => {
- var container = null;
- beforeEach(() => {
- // setup a DOM element as a render target
- container = document.createElement("div");
- document.body.appendChild(container);
-
- signOut.mockReset();
- signOut.mockImplementation(() => () => "dummy action");
- setAuthState.mockReset();
- setAuthState.mockImplementation(() => () => "dummy action");
- });
-
- afterEach(() => {
- // cleanup on exiting
- unmountComponentAtNode(container);
- container.remove();
- container = null;
- });
-
- it("signed in", () => {
- surveyStore.dispatch({ type: SET_AUTH_STATE, authState: SIGNED_IN });
- renderComponent();
-
- expect(signInOutButton().textContent).toStrictEqual("LOG OUT");
- click(signInOutButton());
-
- expect(signOut).toHaveBeenCalledTimes(1);
- expect(setAuthState).not.toHaveBeenCalledTimes(1);
- });
-
- it("signed out", () => {
- surveyStore.dispatch({ type: SET_AUTH_STATE, authState: SIGNED_OUT });
- renderComponent();
-
- expect(signInOutButton().textContent).toStrictEqual("LOG IN");
- click(signInOutButton());
-
- expect(signOut).not.toHaveBeenCalled();
- expect(setAuthState).toHaveBeenCalledTimes(1);
- expect(setAuthState).toHaveBeenCalledWith(SIGN_IN);
- });
-
- it("auth state changes", () => {
- surveyStore.dispatch({ type: SET_AUTH_STATE, authState: SIGNED_IN });
- renderComponent();
- expect(signInOutButton().textContent).toStrictEqual("LOG OUT");
-
- surveyStore.dispatch({ type: SET_AUTH_STATE, authState: REGISTER });
- renderComponent();
- expect(signInOutButton().textContent).toStrictEqual("LOG OUT");
-
- surveyStore.dispatch({ type: SET_AUTH_STATE, authState: SIGNED_OUT });
- renderComponent();
- expect(signInOutButton().textContent).toStrictEqual("LOG IN");
-
- surveyStore.dispatch({ type: SET_AUTH_STATE, authState: REGISTER });
- renderComponent();
- expect(signInOutButton().textContent).toStrictEqual("LOG IN");
- });
-
- const signInOutButton = () => container.querySelector("#auth-signin-signout");
-
- function click(element) {
- act(() => {
- element.dispatchEvent(new MouseEvent("click", { bubbles: true }));
- });
- }
-
- function renderComponent() {
- act(() => {
- render(
-
-
- ,
- container
- );
- });
- }
-});
diff --git a/surveyclient/src/components/auth/AuthSignOut.jsx b/surveyclient/src/components/auth/AuthSignOut.jsx
new file mode 100644
index 0000000..0fe6a34
--- /dev/null
+++ b/surveyclient/src/components/auth/AuthSignOut.jsx
@@ -0,0 +1,39 @@
+import React, { useState } from "react";
+import { useDispatch } from "react-redux";
+import { signOut } from "../../model/AuthActions";
+import ConfirmDialog from "../ConfirmDialog";
+import "../../App.css";
+
+export default function AuthSignOut() {
+ const [showConfirmDialog, setShowConfirmDialog] = useState(false);
+
+ const dispatch = useDispatch();
+
+ return (
+ <>
+
setShowConfirmDialog(true)}
+ id="auth-signout"
+ >
+ LOG OUT
+
+ {showConfirmDialog && (
+
{
+ closeConfirmed && dispatch(signOut());
+ setShowConfirmDialog(false);
+ }}
+ >
+ Are you sure you want to Log Out?
+
+ You will not be able to continue your survey and you will need
+ access to an internet connection to Login again.
+
+
+ )}
+ >
+ );
+}
diff --git a/surveyclient/src/components/auth/AuthSignOut.test.js b/surveyclient/src/components/auth/AuthSignOut.test.js
new file mode 100644
index 0000000..225125a
--- /dev/null
+++ b/surveyclient/src/components/auth/AuthSignOut.test.js
@@ -0,0 +1,96 @@
+import React from "react";
+import { render, unmountComponentAtNode } from "react-dom";
+import { act } from "react-dom/test-utils";
+import AuthSignOut from "./AuthSignOut";
+import surveyStore from "../../model/SurveyModel";
+import { Provider } from "react-redux";
+import { signOut } from "../../model/AuthActions";
+
+jest.mock("../../model/AuthActions");
+
+describe("component AuthSignOut", () => {
+ var container = null;
+ beforeEach(() => {
+ // setup a DOM element as a render target
+ container = document.createElement("div");
+ document.body.appendChild(container);
+
+ signOut.mockReset();
+ signOut.mockImplementation(() => () => "dummy action");
+ });
+
+ afterEach(() => {
+ // cleanup on exiting
+ unmountComponentAtNode(container);
+ container.remove();
+ container = null;
+ });
+
+ it("confirm dialog appears", () => {
+ renderComponent();
+ expect(confirmYesButton()).toBeNull();
+
+ click(signOutButton());
+ expect(confirmYesButton()).not.toBeNull();
+ });
+
+ it("signed out cancel", () => {
+ renderComponent();
+ click(signOutButton());
+ renderComponent();
+
+ click(confirmNoButton());
+ renderComponent();
+
+ expect(confirmYesButton()).toBeNull();
+ expect(signOut).not.toHaveBeenCalled();
+ });
+
+ it("signed out cancel click background", () => {
+ renderComponent();
+ click(signOutButton());
+ renderComponent();
+
+ click(backdrop());
+ renderComponent();
+
+ expect(confirmYesButton()).toBeNull();
+ expect(signOut).not.toHaveBeenCalled();
+ });
+
+ it("signed out confirm", () => {
+ renderComponent();
+ click(signOutButton());
+ renderComponent();
+
+ click(confirmYesButton());
+ renderComponent();
+
+ expect(confirmYesButton()).toBeNull();
+ expect(signOut).toHaveBeenCalledTimes(1);
+ });
+
+ const signOutButton = () => container.querySelector("#auth-signout");
+
+ const confirmYesButton = () => document.querySelector(".dialog #yes-button");
+ const confirmNoButton = () => document.querySelector(".dialog #no-button");
+ const backdrop = () =>
+ document.querySelector("#dialog-container div:first-child");
+
+ function click(element) {
+ act(() => {
+ element.dispatchEvent(new MouseEvent("click", { bubbles: true }));
+ });
+ }
+
+ function renderComponent() {
+ act(() => {
+ render(
+
+
+ ,
+ container
+ );
+ });
+ }
+});
diff --git a/surveyclient/src/components/auth/ConfirmRegistration.jsx b/surveyclient/src/components/auth/ConfirmRegistration.jsx
index 912a654..83f4085 100644
--- a/surveyclient/src/components/auth/ConfirmRegistration.jsx
+++ b/surveyclient/src/components/auth/ConfirmRegistration.jsx
@@ -6,7 +6,6 @@ import {
resendConfirmCode,
confirmRegistration,
} from "../../model/AuthActions";
-import ContinueSignedOutButton from "./ContinueSignedOutButton";
const EMAIL_ID = "confirmEmailInput";
const CODE_ID = "codeInput";
@@ -74,7 +73,6 @@ export default function ConfirmRegistration() {
>
{loading ?
:
CONFIRM }
-
{
container = null;
});
- it("initial render and code entry - first login", () => {
+ it("initial render and code entry", () => {
renderComponent();
expect(emailInput().value).toStrictEqual(TEST_USER);
expect(codeInput().value).toStrictEqual("");
expect(confirmButton()).toBeDisabled();
- expect(continueButton()).toBeNull();
enterCode(TEST_CODE);
renderComponent();
@@ -150,34 +141,11 @@ describe("component ConfirmRegistration", () => {
expect(confirmButton()).not.toBeDisabled();
});
- it("not first login can continue", () => {
- surveyStore.dispatch({
- type: REFRESH_STATE,
- state: {
- hasEverLoggedIn: true,
- authentication: {
- errorMessage: "",
- state: CONFIRM_REGISTRATION,
- user: undefined,
- },
- },
- });
- renderComponent();
-
- expect(continueButton()).not.toBeNull();
- click(continueButton());
-
- expect(setAuthState).toHaveBeenCalledTimes(1);
- expect(setAuthState).toHaveBeenCalledWith(SIGNED_OUT);
- });
-
const emailInput = () => container.querySelector("#confirmEmailInput");
const codeInput = () => container.querySelector("#codeInput");
const confirmButton = () => container.querySelector("#confirm-button");
const resendCodeButton = () => container.querySelector("#resend-code-button");
const signInButton = () => container.querySelector("#signin-button");
- const continueButton = () =>
- container.querySelector("#continue-signed-out-button");
function enterCode(value) {
act(() => {
diff --git a/surveyclient/src/components/auth/ContinueSignedOutButton.jsx b/surveyclient/src/components/auth/ContinueSignedOutButton.jsx
deleted file mode 100644
index c65c191..0000000
--- a/surveyclient/src/components/auth/ContinueSignedOutButton.jsx
+++ /dev/null
@@ -1,24 +0,0 @@
-import React from "react";
-import { useDispatch, useSelector } from "react-redux";
-import { SIGNED_OUT } from "../../model/AuthStates";
-import { setAuthState } from "../../model/AuthActions";
-import "../../App.css";
-
-export default function ContinueSignedOutButton() {
- const hasEverLoggedIn = useSelector((state) => state.hasEverLoggedIn);
- const dispatch = useDispatch();
-
- if (!hasEverLoggedIn) {
- return null;
- }
-
- return (
- dispatch(setAuthState(SIGNED_OUT))}
- >
- CONTINUE SURVEY
-
- );
-}
diff --git a/surveyclient/src/components/auth/ContinueSignedOutButton.test.js b/surveyclient/src/components/auth/ContinueSignedOutButton.test.js
deleted file mode 100644
index 3751faa..0000000
--- a/surveyclient/src/components/auth/ContinueSignedOutButton.test.js
+++ /dev/null
@@ -1,72 +0,0 @@
-import React from "react";
-import { render, unmountComponentAtNode } from "react-dom";
-import { act } from "react-dom/test-utils";
-import ContinueSignedOutButton from "./ContinueSignedOutButton";
-import surveyStore from "../../model/SurveyModel";
-import { Provider } from "react-redux";
-import { REFRESH_STATE } from "../../model/ActionTypes";
-import { SIGNED_OUT, REGISTER } from "../../model/AuthStates";
-
-describe("component ContinueSignedOutButton", () => {
- var container = null;
- beforeEach(() => {
- // setup a DOM element as a render target
- container = document.createElement("div");
- document.body.appendChild(container);
- });
-
- afterEach(() => {
- // cleanup on exiting
- unmountComponentAtNode(container);
- container.remove();
- container = null;
- });
-
- it("first login", () => {
- surveyStore.dispatch({
- type: REFRESH_STATE,
- state: { hasEverLoggedIn: false },
- });
- renderComponent();
-
- expect(continueButton()).toBeNull();
- });
-
- it("not first login", () => {
- surveyStore.dispatch({
- type: REFRESH_STATE,
- state: {
- hasEverLoggedIn: true,
- authentication: { errorMessage: "", state: REGISTER, user: undefined },
- },
- });
- renderComponent();
-
- expect(continueButton()).not.toBeNull();
- click(continueButton());
-
- expect(surveyStore.getState().authentication.state).toStrictEqual(
- SIGNED_OUT
- );
- });
-
- const continueButton = () =>
- container.querySelector("#continue-signed-out-button");
-
- function click(element) {
- act(() => {
- element.dispatchEvent(new MouseEvent("click", { bubbles: true }));
- });
- }
-
- function renderComponent() {
- act(() => {
- render(
-
-
- ,
- container
- );
- });
- }
-});
diff --git a/surveyclient/src/components/auth/ForgotPasswordRequest.jsx b/surveyclient/src/components/auth/ForgotPasswordRequest.jsx
index 4360163..75e28b3 100644
--- a/surveyclient/src/components/auth/ForgotPasswordRequest.jsx
+++ b/surveyclient/src/components/auth/ForgotPasswordRequest.jsx
@@ -2,7 +2,6 @@ import React, { useState, useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import { SIGN_IN } from "../../model/AuthStates";
import { setAuthState, forgotPasswordRequest } from "../../model/AuthActions";
-import ContinueSignedOutButton from "./ContinueSignedOutButton";
const EMAIL_ID = "emailInput";
@@ -42,7 +41,6 @@ export default function ForgotPasswordRequest() {
>
{loading ?
: SEND CODE }
-
{
container = null;
});
- it("initial render and enable password request action - first login", () => {
+ it("initial render and enable password request action", () => {
renderComponent();
expect(emailInput().value).toStrictEqual("");
expect(requestButton()).toBeDisabled();
- expect(continueButton()).toBeNull();
// Form complete
enterEmail(TEST_USER);
@@ -118,32 +109,9 @@ describe("component ForgotPasswordRequest", () => {
expect(requestButton()).not.toBeDisabled();
});
- it("not first login can continue", () => {
- surveyStore.dispatch({
- type: REFRESH_STATE,
- state: {
- hasEverLoggedIn: true,
- authentication: {
- errorMessage: "",
- state: FORGOT_PASSWORD_REQUEST,
- user: undefined,
- },
- },
- });
- renderComponent();
-
- expect(continueButton()).not.toBeNull();
- click(continueButton());
-
- expect(setAuthState).toHaveBeenCalledTimes(1);
- expect(setAuthState).toHaveBeenCalledWith(SIGNED_OUT);
- });
-
const emailInput = () => container.querySelector("#emailInput");
const requestButton = () => container.querySelector("#request-button");
const signInButton = () => container.querySelector("#signin-button");
- const continueButton = () =>
- container.querySelector("#continue-signed-out-button");
function enterEmail(value) {
act(() => {
diff --git a/surveyclient/src/components/auth/ForgotPasswordSubmit.jsx b/surveyclient/src/components/auth/ForgotPasswordSubmit.jsx
index 7245053..9a749e7 100644
--- a/surveyclient/src/components/auth/ForgotPasswordSubmit.jsx
+++ b/surveyclient/src/components/auth/ForgotPasswordSubmit.jsx
@@ -2,7 +2,6 @@ import React, { useState, useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import { SIGN_IN } from "../../model/AuthStates";
import { setAuthState, forgotPasswordSubmit } from "../../model/AuthActions";
-import ContinueSignedOutButton from "./ContinueSignedOutButton";
const EMAIL_ID = "emailInput";
const CODE_ID = "codeInput";
@@ -73,7 +72,6 @@ export default function ForgotPasswordSubmit() {
>
{loading ?
: {"SUBMIT"} }
-
{
container = null;
});
- it("initial render and enable submit action - first login", () => {
+ it("initial render and enable submit action", () => {
renderComponent();
expect(emailInput().value).toStrictEqual(TEST_USER);
expect(codeInput().value).toStrictEqual("");
expect(passwordInput().value).toStrictEqual("");
expect(submitButton()).toBeDisabled();
- expect(continueButton()).toBeNull();
// Form complete
enterCode("123456");
@@ -88,21 +83,21 @@ describe("component ForgotPasswordSubmit", () => {
});
it("render missing user", () => {
- surveyStore.dispatch({
- type: SET_AUTH_STATE,
- authState: FORGOT_PASSWORD_SUBMIT,
- user: {},
- });
- renderComponent();
- expect(emailInput().value).toStrictEqual("");
-
- surveyStore.dispatch({
- type: SET_AUTH_STATE,
- authState: FORGOT_PASSWORD_SUBMIT,
- user: undefined,
- });
- renderComponent();
- expect(emailInput().value).toStrictEqual("");
+ surveyStore.dispatch({
+ type: SET_AUTH_STATE,
+ authState: FORGOT_PASSWORD_SUBMIT,
+ user: {},
+ });
+ renderComponent();
+ expect(emailInput().value).toStrictEqual("");
+
+ surveyStore.dispatch({
+ type: SET_AUTH_STATE,
+ authState: FORGOT_PASSWORD_SUBMIT,
+ user: undefined,
+ });
+ renderComponent();
+ expect(emailInput().value).toStrictEqual("");
});
it("confirm success", () => {
@@ -113,7 +108,11 @@ describe("component ForgotPasswordSubmit", () => {
click(submitButton());
expect(forgotPasswordSubmit).toHaveBeenCalledTimes(1);
- expect(forgotPasswordSubmit).toHaveBeenCalledWith(TEST_USER, "123456", "12345678");
+ expect(forgotPasswordSubmit).toHaveBeenCalledWith(
+ TEST_USER,
+ "123456",
+ "12345678"
+ );
renderComponent();
expect(submitButton()).toBeDisabled();
});
@@ -158,35 +157,11 @@ describe("component ForgotPasswordSubmit", () => {
expect(submitButton()).not.toBeDisabled();
});
- it("not first login can continue", () => {
- surveyStore.dispatch({
- type: REFRESH_STATE,
- state: {
- hasEverLoggedIn: true,
- authentication: {
- errorMessage: "",
- state: FORGOT_PASSWORD_SUBMIT,
- user: undefined,
- },
- },
- });
- renderComponent();
-
- expect(continueButton()).not.toBeNull();
- click(continueButton());
-
- expect(setAuthState).toHaveBeenCalledTimes(1);
- expect(setAuthState).toHaveBeenCalledWith(SIGNED_OUT);
- });
-
-
const emailInput = () => container.querySelector("#emailInput");
const codeInput = () => container.querySelector("#codeInput");
const passwordInput = () => container.querySelector("#passwordInput");
const submitButton = () => container.querySelector("#submit-button");
const signInButton = () => container.querySelector("#signin-button");
- const continueButton = () =>
- container.querySelector("#continue-signed-out-button");
function enterCode(value) {
act(() => {
diff --git a/surveyclient/src/components/auth/Register.jsx b/surveyclient/src/components/auth/Register.jsx
index 4ed3bda..27f0dcc 100644
--- a/surveyclient/src/components/auth/Register.jsx
+++ b/surveyclient/src/components/auth/Register.jsx
@@ -3,7 +3,6 @@ import { setAuthState, register } from "../../model/AuthActions";
import { useDispatch, useSelector } from "react-redux";
import { SIGN_IN } from "../../model/AuthStates";
import Modal from "@material-ui/core/Modal";
-import ContinueSignedOutButton from "./ContinueSignedOutButton";
const EMAIL_ID = "emailInput";
const PASSWORD_ID = "passwordInput";
@@ -147,7 +146,6 @@ for any other purpose.`;
>
{loading ?
: REGISTER }
-
Already have an account?{" "}
diff --git a/surveyclient/src/components/auth/Register.test.js b/surveyclient/src/components/auth/Register.test.js
index 6f55df5..4dedb9c 100644
--- a/surveyclient/src/components/auth/Register.test.js
+++ b/surveyclient/src/components/auth/Register.test.js
@@ -4,12 +4,8 @@ import { act, Simulate } from "react-dom/test-utils";
import Register from "./Register";
import surveyStore from "../../model/SurveyModel";
import { Provider } from "react-redux";
-import {
- SET_AUTH_STATE,
- SET_AUTH_ERROR,
- REFRESH_STATE,
-} from "../../model/ActionTypes";
-import { SIGN_IN, SIGNED_OUT, REGISTER } from "../../model/AuthStates";
+import { SET_AUTH_STATE, SET_AUTH_ERROR } from "../../model/ActionTypes";
+import { SIGN_IN, REGISTER } from "../../model/AuthStates";
import { setAuthState, register } from "../../model/AuthActions";
const TEST_USER = "test@example.com";
@@ -42,14 +38,13 @@ describe("component Register", () => {
container = null;
});
- it("initial render and enable register action - first login", () => {
+ it("initial render and enable register action", () => {
renderComponent();
expect(emailInput().value).toStrictEqual("");
expect(passwordInput().value).toStrictEqual("");
expect(tncCheck()).not.toBeChecked();
expect(gdprCheck()).not.toBeChecked();
expect(registerButton()).toBeDisabled();
- expect(continueButton()).toBeNull();
// Form complete
enterEmail(TEST_USER);
@@ -169,27 +164,6 @@ describe("component Register", () => {
expect(registerButton()).not.toBeDisabled();
});
- it("not first login can continue", () => {
- surveyStore.dispatch({
- type: REFRESH_STATE,
- state: {
- hasEverLoggedIn: true,
- authentication: {
- errorMessage: "",
- state: REGISTER,
- user: undefined,
- },
- },
- });
- renderComponent();
-
- expect(continueButton()).not.toBeNull();
- click(continueButton());
-
- expect(setAuthState).toHaveBeenCalledTimes(1);
- expect(setAuthState).toHaveBeenCalledWith(SIGNED_OUT);
- });
-
it("gdpr popup", () => {
renderComponent();
expect(gdprPopup()).toBeNull();
@@ -220,8 +194,6 @@ describe("component Register", () => {
const passwordInput = () => container.querySelector("#passwordInput");
const registerButton = () => container.querySelector("#register-button");
const signInButton = () => container.querySelector("#signin-button");
- const continueButton = () =>
- container.querySelector("#continue-signed-out-button");
const gdprPopupCloseButton = () =>
document.querySelector(".tooltip-popup .close-button");
const backdrop = () =>
diff --git a/surveyclient/src/components/auth/RequireNewPassword.jsx b/surveyclient/src/components/auth/RequireNewPassword.jsx
index 7aa6872..9007366 100644
--- a/surveyclient/src/components/auth/RequireNewPassword.jsx
+++ b/surveyclient/src/components/auth/RequireNewPassword.jsx
@@ -2,7 +2,6 @@ import React, { useState, useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import { SIGN_IN } from "../../model/AuthStates";
import { setAuthState, completeNewPassword } from "../../model/AuthActions";
-import ContinueSignedOutButton from "./ContinueSignedOutButton";
const PASSWORD_ID = "passwordInput";
const MIN_PASSWORD_LENGTH = 8;
@@ -47,7 +46,6 @@ export default function RequireNewPassword() {
>
{loading ?
:
CHANGE }
-
{
container = null;
});
- it("initial render and enable change action - first login", () => {
+ it("initial render and enable change actionn", () => {
renderComponent();
expect(passwordInput().value).toStrictEqual("");
expect(changeButton()).toBeDisabled();
- expect(continueButton()).toBeNull();
// Form complete
enterPassword("12345678");
@@ -127,32 +122,9 @@ describe("component RequireNewPassword", () => {
expect(changeButton()).not.toBeDisabled();
});
- it("not first login can continue", () => {
- surveyStore.dispatch({
- type: REFRESH_STATE,
- state: {
- hasEverLoggedIn: true,
- authentication: {
- errorMessage: "",
- state: RESET_PASSWORD,
- user: { username: TEST_USER },
- },
- },
- });
- renderComponent();
-
- expect(continueButton()).not.toBeNull();
- click(continueButton());
-
- expect(setAuthState).toHaveBeenCalledTimes(1);
- expect(setAuthState).toHaveBeenCalledWith(SIGNED_OUT);
- });
-
const passwordInput = () => container.querySelector("#passwordInput");
const changeButton = () => container.querySelector("#change-button");
const signInButton = () => container.querySelector("#signin-button");
- const continueButton = () =>
- container.querySelector("#continue-signed-out-button");
function enterPassword(value) {
act(() => {
diff --git a/surveyclient/src/components/auth/SignIn.jsx b/surveyclient/src/components/auth/SignIn.jsx
index 7baf642..140db9d 100644
--- a/surveyclient/src/components/auth/SignIn.jsx
+++ b/surveyclient/src/components/auth/SignIn.jsx
@@ -2,7 +2,6 @@ import React, { useEffect, useState } from "react";
import { signIn, setAuthState } from "../../model/AuthActions";
import { useDispatch, useSelector } from "react-redux";
import { REGISTER, FORGOT_PASSWORD_REQUEST } from "../../model/AuthStates";
-import ContinueSignedOutButton from "./ContinueSignedOutButton";
const EMAIL_ID = "emailInput";
const PASSWORD_ID = "passwordInput";
@@ -63,7 +62,6 @@ export default function SignIn() {
>
{loading ?
: LOGIN }
-
Don't have an account?{" "}
diff --git a/surveyclient/src/components/auth/SignIn.test.js b/surveyclient/src/components/auth/SignIn.test.js
index 652cd34..bde9752 100644
--- a/surveyclient/src/components/auth/SignIn.test.js
+++ b/surveyclient/src/components/auth/SignIn.test.js
@@ -4,14 +4,9 @@ import { act, Simulate } from "react-dom/test-utils";
import SignIn from "./SignIn";
import surveyStore from "../../model/SurveyModel";
import { Provider } from "react-redux";
-import {
- SET_AUTH_STATE,
- SET_AUTH_ERROR,
- REFRESH_STATE,
-} from "../../model/ActionTypes";
+import { SET_AUTH_STATE, SET_AUTH_ERROR } from "../../model/ActionTypes";
import {
SIGN_IN,
- SIGNED_OUT,
SIGNED_IN,
REGISTER,
FORGOT_PASSWORD_REQUEST,
@@ -48,12 +43,11 @@ describe("component SignIn", () => {
container = null;
});
- it("initial render and enable signIn action - first login", () => {
+ it("initial render and enable signIn action", () => {
renderComponent();
expect(emailInput().value).toStrictEqual("");
expect(passwordInput().value).toStrictEqual("");
expect(signInButton()).toBeDisabled();
- expect(continueButton()).toBeNull();
// Form complete
enterEmail(TEST_USER);
@@ -143,35 +137,12 @@ describe("component SignIn", () => {
expect(signInButton()).not.toBeDisabled();
});
- it("not first login can continue", () => {
- surveyStore.dispatch({
- type: REFRESH_STATE,
- state: {
- hasEverLoggedIn: true,
- authentication: {
- errorMessage: "",
- state: SIGN_IN,
- user: undefined,
- },
- },
- });
- renderComponent();
-
- expect(continueButton()).not.toBeNull();
- click(continueButton());
-
- expect(setAuthState).toHaveBeenCalledTimes(1);
- expect(setAuthState).toHaveBeenCalledWith(SIGNED_OUT);
- });
-
const emailInput = () => container.querySelector("#emailInput");
const passwordInput = () => container.querySelector("#passwordInput");
const registerButton = () => container.querySelector("#register-button");
const forgotPasswordButton = () =>
container.querySelector("#forgot-password-button");
const signInButton = () => container.querySelector("#signin-button");
- const continueButton = () =>
- container.querySelector("#continue-signed-out-button");
function enterEmail(value) {
act(() => {
diff --git a/surveyclient/src/model/ActionTypes.js b/surveyclient/src/model/ActionTypes.js
index a0ee7fb..6f6a335 100644
--- a/surveyclient/src/model/ActionTypes.js
+++ b/surveyclient/src/model/ActionTypes.js
@@ -1,5 +1,6 @@
export const SET_ANSWER = "setAnswer";
export const REFRESH_STATE = "refreshState";
+export const RESTART_SURVEY = "restartSurvey";
export const ADD_PHOTO = "addPhoto";
export const DELETE_PHOTO = "deletePhoto";
export const UPDATE_PHOTO_DESCRIPTION = "updatePhotoDescription";
diff --git a/surveyclient/src/model/SurveyModel.js b/surveyclient/src/model/SurveyModel.js
index 24e2291..86d7717 100644
--- a/surveyclient/src/model/SurveyModel.js
+++ b/surveyclient/src/model/SurveyModel.js
@@ -3,6 +3,7 @@ import thunk from "redux-thunk";
import {
SET_ANSWER,
REFRESH_STATE,
+ RESTART_SURVEY,
RESET_STATE,
ADD_PHOTO,
DELETE_PHOTO,
@@ -11,7 +12,7 @@ import {
SET_AUTH_ERROR,
CLEAR_AUTH_ERROR,
CONFIRM_WELCOME,
-} from "./ActionTypes.js";
+} from "./ActionTypes";
import {
sectionsContent,
SURVEY_VERSION,
@@ -102,6 +103,20 @@ export function surveyReducer(state = initialState(), action) {
writePhotos(newState);
return newState;
+ case RESTART_SURVEY:
+ // console.log("RESTART_SURVEY");
+ newState = {
+ ...state,
+ answers: createEmptyAnswers(),
+ answerCounts: createAnswerCounts(),
+ photos: {},
+ photoDetails: {},
+ initialisingState: false,
+ };
+ writeAnswers(newState);
+ writePhotos(newState);
+ return newState;
+
case REFRESH_STATE:
// console.log("REFRESH_STATE", action.state);
return action.state;
diff --git a/surveyclient/src/model/SurveyModel.test.js b/surveyclient/src/model/SurveyModel.test.js
index 6b5fd03..4dd5380 100644
--- a/surveyclient/src/model/SurveyModel.test.js
+++ b/surveyclient/src/model/SurveyModel.test.js
@@ -1,9 +1,10 @@
-import { surveyReducer, refreshState, loadPhoto } from "./SurveyModel.js";
+import { surveyReducer, refreshState, loadPhoto } from "./SurveyModel";
import configureStore from "redux-mock-store";
import thunk from "redux-thunk";
import {
SET_ANSWER,
REFRESH_STATE,
+ RESTART_SURVEY,
RESET_STATE,
ADD_PHOTO,
DELETE_PHOTO,
@@ -12,7 +13,7 @@ import {
SET_AUTH_ERROR,
CLEAR_AUTH_ERROR,
CONFIRM_WELCOME,
-} from "./ActionTypes.js";
+} from "./ActionTypes";
import { SIGNED_IN, SIGN_IN } from "./AuthStates";
import rfdc from "rfdc";
// local forage is mocked in setupTests.js
@@ -51,6 +52,21 @@ describe("surveyReducer", () => {
).toStrictEqual({ ...EMPTY_STATE, initialisingState: false });
});
+ it("action RESTART_SURVEY", () => {
+ expect(
+ surveyReducer(INPUT_STATE, {
+ type: RESTART_SURVEY,
+ })
+ ).toStrictEqual({
+ ...INPUT_STATE,
+ answers: EMPTY_STATE.answers,
+ answerCounts: EMPTY_STATE.answerCounts,
+ initialisingState: false,
+ photoDetails: {},
+ photos: {},
+ });
+ });
+
it("action REFRESH_STATE", () => {
expect(
surveyReducer(EMPTY_STATE, {