From e7307fe9c7e0b6b5f0ccaeded4ab508de6139361 Mon Sep 17 00:00:00 2001 From: Diego Serrano Date: Thu, 24 Oct 2019 11:24:16 -0500 Subject: [PATCH] Update third screen Add support for third screen settings values from the Admin panel. Changes - Update 3rd screens - Add tests --- CHANGELOG.md | 4 + README.md | 4 +- androidsdk/build.gradle | 1 - androidsdk/gradle.properties | 4 +- .../wootric/androidsdk/objects/Settings.java | 299 ++++++- .../objects/WootricCustomThankYou.java | 262 +++++- .../androidsdk/objects/WootricSocial.java | 82 ++ .../androidsdk/utils/SocialHandler.java | 8 +- .../com/wootric/androidsdk/utils/Utils.java | 4 + .../androidsdk/views/SurveyFragment.java | 4 +- .../androidsdk/views/SurveyLayout.java | 3 +- .../views/phone/SurveyLayoutPhone.java | 7 +- .../views/phone/ThankYouDialogFactory.java | 9 +- .../views/phone/ThankYouLayout.java | 25 +- .../views/support/SurveyFragment.java | 4 +- .../views/tablet/SurveyLayoutTablet.java | 49 +- .../res/layout/wootric_thank_you_layout.xml | 12 +- .../com/wootric/androidsdk/TestHelper.java | 15 +- .../androidsdk/objects/SettingsTest.java | 836 +++++++++++++++++- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- 21 files changed, 1499 insertions(+), 139 deletions(-) create mode 100644 androidsdk/src/main/java/com/wootric/androidsdk/objects/WootricSocial.java diff --git a/CHANGELOG.md b/CHANGELOG.md index b3663ac..dbd31af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.14.0 (2019-11-14) + +- Add support of admin panel values for 3rd screen + ## 2.13.0 (2019-08-09) - Add callbacks diff --git a/README.md b/README.md index 2c238af..b58b852 100644 --- a/README.md +++ b/README.md @@ -28,14 +28,14 @@ If you use Maven, you can include this library as a dependency: com.wootric wootric-sdk-android - 2.13.0 + 2.14.0 ``` ### Using Gradle ```xml -compile 'com.wootric:wootric-sdk-android:2.13.0' +compile 'com.wootric:wootric-sdk-android:2.14.0' ``` ## Initializing Wootric diff --git a/androidsdk/build.gradle b/androidsdk/build.gradle index 61c1d6a..f522a62 100644 --- a/androidsdk/build.gradle +++ b/androidsdk/build.gradle @@ -25,7 +25,6 @@ android { testOptions { unitTests.returnDefaultValues = true unitTests.includeAndroidResources = true - } sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } } } diff --git a/androidsdk/gradle.properties b/androidsdk/gradle.properties index 90d5780..e80855c 100644 --- a/androidsdk/gradle.properties +++ b/androidsdk/gradle.properties @@ -1,5 +1,5 @@ -VERSION_NAME=2.13.0 -VERSION_CODE=2130 +VERSION_NAME=2.14.0 +VERSION_CODE=2140 GROUP=com.wootric POM_DESCRIPTION=WootricSDK Android diff --git a/androidsdk/src/main/java/com/wootric/androidsdk/objects/Settings.java b/androidsdk/src/main/java/com/wootric/androidsdk/objects/Settings.java index cd7938e..b345201 100644 --- a/androidsdk/src/main/java/com/wootric/androidsdk/objects/Settings.java +++ b/androidsdk/src/main/java/com/wootric/androidsdk/objects/Settings.java @@ -35,6 +35,8 @@ import java.util.Date; +import static com.wootric.androidsdk.utils.Utils.isBlank; + /** * Created by maciejwitowski on 5/5/15. */ @@ -50,6 +52,12 @@ public class Settings implements Parcelable { private WootricCustomMessage adminPanelCustomMessage; private WootricCustomMessage localCustomMessage; + private WootricSocial adminPanelSocial; + private WootricSocial localSocial; + + private WootricCustomThankYou localCustomThankYou; + private WootricCustomThankYou adminPanelCustomThankYou; + private int timeDelay = Constants.NOT_SET; private boolean surveyImmediately; @@ -66,12 +74,8 @@ public class Settings implements Parcelable { private String languageCode; private String productName; private String recommendTarget; - private String facebookPageId; - private String twitterPage; private String surveyType; - private WootricCustomThankYou customThankYou; - private int surveyColor = Constants.NOT_SET; private int scoreColor = Constants.NOT_SET; private int thankYouButtonBackgroundColor = Constants.NOT_SET; @@ -80,12 +84,14 @@ public class Settings implements Parcelable { // Sets values from the argument settings only if they are not provided yet public void mergeWithSurveyServerSettings(Settings settings) { - if(settings == null) { + if (settings == null) { return; } this.adminPanelCustomMessage = settings.adminPanelCustomMessage; this.adminPanelTimeDelay = settings.adminPanelTimeDelay; + this.adminPanelCustomThankYou = settings.adminPanelCustomThankYou; + this.adminPanelSocial = settings.adminPanelSocial; this.localizedTexts = settings.localizedTexts; this.userID = settings.userID; this.accountID = settings.accountID; @@ -140,10 +146,10 @@ public void setSkipFeedbackScreen(boolean skipFeedbackScreen) { public int getTimeDelayInMillis() { int time; - if(timeDelay != Constants.NOT_SET) { + if (timeDelay != Constants.NOT_SET) { time = timeDelay; - } else if(adminPanelTimeDelay != Constants.NOT_SET) { + } else if (adminPanelTimeDelay != Constants.NOT_SET) { time = adminPanelTimeDelay; } else { time = 0; @@ -183,15 +189,15 @@ public String getBtnEditScore() { public String getFollowupQuestion(int score) { String followupQuestion = null; - if(localCustomMessage != null) { + if (localCustomMessage != null) { followupQuestion = localCustomMessage.getFollowupQuestionForScore(score, surveyType, surveyTypeScale); } - if(followupQuestion == null && adminPanelCustomMessage != null) { + if (isBlank(followupQuestion) && adminPanelCustomMessage != null) { followupQuestion = adminPanelCustomMessage.getFollowupQuestionForScore(score, surveyType, surveyTypeScale); } - if(followupQuestion == null) { + if (isBlank(followupQuestion)) { followupQuestion = localizedTexts.getFollowupQuestion(); } @@ -201,15 +207,15 @@ public String getFollowupQuestion(int score) { public String getFollowupPlaceholder(int score) { String followupPlaceholder = null; - if(localCustomMessage != null) { + if (localCustomMessage != null) { followupPlaceholder = localCustomMessage.getPlaceholderForScore(score, surveyType, surveyTypeScale); } - if(followupPlaceholder == null && adminPanelCustomMessage != null) { + if (isBlank(followupPlaceholder) && adminPanelCustomMessage != null) { followupPlaceholder = adminPanelCustomMessage.getPlaceholderForScore(score, surveyType, surveyTypeScale); } - if(followupPlaceholder == null) { + if (isBlank(followupPlaceholder)) { followupPlaceholder = localizedTexts.getFollowupPlaceholder(); } @@ -219,31 +225,182 @@ public String getFollowupPlaceholder(int score) { public String getCustomThankYouMessage(int score) { String thankYouMessage = null; - if(customThankYou != null) { - thankYouMessage = customThankYou.getTextForScore(score, surveyType, surveyTypeScale); + if (localCustomThankYou != null) { + thankYouMessage = localCustomThankYou.getTextForScore(score, surveyType, surveyTypeScale); + } + + if (isBlank(thankYouMessage) && adminPanelCustomThankYou != null) { + thankYouMessage = adminPanelCustomThankYou.getTextForScore(score, surveyType, surveyTypeScale); + + if (isBlank(thankYouMessage)) { + Score mScore = new Score(score, this.getSurveyType(), this.getSurveyTypeScale()); + if (mScore.isPromoter() && (adminPanelCustomThankYou.getUniqueByScore() || isTwitterEnabled() || isFacebookEnabled())) { + thankYouMessage = localizedTexts.getSocialShareQuestion(); + } + } } return thankYouMessage; } - public String getThankYouMessage() { - return localizedTexts.getFinalThankYou(); + + public String getFinalThankYou(int score) { + String finalThankYou = null; + + if (localCustomThankYou != null) { + finalThankYou = localCustomThankYou.getFinalThankYouForScore(score, surveyType, surveyTypeScale); + } + + if (isBlank(finalThankYou) && adminPanelCustomThankYou != null) { + finalThankYou = adminPanelCustomThankYou.getFinalThankYouForScore(score, surveyType, surveyTypeScale); + } + + if (isBlank(finalThankYou) && localizedTexts != null) { + finalThankYou = localizedTexts.getFinalThankYou(); + } + + return finalThankYou; } public String getThankYouLinkText(int score) { - return (customThankYou == null) ? - null : customThankYou.getLinkTextForScore(score, surveyType, surveyTypeScale); + String thankYouLinkText = null; + + if (localCustomThankYou != null) { + thankYouLinkText = localCustomThankYou.getLinkTextForScore(score, surveyType, surveyTypeScale); + } + + if (adminPanelCustomThankYou != null && thankYouLinkText == null) { + thankYouLinkText = adminPanelCustomThankYou.getLinkTextForScore(score, surveyType, surveyTypeScale); + } + + return thankYouLinkText; + } + + public Uri getThankYouLinkUri(String email, int score, String comment) { + Uri thankYouLinkUri = null; + + if (localCustomThankYou != null) { + thankYouLinkUri = localCustomThankYou.getLinkUri(score, surveyType, surveyTypeScale); + + } + + if (adminPanelCustomThankYou != null && thankYouLinkUri == null) { + thankYouLinkUri = adminPanelCustomThankYou.getLinkUri(score, surveyType, surveyTypeScale); + } + + if (thankYouLinkUri != null) { + thankYouLinkUri = addEmail(thankYouLinkUri, email, score); + thankYouLinkUri = addScore(thankYouLinkUri, score); + thankYouLinkUri = addComment(thankYouLinkUri, comment, score); + } + + return thankYouLinkUri; } - public Uri getThankYouLinkUri(int score, String comment) { - return (customThankYou == null) ? - null : customThankYou.getLinkUri(score, comment, surveyType, surveyTypeScale); + private Uri addEmail(Uri link, String email, int score) { + Boolean localEmailInUri = null; + Boolean adminEmailInUri = null; + boolean addEmail = false; + + if (localCustomThankYou != null) { + localEmailInUri = localCustomThankYou.getEmailInUri(score, surveyType, surveyTypeScale); + } + + if (adminPanelCustomThankYou != null) { + adminEmailInUri = adminPanelCustomThankYou.getEmailInUri(score, surveyType, surveyTypeScale); + } + + if (adminEmailInUri != null) { + addEmail = adminEmailInUri; + } + + if (localEmailInUri != null) { + addEmail = localEmailInUri; + } + + if (addEmail){ + link = link.buildUpon() + .appendQueryParameter("wootric_email", email) + .build(); + } + + return link; } - public boolean isThankYouActionConfigured(int score, String comment) { - return customThankYou != null && - customThankYou.getLinkTextForScore(score, surveyType, surveyTypeScale) != null && - customThankYou.getLinkUri(score, comment, surveyType, surveyTypeScale) != null; + private Uri addScore(Uri link, int score) { + Boolean localScoreInUri = null; + Boolean adminScoreInUri = null; + boolean addScore = false; + + if (localCustomThankYou != null) { + localScoreInUri = localCustomThankYou.getScoreInUri(score, surveyType, surveyTypeScale); + } + + if (adminPanelCustomThankYou != null) { + adminScoreInUri = adminPanelCustomThankYou.getScoreInUri(score, surveyType, surveyTypeScale); + } + + if (adminScoreInUri != null) { + addScore = adminScoreInUri; + } + + if (localScoreInUri != null) { + addScore = localScoreInUri; + } + + if (addScore){ + link = link.buildUpon() + .appendQueryParameter("wootric_score", String.valueOf(score)) + .build(); + } + + return link; + } + + private Uri addComment(Uri link, String comment, int score) { + Boolean localCommentInUri = null; + Boolean adminCommentInUri = null; + boolean addComment = false; + + if (localCustomThankYou != null) { + localCommentInUri = localCustomThankYou.getCommentInUri(score, surveyType, surveyTypeScale); + } + + if (adminPanelCustomThankYou != null) { + adminCommentInUri = adminPanelCustomThankYou.getCommentInUri(score, surveyType, surveyTypeScale); + } + + if (adminCommentInUri != null) { + addComment = adminCommentInUri; + } + + if (localCommentInUri != null) { + addComment = localCommentInUri; + } + + if (addComment){ + link = link.buildUpon() + .appendQueryParameter("wootric_comment", comment) + .build(); + } + + return link; + } + + public boolean isThankYouActionConfigured(String email, int score, String comment) { + return isLocalThankYouConfigured(score) || isAdminPanelThankYouConfigured(score); + } + + private boolean isLocalThankYouConfigured(int score) { + return localCustomThankYou != null && + localCustomThankYou.getLinkTextForScore(score, surveyType, surveyTypeScale) != null && + localCustomThankYou.getLinkUri(score, surveyType, surveyTypeScale) != null; + } + + private boolean isAdminPanelThankYouConfigured(int score) { + return adminPanelCustomThankYou != null && + adminPanelCustomThankYou.getLinkTextForScore(score, surveyType, surveyTypeScale) != null && + adminPanelCustomThankYou.getLinkUri(score, surveyType, surveyTypeScale) != null; } public String getSocialShareQuestion() { @@ -254,9 +411,6 @@ public String getSocialShareDecline() { return localizedTexts.getSocialShareDecline(); } - public String getFinalThankYou() { - return localizedTexts.getFinalThankYou(); - } public void setTimeDelay(int timeDelay) { this.timeDelay = timeDelay; @@ -298,6 +452,20 @@ public WootricCustomMessage getAdminPanelCustomMessage() { return adminPanelCustomMessage; } + public void setLocalCustomThankYou(WootricCustomThankYou localCustomThankYou) { + this.localCustomThankYou = localCustomThankYou; + } + + public WootricCustomThankYou getLocalCustomThankYou() { return localCustomThankYou; } + + public void setAdminPanelCustomThankYou(WootricCustomThankYou adminPanelCustomThankYou) { + this.adminPanelCustomThankYou = adminPanelCustomThankYou; + } + + public WootricCustomThankYou getAdminPanelCustomThankYou() { + return adminPanelCustomThankYou; + } + public void setAdminPanelTimeDelay(int adminPanelTimeDelay) { this.adminPanelTimeDelay = adminPanelTimeDelay; } @@ -371,21 +539,61 @@ public void setRecommendTarget(String recommendTarget) { } public String getFacebookPageId() { + String facebookPageId; + + facebookPageId = localSocial.getFacebookPageId(); + + if (isBlank(facebookPageId) && adminPanelSocial != null) { + facebookPageId = adminPanelSocial.getFacebookPageId(); + } + return facebookPageId; } - public void setFacebookPageId(String facebookPageId) { - this.facebookPageId = facebookPageId; - } + public void setFacebookPageId(String facebookPageId) { this.localSocial.setFacebookPageId(facebookPageId); } public String getTwitterPage() { + String twitterPage; + + twitterPage = localSocial.getTwitterPage(); + + if (isBlank(twitterPage) && adminPanelSocial != null) { + twitterPage = adminPanelSocial.getTwitterPage(); + } + return twitterPage; } - public void setTwitterPage(String twitterPage) { - this.twitterPage = twitterPage; + public boolean isTwitterEnabled() { + boolean twitterEnabled = false; + + if (adminPanelSocial != null && adminPanelSocial.isTwitterEnabled() != null) { + twitterEnabled = adminPanelSocial.isTwitterEnabled(); + } + + if (localSocial != null && localSocial.isTwitterEnabled() != null) { + twitterEnabled = localSocial.isTwitterEnabled(); + } + + return twitterEnabled; + } + + public boolean isFacebookEnabled() { + boolean facebookEnabled = false; + + if (adminPanelSocial != null && adminPanelSocial.isFacebookEnabled() != null) { + facebookEnabled = adminPanelSocial.isFacebookEnabled(); + } + + if (localSocial != null && localSocial.isFacebookEnabled() != null) { + facebookEnabled = localSocial.isFacebookEnabled(); + } + + return facebookEnabled; } + public void setTwitterPage(String twitterPage) { this.localSocial.setTwitterPage(twitterPage); } + public String getSurveyType() { return surveyType; } public int getSurveyTypeScale() { return surveyTypeScale; } @@ -395,7 +603,7 @@ public void setSurveyType(String surveyType) { } public void setCustomThankYou(WootricCustomThankYou customThankYou) { - this.customThankYou = customThankYou; + this.localCustomThankYou = customThankYou; } public void setCustomSurveyTypeScale(int customSurveyTypeScale) { @@ -448,6 +656,7 @@ public void setSocialSharingColor (int socialSharingColor) { } public Settings() { + this.localSocial = new WootricSocial(); } @Override @@ -474,10 +683,11 @@ public void writeToParcel(Parcel dest, int flags) { dest.writeString(this.languageCode); dest.writeString(this.productName); dest.writeString(this.recommendTarget); - dest.writeString(this.facebookPageId); - dest.writeString(this.twitterPage); dest.writeString(this.surveyType); - dest.writeParcelable(this.customThankYou, 0); + dest.writeParcelable(this.localCustomThankYou, 0); + dest.writeParcelable(this.adminPanelCustomThankYou, 0); + dest.writeParcelable(this.localSocial, 0); + dest.writeParcelable(this.adminPanelSocial, 0); } private Settings(Parcel in) { @@ -498,10 +708,11 @@ private Settings(Parcel in) { this.languageCode = in.readString(); this.productName = in.readString(); this.recommendTarget = in.readString(); - this.facebookPageId = in.readString(); - this.twitterPage = in.readString(); this.surveyType = in.readString(); - this.customThankYou = in.readParcelable(WootricCustomThankYou.class.getClassLoader()); + this.localCustomThankYou = in.readParcelable(WootricCustomThankYou.class.getClassLoader()); + this.adminPanelCustomThankYou = in.readParcelable(WootricCustomThankYou.class.getClassLoader()); + this.localSocial = in.readParcelable(WootricSocial.class.getClassLoader()); + this.adminPanelSocial = in.readParcelable(WootricSocial.class.getClassLoader()); } public static final Creator CREATOR = new Creator() { @@ -543,6 +754,12 @@ public static Settings fromJson(JSONObject settingsObject) throws JSONException JSONObject customMessagesJson = settingsObject.optJSONObject("messages"); settings.adminPanelCustomMessage = WootricCustomMessage.fromJson(customMessagesJson); + JSONObject customThankYouJson = settingsObject.optJSONObject("custom_thank_you"); + settings.adminPanelCustomThankYou = WootricCustomThankYou.fromJson(customThankYouJson); + + JSONObject socialJson = settingsObject.optJSONObject("social"); + settings.adminPanelSocial = WootricSocial.fromJson(socialJson); + return settings; } } \ No newline at end of file diff --git a/androidsdk/src/main/java/com/wootric/androidsdk/objects/WootricCustomThankYou.java b/androidsdk/src/main/java/com/wootric/androidsdk/objects/WootricCustomThankYou.java index a9119aa..11b3973 100644 --- a/androidsdk/src/main/java/com/wootric/androidsdk/objects/WootricCustomThankYou.java +++ b/androidsdk/src/main/java/com/wootric/androidsdk/objects/WootricCustomThankYou.java @@ -26,11 +26,19 @@ import android.os.Parcel; import android.os.Parcelable; +import org.json.JSONException; +import org.json.JSONObject; + /** * Created by maciejwitowski on 9/23/15. */ public class WootricCustomThankYou implements Parcelable { + private String finalThankYou; + private String detractorFinalThankYou; + private String passiveFinalThankYou; + private String promoterFinalThankYou; + private String text; private String detractorText; private String passiveText; @@ -46,8 +54,34 @@ public class WootricCustomThankYou implements Parcelable { private Uri passiveLinkUri; private Uri promoterLinkUri; - private boolean scoreInUrl; - private boolean commentInUrl; + private Boolean emailInUrl; + private Boolean detractorEmailInUrl; + private Boolean passiveEmailInUrl; + private Boolean promoterEmailInUrl; + private Boolean scoreInUrl; + private Boolean detractorScoreInUrl; + private Boolean passiveScoreInUrl; + private Boolean promoterScoreInUrl; + private Boolean commentInUrl; + private Boolean detractorCommentInUrl; + private Boolean passiveCommentInUrl; + private Boolean promoterCommentInUrl; + + private boolean uniqueByScore = false; + + public String getFinalThankYouForScore(int scoreValue, String surveyType, int surveyTypeScale) { + Score score = new Score(scoreValue, surveyType, surveyTypeScale); + + if(score.isDetractor() && detractorFinalThankYou != null) { + return detractorFinalThankYou; + } else if(score.isPassive() && passiveFinalThankYou != null) { + return passiveFinalThankYou; + } else if(score.isPromoter() && promoterFinalThankYou != null) { + return promoterFinalThankYou; + } else { + return finalThankYou; + } + } public String getTextForScore(int scoreValue, String surveyType, int surveyTypeScale) { Score score = new Score(scoreValue, surveyType, surveyTypeScale); @@ -77,24 +111,8 @@ public String getLinkTextForScore(int scoreValue, String surveyType, int surveyT } } - public Uri getLinkUri(int score, String comment, String surveyType, int surveyTypeScale) { - Uri uri = getLinkUriForScore(score, surveyType, surveyTypeScale); - - if(uri != null) { - if(scoreInUrl) { - uri = uri.buildUpon() - .appendQueryParameter("wootric_score", String.valueOf(score)) - .build(); - } - - if(commentInUrl) { - uri = uri.buildUpon() - .appendQueryParameter("wootric_comment", comment) - .build(); - } - } - - return uri; + public Uri getLinkUri(int score, String surveyType, int surveyTypeScale) { + return getLinkUriForScore(score, surveyType, surveyTypeScale); } private Uri getLinkUriForScore(int scoreValue, String surveyType, int surveyTypeScale) { @@ -111,6 +129,86 @@ private Uri getLinkUriForScore(int scoreValue, String surveyType, int surveyType } } + public Boolean getEmailInUri(int score, String surveyType, int surveyTypeScale) { + return getEmailInUriForScore(score, surveyType, surveyTypeScale); + } + + private Boolean getEmailInUriForScore(int scoreValue, String surveyType, int surveyTypeScale) { + Score score = new Score(scoreValue, surveyType, surveyTypeScale); + + if (this.uniqueByScore) { + if(score.isDetractor()) { + return detractorEmailInUrl; + } else if(score.isPassive()) { + return passiveEmailInUrl; + } else if(score.isPromoter()) { + return promoterEmailInUrl; + } + } + + return emailInUrl; + } + + public Boolean getScoreInUri(int score, String surveyType, int surveyTypeScale) { + return getScoreInUriForScore(score, surveyType, surveyTypeScale); + } + + private Boolean getScoreInUriForScore(int scoreValue, String surveyType, int surveyTypeScale) { + Score score = new Score(scoreValue, surveyType, surveyTypeScale); + + if (this.uniqueByScore) { + if(score.isDetractor()) { + return detractorScoreInUrl; + } else if(score.isPassive()) { + return passiveScoreInUrl; + } else if(score.isPromoter()) { + return promoterScoreInUrl; + } + } + + return scoreInUrl; + } + + public Boolean getCommentInUri(int score, String surveyType, int surveyTypeScale) { + return getCommentInUriForScore(score, surveyType, surveyTypeScale); + } + + private Boolean getCommentInUriForScore(int scoreValue, String surveyType, int surveyTypeScale) { + Score score = new Score(scoreValue, surveyType, surveyTypeScale); + + if (this.uniqueByScore) { + if(score.isDetractor()) { + return detractorCommentInUrl; + } else if(score.isPassive()) { + return passiveCommentInUrl; + } else if(score.isPromoter()) { + return promoterCommentInUrl; + } + } + + return commentInUrl; + } + + public boolean getUniqueByScore() { + return this.uniqueByScore; + } + + public void setFinalThankYou(String finalThankYou) { + this.finalThankYou = finalThankYou; + } + + public void setDetractorFinalThankYou(String detractorFinalThankYou) { + this.detractorFinalThankYou = detractorFinalThankYou; + } + + public void setPassiveFinalThankYou(String passiveFinalThankYou) { + this.passiveFinalThankYou = passiveFinalThankYou; + } + + public void setPromoterFinalThankYou(String promoterFinalThankYou) { + this.promoterFinalThankYou = promoterFinalThankYou; + } + public void setText(String text) { this.text = text; } @@ -159,14 +257,54 @@ public void setPromoterLinkUri(Uri promoterLinkUrl) { this.promoterLinkUri = promoterLinkUrl; } + public void setEmailInUrl(boolean emailInUrl) { + this.emailInUrl = emailInUrl; + } + + public void setDetractorEmailInUrl(boolean detractorEmailInUrl) { + this.detractorEmailInUrl = detractorEmailInUrl; + } + + public void setPassiveEmailInUrl(boolean passiveEmailInUrl) { + this.passiveEmailInUrl = passiveEmailInUrl; + } + + public void setPromoterEmailInUrl(boolean promoterEmailInUrl) { + this.promoterEmailInUrl = promoterEmailInUrl; + } + public void setScoreInUrl(boolean scoreInUrl) { this.scoreInUrl = scoreInUrl; } + public void setDetractorScoreInUrl(boolean detractorScoreInUrl) { + this.detractorScoreInUrl = detractorScoreInUrl; + } + + public void setPassiveScoreInUrl(boolean passiveScoreInUrl) { + this.passiveScoreInUrl = passiveScoreInUrl; + } + + public void setPromoterScoreInUrl(boolean promoterScoreInUrl) { + this.promoterScoreInUrl = promoterScoreInUrl; + } + public void setCommentInUrl(boolean commentInUrl) { this.commentInUrl = commentInUrl; } + public void setDetractorCommentInUrl(boolean detractorCommentInUrl) { + this.detractorCommentInUrl = detractorCommentInUrl; + } + + public void setPassiveCommentInUrl(boolean passiveCommentInUrl) { + this.passiveCommentInUrl = passiveCommentInUrl; + } + + public void setPromoterCommentInUrl(boolean promoterCommentInUrl) { + this.promoterCommentInUrl = promoterCommentInUrl; + } + @Override public int describeContents() { @@ -220,4 +358,88 @@ public WootricCustomThankYou[] newArray(int size) { return new WootricCustomThankYou[size]; } }; + + public static WootricCustomThankYou fromJson(JSONObject customThankYouJson) throws JSONException { + if(customThankYouJson == null) return null; + + WootricCustomThankYou wootricCustomThankYou = new WootricCustomThankYou(); + + JSONObject thankYouMessagesJson = customThankYouJson.optJSONObject("thank_you_messages"); + JSONObject thankYouLinksJson = customThankYouJson.optJSONObject("thank_you_links"); + + if (thankYouMessagesJson != null) { + JSONObject thankYouMainList = thankYouMessagesJson.optJSONObject("thank_you_main_list"); + JSONObject thankYouSetupList = thankYouMessagesJson.optJSONObject("thank_you_setup_list"); + + wootricCustomThankYou.finalThankYou = thankYouMessagesJson.optString("thank_you_main"); + wootricCustomThankYou.setText(thankYouMessagesJson.optString("thank_you_setup")); + + if (thankYouMainList != null) { + wootricCustomThankYou.uniqueByScore = true; + wootricCustomThankYou.detractorFinalThankYou = thankYouMainList.optString("detractor_thank_you_main"); + wootricCustomThankYou.passiveFinalThankYou = thankYouMainList.optString("passive_thank_you_main"); + wootricCustomThankYou.promoterFinalThankYou = thankYouMainList.optString("promoter_thank_you_main"); + } + + if (thankYouSetupList != null) { + wootricCustomThankYou.uniqueByScore = true; + wootricCustomThankYou.setDetractorText(thankYouSetupList.optString("detractor_thank_you_setup")); + wootricCustomThankYou.setPassiveText(thankYouSetupList.optString("passive_thank_you_setup")); + wootricCustomThankYou.setPromoterText(thankYouSetupList.optString("promoter_thank_you_setup")); + } + } + + if (thankYouLinksJson != null) { + JSONObject thankYouLinkTextList = thankYouLinksJson.optJSONObject("thank_you_link_text_list"); + JSONObject thankYouLinkUrlList = thankYouLinksJson.optJSONObject("thank_you_link_url_list"); + JSONObject thankYouLinkUrlSettingsList = thankYouLinksJson.optJSONObject("thank_you_link_url_settings_list"); + JSONObject thankYouLinkUrlSettings = thankYouLinksJson.optJSONObject("thank_you_link_url_settings"); + + wootricCustomThankYou.setLinkText(thankYouLinksJson.optString("thank_you_link_text", null)); + wootricCustomThankYou.setLinkUri(Uri.parse(thankYouLinksJson.optString("thank_you_link_url"))); + wootricCustomThankYou.setEmailInUrl(thankYouLinkUrlSettings.getBoolean("add_email_param_to_url")); + wootricCustomThankYou.setScoreInUrl(thankYouLinkUrlSettings.getBoolean("add_score_param_to_url")); + wootricCustomThankYou.setCommentInUrl(thankYouLinkUrlSettings.getBoolean("add_comment_param_to_url")); + + if (thankYouLinkTextList != null) { + wootricCustomThankYou.uniqueByScore = true; + wootricCustomThankYou.setDetractorLinkText(thankYouLinkTextList.optString("detractor_thank_you_link_text", null)); + wootricCustomThankYou.setPassiveLinkText(thankYouLinkTextList.optString("passive_thank_you_link_text", null)); + wootricCustomThankYou.setPromoterLinkText(thankYouLinkTextList.optString("promoter_thank_you_link_text", null)); + } + + if (thankYouLinkUrlList != null) { + wootricCustomThankYou.uniqueByScore = true; + wootricCustomThankYou.setDetractorLinkUri(Uri.parse(thankYouLinkUrlList.optString("detractor_thank_you_link_url"))); + wootricCustomThankYou.setPassiveLinkUri(Uri.parse(thankYouLinkUrlList.optString("passive_thank_you_link_url"))); + wootricCustomThankYou.setPromoterLinkUri(Uri.parse(thankYouLinkUrlList.optString("promoter_thank_you_link_url"))); + } + + if (thankYouLinkUrlSettingsList != null) { + JSONObject detractorThankYouLinkUrlSettingsList = thankYouLinkUrlSettingsList.optJSONObject("detractor_thank_you_link_url_settings"); + JSONObject passiveThankYouLinkUrlSettingsList = thankYouLinkUrlSettingsList.optJSONObject("passive_thank_you_link_url_settings"); + JSONObject promoterThankYouLinkUrlSettingsList = thankYouLinkUrlSettingsList.optJSONObject("promoter_thank_you_link_url_settings"); + + if (detractorThankYouLinkUrlSettingsList != null) { + wootricCustomThankYou.setDetractorEmailInUrl(detractorThankYouLinkUrlSettingsList.getBoolean("add_email_param_to_url")); + wootricCustomThankYou.setDetractorScoreInUrl(detractorThankYouLinkUrlSettingsList.getBoolean("add_score_param_to_url")); + wootricCustomThankYou.setDetractorCommentInUrl(detractorThankYouLinkUrlSettingsList.getBoolean("add_comment_param_to_url")); + } + + if (passiveThankYouLinkUrlSettingsList != null) { + wootricCustomThankYou.setPassiveEmailInUrl(passiveThankYouLinkUrlSettingsList.getBoolean("add_email_param_to_url")); + wootricCustomThankYou.setPassiveScoreInUrl(passiveThankYouLinkUrlSettingsList.getBoolean("add_score_param_to_url")); + wootricCustomThankYou.setPassiveCommentInUrl(passiveThankYouLinkUrlSettingsList.getBoolean("add_comment_param_to_url")); + } + + if (promoterThankYouLinkUrlSettingsList != null) { + wootricCustomThankYou.setPromoterEmailInUrl(promoterThankYouLinkUrlSettingsList.getBoolean("add_email_param_to_url")); + wootricCustomThankYou.setPromoterScoreInUrl(promoterThankYouLinkUrlSettingsList.getBoolean("add_score_param_to_url")); + wootricCustomThankYou.setPromoterCommentInUrl(promoterThankYouLinkUrlSettingsList.getBoolean("add_comment_param_to_url")); + } + } + } + + return wootricCustomThankYou; + } } diff --git a/androidsdk/src/main/java/com/wootric/androidsdk/objects/WootricSocial.java b/androidsdk/src/main/java/com/wootric/androidsdk/objects/WootricSocial.java new file mode 100644 index 0000000..13a7bda --- /dev/null +++ b/androidsdk/src/main/java/com/wootric/androidsdk/objects/WootricSocial.java @@ -0,0 +1,82 @@ +package com.wootric.androidsdk.objects; + +import android.net.Uri; +import android.os.Parcel; +import android.os.Parcelable; + +import org.json.JSONException; +import org.json.JSONObject; + +public class WootricSocial implements Parcelable { + private String facebookPageId; + private String twitterPage; + + private Boolean facebookEnabled; + private Boolean twitterEnabled; + + public void setFacebookPageId(String facebookPageId) { this.facebookPageId = facebookPageId; } + + public String getFacebookPageId() { return this.facebookPageId; } + + public void setTwitterPage(String twitterPage) { this.twitterPage = twitterPage; } + + public String getTwitterPage() { return twitterPage; } + + public Boolean isTwitterEnabled() { + return twitterEnabled; + } + + public Boolean isFacebookEnabled() { + return facebookEnabled; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(this.facebookPageId); + dest.writeString(this.twitterPage); + dest.writeByte(facebookEnabled ? (byte) 1 : (byte) 0); + dest.writeByte(twitterEnabled ? (byte) 1 : (byte) 0); + } + + public WootricSocial() { + } + + private WootricSocial(Parcel in) { + this.facebookPageId = in.readString(); + this.twitterPage = in.readString(); + this.facebookEnabled = in.readByte() != 0; + this.twitterEnabled = in.readByte() != 0; + } + + public static final Creator CREATOR = new Creator() { + public WootricSocial createFromParcel(Parcel source) { + return new WootricSocial(source); + } + + public WootricSocial[] newArray(int size) { + return new WootricSocial[size]; + } + }; + + public static WootricSocial fromJson(JSONObject socialJson) throws JSONException { + if(socialJson == null) return null; + + WootricSocial wootricSocial = new WootricSocial(); + + wootricSocial.facebookEnabled = socialJson.optBoolean("facebook_enabled"); + wootricSocial.twitterEnabled = socialJson.optBoolean("twitter_enabled"); + + JSONObject accountsJson = socialJson.optJSONObject("accounts"); + if (accountsJson != null) { + wootricSocial.facebookPageId = accountsJson.optString("facebook_page"); + wootricSocial.twitterPage = accountsJson.optString("twitter_account"); + } + + return wootricSocial; + } +} diff --git a/androidsdk/src/main/java/com/wootric/androidsdk/utils/SocialHandler.java b/androidsdk/src/main/java/com/wootric/androidsdk/utils/SocialHandler.java index 8a1bcb9..1f0d580 100644 --- a/androidsdk/src/main/java/com/wootric/androidsdk/utils/SocialHandler.java +++ b/androidsdk/src/main/java/com/wootric/androidsdk/utils/SocialHandler.java @@ -41,10 +41,10 @@ public SocialHandler(Context mContext) { this.mContext = mContext; } - public void shareOnFacebook(String facebookId) { + public void shareOnFacebook(String facebookUrl) { if (mContext == null) return; - String urlToShare = "https://www.facebook.com/" + facebookId; + String urlToShare = facebookUrl; Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, urlToShare); @@ -67,10 +67,10 @@ public void shareOnFacebook(String facebookId) { mContext.startActivity(intent); } - public void goToFacebook(String facebookId) { + public void goToFacebook(String facebookUrl) { if (mContext == null) return; - final String url = "https://www.facebook.com/" + facebookId; + final String url = facebookUrl; final Uri facebookSchemeUri = Uri.parse("fb://facewebmodal/f?href=" + url); Intent intent = new Intent(Intent.ACTION_VIEW, facebookSchemeUri); diff --git a/androidsdk/src/main/java/com/wootric/androidsdk/utils/Utils.java b/androidsdk/src/main/java/com/wootric/androidsdk/utils/Utils.java index 8661a79..c36748f 100644 --- a/androidsdk/src/main/java/com/wootric/androidsdk/utils/Utils.java +++ b/androidsdk/src/main/java/com/wootric/androidsdk/utils/Utils.java @@ -47,6 +47,10 @@ public static boolean isNotEmpty(String s) { return s != null && !s.isEmpty() && !isWhitespaceString(s); } + public static boolean isBlank(String s) { + return s == null || (s != null && (s.isEmpty() || isWhitespaceString(s))); + } + private static boolean isWhitespaceString(String s) { return s.trim().length() == 0; } diff --git a/androidsdk/src/main/java/com/wootric/androidsdk/views/SurveyFragment.java b/androidsdk/src/main/java/com/wootric/androidsdk/views/SurveyFragment.java index 8fe08de..5f576a3 100644 --- a/androidsdk/src/main/java/com/wootric/androidsdk/views/SurveyFragment.java +++ b/androidsdk/src/main/java/com/wootric/androidsdk/views/SurveyFragment.java @@ -173,7 +173,7 @@ public void onClick(View v) { @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - mSurveyLayout.initWithSettings(mSettings); + mSurveyLayout.initWithSettings(mSettings, mEndUser.getEmail()); } @Override @@ -297,7 +297,7 @@ public void onTwitterBtnClick() { @Override public void onThankYouActionClick() { - final Uri uri = mSettings.getThankYouLinkUri(mSurveyLayout.getSelectedScore(), mSurveyLayout.getFeedback()); + final Uri uri = mSettings.getThankYouLinkUri(mSurveyLayout.getEmail(), mSurveyLayout.getSelectedScore(), mSurveyLayout.getFeedback()); final Intent intent = new Intent(Intent.ACTION_VIEW, uri); final Activity activity = getActivity(); diff --git a/androidsdk/src/main/java/com/wootric/androidsdk/views/SurveyLayout.java b/androidsdk/src/main/java/com/wootric/androidsdk/views/SurveyLayout.java index 862f8cf..a322a88 100644 --- a/androidsdk/src/main/java/com/wootric/androidsdk/views/SurveyLayout.java +++ b/androidsdk/src/main/java/com/wootric/androidsdk/views/SurveyLayout.java @@ -31,9 +31,10 @@ public interface SurveyLayout { void setSurveyLayoutListener(SurveyLayoutListener surveyLayoutListener); - void initWithSettings(Settings settings); + void initWithSettings(Settings settings, String email); int getSelectedScore(); String getFeedback(); + String getEmail(); void showThankYouLayout(); } diff --git a/androidsdk/src/main/java/com/wootric/androidsdk/views/phone/SurveyLayoutPhone.java b/androidsdk/src/main/java/com/wootric/androidsdk/views/phone/SurveyLayoutPhone.java index da46b50..c3f7651 100644 --- a/androidsdk/src/main/java/com/wootric/androidsdk/views/phone/SurveyLayoutPhone.java +++ b/androidsdk/src/main/java/com/wootric/androidsdk/views/phone/SurveyLayoutPhone.java @@ -85,6 +85,7 @@ public class SurveyLayoutPhone extends LinearLayout private int mColorEnabled; private Score mScore; + private String mEmail; private String mSurveyType; private int mScaleMinimum; private int mScaleMaximum; @@ -311,8 +312,9 @@ public int getSelectedScore() { } @Override - public void initWithSettings(Settings settings) { + public void initWithSettings(Settings settings, String email) { mSettings = settings; + mEmail = email; mSurveyType = mSettings.getSurveyType(); initResources(); @@ -419,7 +421,7 @@ private void setupThankYouState() { setKeyboardVisibility(false); mThankYouLayout.setVisibility(VISIBLE); - mThankYouLayout.initValues(mSettings, mRatingBar.getSelectedScore(), getFeedback()); + mThankYouLayout.initValues(mSettings, mEmail, mRatingBar.getSelectedScore(), getFeedback()); } private void updateSubmitBtn(boolean enable) { @@ -439,6 +441,7 @@ private boolean isFeedbackState() { public String getFeedback() { return mEtFeedback.getText().toString(); } + public String getEmail() { return mEmail; } private void setKeyboardVisibility(boolean showKeyboard) { final InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE); diff --git a/androidsdk/src/main/java/com/wootric/androidsdk/views/phone/ThankYouDialogFactory.java b/androidsdk/src/main/java/com/wootric/androidsdk/views/phone/ThankYouDialogFactory.java index 8823b26..e9ce87a 100644 --- a/androidsdk/src/main/java/com/wootric/androidsdk/views/phone/ThankYouDialogFactory.java +++ b/androidsdk/src/main/java/com/wootric/androidsdk/views/phone/ThankYouDialogFactory.java @@ -40,14 +40,9 @@ public class ThankYouDialogFactory { public static Dialog create(Context context, Settings settings, final int score, final String text, final WootricSurveyCallback surveyCallback) { AlertDialog thankYouDialog = new AlertDialog.Builder(context).create(); thankYouDialog.setCancelable(false); - final String customThankYouText = settings.getCustomThankYouMessage(score); - final String thankYouText = settings.getThankYouMessage(); + final String thankYouText = settings.getFinalThankYou(score); - if (customThankYouText != null) { - thankYouDialog.setMessage(customThankYouText); - } else { - thankYouDialog.setMessage(thankYouText); - } + thankYouDialog.setMessage(thankYouText); thankYouDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "OK", new DialogInterface.OnClickListener() { @Override diff --git a/androidsdk/src/main/java/com/wootric/androidsdk/views/phone/ThankYouLayout.java b/androidsdk/src/main/java/com/wootric/androidsdk/views/phone/ThankYouLayout.java index 8cc0c40..6d44e1b 100644 --- a/androidsdk/src/main/java/com/wootric/androidsdk/views/phone/ThankYouLayout.java +++ b/androidsdk/src/main/java/com/wootric/androidsdk/views/phone/ThankYouLayout.java @@ -52,6 +52,7 @@ public class ThankYouLayout extends RelativeLayout { private LinearLayout mLayoutTwitter; private TextView mTvThankYou; + private TextView mTvThankYouSetup; private TextView mTvFacebookLike; private TextView mTvFacebook; private TextView mTvTwitter; @@ -65,6 +66,7 @@ public class ThankYouLayout extends RelativeLayout { private String mFeedback; private int mScore; + private String mEmail; private Settings mSettings; public ThankYouLayout(Context context) { @@ -89,6 +91,7 @@ private void init(Context context) { mLayoutBody = (RelativeLayout) findViewById(R.id.wootric_thank_you_layout_body); mTvThankYou = (TextView) mLayoutBody.findViewById(R.id.wootric_tv_thank_you); + mTvThankYouSetup = (TextView) mLayoutBody.findViewById(R.id.wootric_tv_thank_you_setup); mFaFacebookLike = (TextView) mLayoutBody.findViewById(R.id.wootric_fa_facebook_like); mFaFacebook = (TextView) mLayoutBody.findViewById(R.id.wootric_fa_facebook); mFaTwitter = (TextView) mLayoutBody.findViewById(R.id.wootric_fa_twitter); @@ -176,8 +179,9 @@ public void setThankYouLayoutListener(ThankYouLayoutListener thankYouLayoutListe mThankYouLayoutListener = thankYouLayoutListener; } - public void initValues(Settings settings, int score, String feedback) { + public void initValues(Settings settings, String email, int score, String feedback) { mSettings = settings; + mEmail = email; mScore = score; mFeedback = feedback; @@ -185,13 +189,13 @@ public void initValues(Settings settings, int score, String feedback) { } private void initValues() { - final String customThankYouText = mSettings.getCustomThankYouMessage(mScore); - final String thankYouText = mSettings.getThankYouMessage(); + final String thankYouText = mSettings.getFinalThankYou(mScore); + final String thankYouSetupText = mSettings.getCustomThankYouMessage(mScore); - if (customThankYouText != null) { - mTvThankYou.setText(customThankYouText); - } else { - mTvThankYou.setText(thankYouText); + mTvThankYou.setText(thankYouText); + + if (thankYouSetupText != null) { + mTvThankYouSetup.setText(thankYouSetupText); } mBtnDone.setTextColor(getResources().getColor(mSettings.getSurveyColor())); @@ -204,7 +208,7 @@ private void initValues() { } private void initThankYouActionBtn() { - boolean shouldShowThankYouAction = mSettings.isThankYouActionConfigured(mScore, mFeedback); + boolean shouldShowThankYouAction = mSettings.isThankYouActionConfigured(mEmail, mScore, mFeedback); final String thankYouLinkText = mSettings.getThankYouLinkText(mScore); final int thankYouBackgroundColor = getResources().getColor(mSettings.getThankYouButtonBackgroundColor()); @@ -215,7 +219,9 @@ private void initThankYouActionBtn() { private void initSocialLinks() { Score score = new Score(mScore, mSettings.getSurveyType(), mSettings.getSurveyTypeScale()); - boolean shouldShowFacebookBtn = (score.isPromoter() && mSettings.getFacebookPageId() != null); + boolean shouldShowFacebookBtn = (score.isPromoter() && + mSettings.isFacebookEnabled() && + mSettings.getFacebookPageId() != null); mLayoutFacebook.setVisibility(shouldShowFacebookBtn ? VISIBLE : GONE); mLayoutFacebookLike.setVisibility(shouldShowFacebookBtn ? VISIBLE : GONE); @@ -225,6 +231,7 @@ private void initSocialLinks() { boolean shouldShowTwitterBtn = score.isPromoter() && + mSettings.isTwitterEnabled() && mSettings.getTwitterPage() != null && mFeedback != null && !mFeedback.isEmpty(); diff --git a/androidsdk/src/main/java/com/wootric/androidsdk/views/support/SurveyFragment.java b/androidsdk/src/main/java/com/wootric/androidsdk/views/support/SurveyFragment.java index fa175e5..4eb4022 100644 --- a/androidsdk/src/main/java/com/wootric/androidsdk/views/support/SurveyFragment.java +++ b/androidsdk/src/main/java/com/wootric/androidsdk/views/support/SurveyFragment.java @@ -174,7 +174,7 @@ public void onClick(View v) { @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - mSurveyLayout.initWithSettings(mSettings); + mSurveyLayout.initWithSettings(mSettings, mEndUser.getEmail()); } @Override @@ -298,7 +298,7 @@ public void onTwitterBtnClick() { @Override public void onThankYouActionClick() { - final Uri uri = mSettings.getThankYouLinkUri(mSurveyLayout.getSelectedScore(), mSurveyLayout.getFeedback()); + final Uri uri = mSettings.getThankYouLinkUri(mSurveyLayout.getEmail(), mSurveyLayout.getSelectedScore(), mSurveyLayout.getFeedback()); final Intent intent = new Intent(Intent.ACTION_VIEW, uri); final Activity activity = getActivity(); diff --git a/androidsdk/src/main/java/com/wootric/androidsdk/views/tablet/SurveyLayoutTablet.java b/androidsdk/src/main/java/com/wootric/androidsdk/views/tablet/SurveyLayoutTablet.java index 84e9e6d..2398984 100644 --- a/androidsdk/src/main/java/com/wootric/androidsdk/views/tablet/SurveyLayoutTablet.java +++ b/androidsdk/src/main/java/com/wootric/androidsdk/views/tablet/SurveyLayoutTablet.java @@ -97,6 +97,7 @@ public class SurveyLayoutTablet extends LinearLayout private int mScoresTop; private ScoreView[] mScoreViews; private int mCurrentScore = -1; + private String mCurrentEmail; private SurveyLayoutListener mSurveyLayoutListener; @@ -241,8 +242,9 @@ public void setSurveyLayoutListener(SurveyLayoutListener surveyLayoutListener) { } @Override - public void initWithSettings(Settings settings) { + public void initWithSettings(Settings settings, String email) { mSettings = settings; + mCurrentEmail = email; mSurveyType = mSettings.getSurveyType(); mScore = new Score(mCurrentScore, mSurveyType, mSettings.getSurveyTypeScale()); @@ -295,7 +297,7 @@ private void setFeedbackTexts() { private void initThankYouActionBtn() { final String feedback = getFeedback(); - boolean shouldShowThankYouAction = mSettings.isThankYouActionConfigured(mCurrentScore, feedback); + boolean shouldShowThankYouAction = mSettings.isThankYouActionConfigured(mCurrentEmail, mCurrentScore, feedback); final String thankYouLinkText = mSettings.getThankYouLinkText(mCurrentScore); mBtnThankYouAction.setVisibility(shouldShowThankYouAction ? VISIBLE : GONE); @@ -303,8 +305,11 @@ private void initThankYouActionBtn() { } private void setupThankYouState() { + final String feedback = getFeedback(); mSurveyLayout.setVisibility(GONE); + boolean shouldShowThankYouAction = mSettings.isThankYouActionConfigured(mCurrentEmail, mCurrentScore, feedback) ; + initThankYouActionBtn(); initSocialLinks(); @@ -316,17 +321,16 @@ private void setupThankYouState() { mBtnThankYouDone.setVisibility(shouldShowThankYouDone ? GONE : VISIBLE); mBtnThankYouDone.setText(mSettings.getSocialShareDecline()); - final String customThankYouText = mSettings.getCustomThankYouMessage(mCurrentScore); - final String thankYouText = mSettings.getThankYouMessage(); + final String thankYouText = mSettings.getFinalThankYou(mCurrentScore); + final String thankYouSetupText = mSettings.getCustomThankYouMessage(mCurrentScore); + + mTvThankYou.setText(thankYouText); - if (customThankYouText != null) { - mTvCustomThankYou.setText(customThankYouText); + if (thankYouSetupText != null) { + mTvCustomThankYou.setText(thankYouSetupText); mTvCustomThankYou.setVisibility(VISIBLE); - mTvThankYou.setVisibility(GONE); } else { - mTvThankYou.setText(thankYouText); mTvCustomThankYou.setVisibility(GONE); - mTvThankYou.setVisibility(VISIBLE); } mThankYouLayout.setAlpha(0); @@ -335,7 +339,10 @@ private void setupThankYouState() { } private void initSocialLinks() { - boolean shouldShowFacebookBtn = (mScore.isPromoter() && mSettings.getFacebookPageId() != null); + Score score = new Score(mCurrentScore, mSettings.getSurveyType(), mSettings.getSurveyTypeScale()); + boolean shouldShowFacebookBtn = (score.isPromoter() && + mSettings.isFacebookEnabled() && + mSettings.getFacebookPageId() != null); mBtnFacebook.setVisibility(shouldShowFacebookBtn ? VISIBLE : GONE); mBtnFacebookLike.setVisibility(shouldShowFacebookBtn ? VISIBLE : GONE); @@ -343,11 +350,11 @@ private void initSocialLinks() { final String feedback = getFeedback(); boolean shouldShowTwitterBtn = - mScore.isPromoter() && + score.isPromoter() && + mSettings.isTwitterEnabled() && mSettings.getTwitterPage() != null && feedback != null && !feedback.isEmpty(); - mBtnTwitter.setVisibility(shouldShowTwitterBtn ? VISIBLE : GONE); } @@ -365,10 +372,11 @@ private void setKeyboardVisibility(boolean showKeyboard) { } } - private void setupState(int surveyState, int selectedScore) { + private void setupState(String email, int surveyState, int selectedScore) { updateState(surveyState); mCurrentScore = selectedScore; + mCurrentEmail = email; if(mCurrentScore != Constants.NOT_SET) { mScoreViews[mCurrentScore].setSelected(true); } @@ -384,6 +392,9 @@ public String getFeedback() { return mEtFeedback.getText().toString(); } + @Override + public String getEmail() { return mCurrentEmail; } + @Override public void showThankYouLayout() { updateState(STATE_THANK_YOU); @@ -486,12 +497,13 @@ protected Parcelable onSaveInstanceState() { protected void onRestoreInstanceState(Parcelable state) { SurveyLayoutSavedState savedState = (SurveyLayoutSavedState) state; super.onRestoreInstanceState(savedState.getSuperState()); - setupState(savedState.getCurrentState(), savedState.getCurrentScore()); + setupState(savedState.getCurrentEmail(), savedState.getCurrentState(), savedState.getCurrentScore()); } private static class SurveyLayoutSavedState extends View.BaseSavedState { private int currentState; private int currentScore; + private String currentEmail; public SurveyLayoutSavedState(Parcelable superState) { super(superState); @@ -499,10 +511,19 @@ public SurveyLayoutSavedState(Parcelable superState) { public SurveyLayoutSavedState(Parcel source) { super(source); + currentEmail = source.readString(); currentState = source.readInt(); currentScore = source.readInt(); } + public String getCurrentEmail() { + return currentEmail; + } + + public void setCurrentEmail(String currentEmail) { + this.currentEmail = currentEmail; + } + public int getCurrentState() { return currentState; } diff --git a/androidsdk/src/main/res/layout/wootric_thank_you_layout.xml b/androidsdk/src/main/res/layout/wootric_thank_you_layout.xml index 4c36966..9aacd80 100644 --- a/androidsdk/src/main/res/layout/wootric_thank_you_layout.xml +++ b/androidsdk/src/main/res/layout/wootric_thank_you_layout.xml @@ -16,11 +16,20 @@ android:text="@string/wootric_thank_you" android:textColor="@android:color/black" /> + + @@ -127,4 +136,5 @@ android:padding="@dimen/wootric_btn_padding" android:layout_marginTop="280dp" android:text="@string/wootric_example_btn_dismiss"/> + \ No newline at end of file diff --git a/androidsdk/src/test/java/com/wootric/androidsdk/TestHelper.java b/androidsdk/src/test/java/com/wootric/androidsdk/TestHelper.java index edd265e..e05f1d3 100644 --- a/androidsdk/src/test/java/com/wootric/androidsdk/TestHelper.java +++ b/androidsdk/src/test/java/com/wootric/androidsdk/TestHelper.java @@ -4,7 +4,6 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.support.v4.app.FragmentActivity; -import android.test.mock.MockPackageManager; import com.wootric.androidsdk.objects.EndUser; import com.wootric.androidsdk.objects.User; @@ -13,7 +12,6 @@ import java.lang.ref.WeakReference; public class TestHelper { - private static final String CLIENT_ID = "testClientId"; private static final String CLIENT_SECRET = "testClientSecret"; private static final String ACCOUNT_TOKEN = "testAccountToken"; @@ -35,7 +33,7 @@ public static PreferencesUtils testPreferenceUtils() { public static final FragmentActivity TEST_FRAGMENT_ACTIVITY = new FragmentActivity() { @Override public PackageManager getPackageManager() { - return TEST_PACKAGE_MANAGER; + return getPackageManager(); } @Override @@ -52,15 +50,4 @@ public Context getApplicationContext() { private static final ApplicationInfo TEST_APPLICATION_INFO = new ApplicationInfo() { public static final String packageName = ""; }; - - private static final MockPackageManager TEST_PACKAGE_MANAGER = new MockPackageManager() { - @Override - public ApplicationInfo getApplicationInfo(String packageName, int flags) throws NameNotFoundException { - return TEST_APPLICATION_INFO; - } - @Override - public CharSequence getApplicationLabel(ApplicationInfo info) { - return "com.test.app"; - } - }; } diff --git a/androidsdk/src/test/java/com/wootric/androidsdk/objects/SettingsTest.java b/androidsdk/src/test/java/com/wootric/androidsdk/objects/SettingsTest.java index b350942..569be89 100644 --- a/androidsdk/src/test/java/com/wootric/androidsdk/objects/SettingsTest.java +++ b/androidsdk/src/test/java/com/wootric/androidsdk/objects/SettingsTest.java @@ -1,26 +1,51 @@ package com.wootric.androidsdk.objects; +import android.net.Uri; +import android.util.Log; + import com.wootric.androidsdk.Constants; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; import java.util.Date; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.doReturn; -@RunWith(MockitoJUnitRunner.class) +@RunWith(RobolectricTestRunner.class) public class SettingsTest { + public static final String LOCALIZED_FINAL_THANK_YOU = "Localized final thank you!"; + public static final String LOCALIZED_THANK_YOU_SETUP = "Localized thank you setup"; + + public static final String EMAIL = "nps@test.com"; + @Mock LocalizedTexts mockLocalizedTexts; @Mock WootricCustomMessage mockCustomMessage; + @Mock + WootricCustomThankYou mockCustomThankYou; + + @Before + public void setUpMockito() { + MockitoAnnotations.initMocks(this); + } + + @After + public void tearDownMockito() { + Mockito.validateMockitoUsage(); + } + @Test public void whenTimeFromIsNotSet_itReturnsTrue() throws Exception { Settings settings = new Settings(); @@ -116,7 +141,7 @@ public void delegatesMethodsToLocalizedTexts() { assertThat(settings.getAnchorNotLikely()).isEqualTo("not likely"); assertThat(settings.getBtnSubmit()).isEqualTo("SUBMIT"); assertThat(settings.getBtnDismiss()).isEqualTo("DISMISS"); - assertThat(settings.getFinalThankYou()).isEqualTo("Thank you!"); + assertThat(settings.getFinalThankYou(0)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); } @Test @@ -190,58 +215,841 @@ public void whenCustomMessageIsNotSet_returnsLocalizedTextFollowupQuestionPlaceh } @Test - public void whenCustomThankYouIsSet_returnsCustomThankYou() { + public void whenFinalThankYouIsNotSet_returnsLocalizedText() { + mockLocalizedTexts(); + + Settings settings = new Settings(); + settings.setLocalCustomThankYou(null); + settings.setAdminPanelCustomThankYou(null); + settings.setLocalizedTexts(mockLocalizedTexts); + + assertThat(settings.getFinalThankYou(10)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + } + + @Test + public void whenFinalThankYouIsSet_returnsLocalFinalThankYou() { + String finalThankYou = "Local final thank you"; + Settings settings = new Settings(); WootricCustomThankYou customThankYou = new WootricCustomThankYou(); - customThankYou.setText("thank you"); + customThankYou.setFinalThankYou(finalThankYou); settings.setCustomThankYou(customThankYou); settings.setSurveyType("NPS"); - assertThat(settings.getCustomThankYouMessage(10)).isEqualTo("thank you"); + assertThat(settings.getFinalThankYou(10)).isEqualTo(finalThankYou); + assertThat(settings.getFinalThankYou(8)).isEqualTo(finalThankYou); + assertThat(settings.getFinalThankYou(0)).isEqualTo(finalThankYou); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getFinalThankYou(5)).isEqualTo(finalThankYou); + assertThat(settings.getFinalThankYou(3)).isEqualTo(finalThankYou); + assertThat(settings.getFinalThankYou(1)).isEqualTo(finalThankYou); + + settings.setSurveyType("CES"); + + assertThat(settings.getFinalThankYou(7)).isEqualTo(finalThankYou); + assertThat(settings.getFinalThankYou(5)).isEqualTo(finalThankYou); + assertThat(settings.getFinalThankYou(1)).isEqualTo(finalThankYou); } @Test - public void whenCustomThankYouIsNotSet_returnsNull() { + public void whenPromoterFinalThankYouIsSet_returnsLocalPromoterFinalThankYou() { + mockLocalizedTexts(); + String promoterFinalThankYou = "Local promoter final thank you"; + Settings settings = new Settings(); + WootricCustomThankYou customThankYou = new WootricCustomThankYou(); + customThankYou.setPromoterFinalThankYou(promoterFinalThankYou); + settings.setCustomThankYou(customThankYou); + settings.setLocalizedTexts(mockLocalizedTexts); + settings.setSurveyType("NPS"); + + assertThat(settings.getFinalThankYou(10)).isEqualTo(promoterFinalThankYou); + assertThat(settings.getFinalThankYou(8)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + assertThat(settings.getFinalThankYou(0)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getFinalThankYou(5)).isEqualTo(promoterFinalThankYou); + assertThat(settings.getFinalThankYou(3)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + assertThat(settings.getFinalThankYou(1)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + + settings.setSurveyType("CES"); + + assertThat(settings.getFinalThankYou(7)).isEqualTo(promoterFinalThankYou); + assertThat(settings.getFinalThankYou(5)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + assertThat(settings.getFinalThankYou(1)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + } + + @Test + public void whenPassiveFinalThankYouIsSet_returnsLocalPassiveFinalThankYou() { mockLocalizedTexts(); + String passiveFinalThankYou = "Local passive final thank you"; + + Settings settings = new Settings(); + WootricCustomThankYou customThankYou = new WootricCustomThankYou(); + customThankYou.setPassiveFinalThankYou(passiveFinalThankYou); + settings.setCustomThankYou(customThankYou); settings.setLocalizedTexts(mockLocalizedTexts); + settings.setSurveyType("NPS"); + + assertThat(settings.getFinalThankYou(10)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + assertThat(settings.getFinalThankYou(8)).isEqualTo(passiveFinalThankYou); + assertThat(settings.getFinalThankYou(0)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getFinalThankYou(5)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + assertThat(settings.getFinalThankYou(3)).isEqualTo(passiveFinalThankYou); + assertThat(settings.getFinalThankYou(1)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + + settings.setSurveyType("CES"); + + assertThat(settings.getFinalThankYou(7)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + assertThat(settings.getFinalThankYou(5)).isEqualTo(passiveFinalThankYou); + assertThat(settings.getFinalThankYou(1)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + } + + @Test + public void whenDetractorFinalThankYouIsSet_returnsLocalDetractorFinalThankYou() { + mockLocalizedTexts(); + String detractorFinalThankYou = "Local detractor final thank you"; + + Settings settings = new Settings(); + WootricCustomThankYou customThankYou = new WootricCustomThankYou(); + customThankYou.setDetractorFinalThankYou(detractorFinalThankYou); + settings.setCustomThankYou(customThankYou); + settings.setLocalizedTexts(mockLocalizedTexts); + settings.setSurveyType("NPS"); + + assertThat(settings.getFinalThankYou(10)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + assertThat(settings.getFinalThankYou(8)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + assertThat(settings.getFinalThankYou(0)).isEqualTo(detractorFinalThankYou); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getFinalThankYou(5)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + assertThat(settings.getFinalThankYou(3)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + assertThat(settings.getFinalThankYou(1)).isEqualTo(detractorFinalThankYou); + + settings.setSurveyType("CES"); + + assertThat(settings.getFinalThankYou(7)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + assertThat(settings.getFinalThankYou(5)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + assertThat(settings.getFinalThankYou(1)).isEqualTo(detractorFinalThankYou); + } + + @Test + public void whenFinalThankYouIsNotSet_returnsAdminPanelFinalThankYou() { + mockLocalizedTexts(); + String finalThankYou = "Admin panel final thank you"; + doReturn(finalThankYou).when(mockCustomThankYou).getFinalThankYouForScore(10, "NPS", 0); + doReturn(finalThankYou).when(mockCustomThankYou).getFinalThankYouForScore(3, "CSAT", 0); + doReturn(finalThankYou).when(mockCustomThankYou).getFinalThankYouForScore(1, "CES", 0); + + Settings settings = new Settings(); + settings.setLocalCustomThankYou(null); + settings.setAdminPanelCustomThankYou(mockCustomThankYou); + settings.setLocalizedTexts(mockLocalizedTexts); + settings.setSurveyType("NPS"); + + assertThat(settings.getFinalThankYou(10)).isEqualTo(finalThankYou); + assertThat(settings.getFinalThankYou(8)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + assertThat(settings.getFinalThankYou(0)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getFinalThankYou(5)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + assertThat(settings.getFinalThankYou(3)).isEqualTo(finalThankYou); + assertThat(settings.getFinalThankYou(1)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + + settings.setSurveyType("CES"); + + assertThat(settings.getFinalThankYou(7)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + assertThat(settings.getFinalThankYou(5)).isEqualTo(LOCALIZED_FINAL_THANK_YOU); + assertThat(settings.getFinalThankYou(1)).isEqualTo(finalThankYou); + } + + @Test + public void whenFinalThankYouIsSetAndAdminPanelIsSet_returnsLocalFinalThankYou() { + mockLocalizedTexts(); + String finalThankYou = "Local final thank you"; + doReturn("admin panel").when(mockCustomThankYou).getFinalThankYouForScore(10, "NPS", 0); + doReturn("admin panel").when(mockCustomThankYou).getFinalThankYouForScore(3, "CSAT", 0); + doReturn("admin panel").when(mockCustomThankYou).getFinalThankYouForScore(1, "CES", 0); + + Settings settings = new Settings(); + WootricCustomThankYou customThankYou = new WootricCustomThankYou(); + customThankYou.setFinalThankYou(finalThankYou); + settings.setCustomThankYou(customThankYou); + settings.setAdminPanelCustomThankYou(mockCustomThankYou); + settings.setLocalizedTexts(mockLocalizedTexts); + settings.setSurveyType("NPS"); + + assertThat(settings.getFinalThankYou(10)).isEqualTo(finalThankYou); + assertThat(settings.getFinalThankYou(8)).isEqualTo(finalThankYou); + assertThat(settings.getFinalThankYou(0)).isEqualTo(finalThankYou); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getFinalThankYou(5)).isEqualTo(finalThankYou); + assertThat(settings.getFinalThankYou(3)).isEqualTo(finalThankYou); + assertThat(settings.getFinalThankYou(1)).isEqualTo(finalThankYou); + + settings.setSurveyType("CES"); + + assertThat(settings.getFinalThankYou(7)).isEqualTo(finalThankYou); + assertThat(settings.getFinalThankYou(5)).isEqualTo(finalThankYou); + assertThat(settings.getFinalThankYou(1)).isEqualTo(finalThankYou); + } + + @Test + public void whenCustomThankYouTextIsNotSetPromoter_returnsLocalizedText() { + mockLocalizedTexts(); + doReturn(true).when(mockCustomThankYou).getUniqueByScore(); + + Settings settings = new Settings(); + settings.setLocalCustomThankYou(null); + settings.setAdminPanelCustomThankYou(mockCustomThankYou); + settings.setLocalizedTexts(mockLocalizedTexts); + settings.setSurveyType("NPS"); + + assertThat(settings.getCustomThankYouMessage(10)).isEqualTo(LOCALIZED_THANK_YOU_SETUP); + assertThat(settings.getCustomThankYouMessage(8)).isNull(); + assertThat(settings.getCustomThankYouMessage(0)).isNull(); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getCustomThankYouMessage(5)).isEqualTo(LOCALIZED_THANK_YOU_SETUP); + assertThat(settings.getCustomThankYouMessage(3)).isNull(); + assertThat(settings.getCustomThankYouMessage(1)).isNull(); + + settings.setSurveyType("CES"); + + assertThat(settings.getCustomThankYouMessage(7)).isEqualTo(LOCALIZED_THANK_YOU_SETUP); + assertThat(settings.getCustomThankYouMessage(5)).isNull(); + assertThat(settings.getCustomThankYouMessage(1)).isNull(); + } + + @Test + public void whenCustomThankYouTextIsSet_returnsCustomThankYouText() { + Settings settings = new Settings(); + String customText = "Local custom text"; + WootricCustomThankYou customThankYou = new WootricCustomThankYou(); + customThankYou.setText(customText); + settings.setCustomThankYou(customThankYou); + settings.setSurveyType("NPS"); + + assertThat(settings.getCustomThankYouMessage(10)).isEqualTo(customText); + assertThat(settings.getCustomThankYouMessage(8)).isEqualTo(customText); + assertThat(settings.getCustomThankYouMessage(0)).isEqualTo(customText); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getCustomThankYouMessage(5)).isEqualTo(customText); + assertThat(settings.getCustomThankYouMessage(3)).isEqualTo(customText); + assertThat(settings.getCustomThankYouMessage(1)).isEqualTo(customText); + + settings.setSurveyType("CES"); + + assertThat(settings.getCustomThankYouMessage(7)).isEqualTo(customText); + assertThat(settings.getCustomThankYouMessage(5)).isEqualTo(customText); + assertThat(settings.getCustomThankYouMessage(1)).isEqualTo(customText); + } + + @Test + public void whenCustomPromoterThankYouTextIsSet_returnsCustomPromoterThankYouText() { + Settings settings = new Settings(); + String promoterText = "Local promoter custom text"; + WootricCustomThankYou customThankYou = new WootricCustomThankYou(); + customThankYou.setPromoterText(promoterText); + settings.setCustomThankYou(customThankYou); + settings.setSurveyType("NPS"); + + assertThat(settings.getCustomThankYouMessage(10)).isEqualTo(promoterText); + assertThat(settings.getCustomThankYouMessage(8)).isNull(); + assertThat(settings.getCustomThankYouMessage(0)).isNull(); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getCustomThankYouMessage(5)).isEqualTo(promoterText); + assertThat(settings.getCustomThankYouMessage(3)).isNull(); + assertThat(settings.getCustomThankYouMessage(1)).isNull(); + + settings.setSurveyType("CES"); + + assertThat(settings.getCustomThankYouMessage(7)).isEqualTo(promoterText); + assertThat(settings.getCustomThankYouMessage(5)).isNull(); + assertThat(settings.getCustomThankYouMessage(1)).isNull(); + } + + @Test + public void whenCustomPassiveThankYouTextIsSet_returnsCustomPassiveThankYouText() { + Settings settings = new Settings(); + String passiveText = "Local passive custom text"; + WootricCustomThankYou customThankYou = new WootricCustomThankYou(); + customThankYou.setPassiveText(passiveText); + settings.setCustomThankYou(customThankYou); + settings.setSurveyType("NPS"); + + assertThat(settings.getCustomThankYouMessage(10)).isNull(); + assertThat(settings.getCustomThankYouMessage(8)).isEqualTo(passiveText); + assertThat(settings.getCustomThankYouMessage(0)).isNull(); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getCustomThankYouMessage(5)).isNull(); + assertThat(settings.getCustomThankYouMessage(3)).isEqualTo(passiveText); + assertThat(settings.getCustomThankYouMessage(1)).isNull(); + + settings.setSurveyType("CES"); + + assertThat(settings.getCustomThankYouMessage(7)).isNull(); + assertThat(settings.getCustomThankYouMessage(5)).isEqualTo(passiveText); + assertThat(settings.getCustomThankYouMessage(1)).isNull(); + } + + @Test + public void whenCustomDetractorThankYouTextIsSet_returnsCustomDetractorThankYouText() { + Settings settings = new Settings(); + String detractorText = "Local detractor custom text"; + WootricCustomThankYou customThankYou = new WootricCustomThankYou(); + customThankYou.setDetractorText(detractorText); + settings.setCustomThankYou(customThankYou); + settings.setSurveyType("NPS"); + + assertThat(settings.getCustomThankYouMessage(10)).isNull(); + assertThat(settings.getCustomThankYouMessage(8)).isNull(); + assertThat(settings.getCustomThankYouMessage(0)).isEqualTo(detractorText); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getCustomThankYouMessage(5)).isNull(); + assertThat(settings.getCustomThankYouMessage(3)).isNull(); + assertThat(settings.getCustomThankYouMessage(1)).isEqualTo(detractorText); + + settings.setSurveyType("CES"); + + assertThat(settings.getCustomThankYouMessage(7)).isNull(); + assertThat(settings.getCustomThankYouMessage(5)).isNull(); + assertThat(settings.getCustomThankYouMessage(1)).isEqualTo(detractorText); + } + + @Test + public void whenCustomThankYouTextIsNotSet_returnsAdminPanel() { + mockLocalizedTexts(); + String adminPanelText = "Admin panel text"; + doReturn(adminPanelText).when(mockCustomThankYou).getTextForScore(10, "NPS", 0); + doReturn(adminPanelText).when(mockCustomThankYou).getTextForScore(3, "CSAT", 0); + doReturn(adminPanelText).when(mockCustomThankYou).getTextForScore(1, "CES", 0); + + Settings settings = new Settings(); + settings.setAdminPanelCustomThankYou(mockCustomThankYou); + settings.setLocalizedTexts(mockLocalizedTexts); + settings.setSurveyType("NPS"); + + assertThat(settings.getCustomThankYouMessage(10)).isEqualTo(adminPanelText); + assertThat(settings.getCustomThankYouMessage(8)).isNull(); + assertThat(settings.getCustomThankYouMessage(0)).isNull(); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getCustomThankYouMessage(5)).isNull(); + assertThat(settings.getCustomThankYouMessage(3)).isEqualTo(adminPanelText); + assertThat(settings.getCustomThankYouMessage(1)).isNull(); + + settings.setSurveyType("CES"); + + assertThat(settings.getCustomThankYouMessage(7)).isNull(); + assertThat(settings.getCustomThankYouMessage(5)).isNull(); + assertThat(settings.getCustomThankYouMessage(1)).isEqualTo(adminPanelText); assertThat(settings.getCustomThankYouMessage(10)).isEqualTo(null); } @Test - public void whenCustomThankYouLinkIsNotSet_returnsNull() { + public void whenCustomThankYouTextIsSetAndAdminPanelIsSet_returnsLocalCustomThankYouText() { + mockLocalizedTexts(); + String finalText = "Local final text"; + doReturn("admin panel text").when(mockCustomThankYou).getTextForScore(10, "NPS", 0); + doReturn("admin panel text").when(mockCustomThankYou).getTextForScore(3, "CSAT", 0); + doReturn("admin panel text").when(mockCustomThankYou).getTextForScore(1, "CES", 0); + + Settings settings = new Settings(); + WootricCustomThankYou customThankYou = new WootricCustomThankYou(); + customThankYou.setText(finalText); + settings.setCustomThankYou(customThankYou); + settings.setAdminPanelCustomThankYou(mockCustomThankYou); + settings.setLocalizedTexts(mockLocalizedTexts); + settings.setSurveyType("NPS"); + + assertThat(settings.getCustomThankYouMessage(10)).isEqualTo(finalText); + assertThat(settings.getCustomThankYouMessage(8)).isEqualTo(finalText); + assertThat(settings.getCustomThankYouMessage(0)).isEqualTo(finalText); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getCustomThankYouMessage(5)).isEqualTo(finalText); + assertThat(settings.getCustomThankYouMessage(3)).isEqualTo(finalText); + assertThat(settings.getCustomThankYouMessage(1)).isEqualTo(finalText); + + settings.setSurveyType("CES"); + + assertThat(settings.getCustomThankYouMessage(7)).isEqualTo(finalText); + assertThat(settings.getCustomThankYouMessage(5)).isEqualTo(finalText); + assertThat(settings.getCustomThankYouMessage(1)).isEqualTo(finalText); + } + + @Test + public void whenCustomThankYouLinkTextIsNotSet_returnsNull() { Settings settings = new Settings(); assertThat(settings.getThankYouLinkText(10)).isNull(); } @Test - public void whenCustomThankYouLinkIsSet_returnsIt() { + public void whenCustomThankYouLinkTextIsSet_returnsLocalThankYouLinkText() { + String linkText = "Local link text"; Settings settings = new Settings(); WootricCustomThankYou customThankYou = new WootricCustomThankYou(); - customThankYou.setLinkText("Link text"); + customThankYou.setLinkText(linkText); settings.setCustomThankYou(customThankYou); settings.setSurveyType("NPS"); - assertThat(settings.getThankYouLinkText(10)).isEqualTo("Link text"); + assertThat(settings.getThankYouLinkText(10)).isEqualTo(linkText); + assertThat(settings.getThankYouLinkText(8)).isEqualTo(linkText); + assertThat(settings.getThankYouLinkText(0)).isEqualTo(linkText); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getThankYouLinkText(5)).isEqualTo(linkText); + assertThat(settings.getThankYouLinkText(3)).isEqualTo(linkText); + assertThat(settings.getThankYouLinkText(1)).isEqualTo(linkText); + + settings.setSurveyType("CES"); + + assertThat(settings.getThankYouLinkText(7)).isEqualTo(linkText); + assertThat(settings.getThankYouLinkText(5)).isEqualTo(linkText); + assertThat(settings.getThankYouLinkText(1)).isEqualTo(linkText); + } + + @Test + public void whenCustomThankYouLinkTextIsNotSetAndAdminPanelIsSet_returnsAdminPanelCustomThankYouLinkText() { + String adminPanelLinkText = "Admin panel link text"; + doReturn(adminPanelLinkText).when(mockCustomThankYou).getLinkTextForScore(10, "NPS", 0); + doReturn(adminPanelLinkText).when(mockCustomThankYou).getLinkTextForScore(3, "CSAT", 0); + doReturn(adminPanelLinkText).when(mockCustomThankYou).getLinkTextForScore(1, "CES", 0); + + Settings settings = new Settings(); + settings.setAdminPanelCustomThankYou(mockCustomThankYou); + settings.setSurveyType("NPS"); + + assertThat(settings.getThankYouLinkText(10)).isEqualTo(adminPanelLinkText); + assertThat(settings.getThankYouLinkText(8)).isNull(); + assertThat(settings.getThankYouLinkText(0)).isNull(); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getThankYouLinkText(5)).isNull(); + assertThat(settings.getThankYouLinkText(3)).isEqualTo(adminPanelLinkText); + assertThat(settings.getThankYouLinkText(1)).isNull(); + + settings.setSurveyType("CES"); + + assertThat(settings.getThankYouLinkText(7)).isNull(); + assertThat(settings.getThankYouLinkText(5)).isNull(); + assertThat(settings.getThankYouLinkText(1)).isEqualTo(adminPanelLinkText); + } + + @Test + public void whenCustomThankYouLinkTextIsSetAndAdminPanelIsSet_returnsLocalCustomThankYouLinkText() { + String adminPanelLinkText = "Admin panel link text"; + doReturn(adminPanelLinkText).when(mockCustomThankYou).getLinkTextForScore(10, "NPS", 0); + doReturn(adminPanelLinkText).when(mockCustomThankYou).getLinkTextForScore(3, "CSAT", 0); + doReturn(adminPanelLinkText).when(mockCustomThankYou).getLinkTextForScore(1, "CES", 0); + + String linkText = "Local link text"; + Settings settings = new Settings(); + WootricCustomThankYou customThankYou = new WootricCustomThankYou(); + customThankYou.setLinkText(linkText); + settings.setCustomThankYou(customThankYou); + settings.setAdminPanelCustomThankYou(mockCustomThankYou); + settings.setSurveyType("NPS"); + + assertThat(settings.getThankYouLinkText(10)).isEqualTo(linkText); + assertThat(settings.getThankYouLinkText(8)).isEqualTo(linkText); + assertThat(settings.getThankYouLinkText(0)).isEqualTo(linkText); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getThankYouLinkText(5)).isEqualTo(linkText); + assertThat(settings.getThankYouLinkText(3)).isEqualTo(linkText); + assertThat(settings.getThankYouLinkText(1)).isEqualTo(linkText); + + settings.setSurveyType("CES"); + + assertThat(settings.getThankYouLinkText(7)).isEqualTo(linkText); + assertThat(settings.getThankYouLinkText(5)).isEqualTo(linkText); + assertThat(settings.getThankYouLinkText(1)).isEqualTo(linkText); } @Test public void whenCustomThankYouLinkUriIsNotSet_returnsNull() { Settings settings = new Settings(); - assertThat(settings.getThankYouLinkUri(10, "feedback")).isNull(); + assertThat(settings.getThankYouLinkUri("",10, "")).isNull(); + } + + @Test + public void whenCustomThankYouLinkUriIsSet_returnsLocalThankYouLinkUri() { + Uri linkUri = Uri.parse("http://wootric.com/"); + Settings settings = new Settings(); + WootricCustomThankYou customThankYou = new WootricCustomThankYou(); + customThankYou.setLinkUri(linkUri); + settings.setCustomThankYou(customThankYou); + settings.setSurveyType("NPS"); + + assertThat(settings.getThankYouLinkUri(EMAIL,10, "")).isEqualTo(linkUri); + assertThat(settings.getThankYouLinkUri(EMAIL,8, "")).isEqualTo(linkUri); + assertThat(settings.getThankYouLinkUri(EMAIL,0, "")).isEqualTo(linkUri); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getThankYouLinkUri(EMAIL,5, "")).isEqualTo(linkUri); + assertThat(settings.getThankYouLinkUri(EMAIL,3, "")).isEqualTo(linkUri); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "")).isEqualTo(linkUri); + + settings.setSurveyType("CES"); + + assertThat(settings.getThankYouLinkUri(EMAIL,7, "")).isEqualTo(linkUri); + assertThat(settings.getThankYouLinkUri(EMAIL,5, "")).isEqualTo(linkUri); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "")).isEqualTo(linkUri); + } + + @Test + public void whenCustomThankYouLinkUriIsNotSetAndAdminPanelIsSet_returnsAdminPanelCustomThankYouLinkUri() { + Uri adminPanelLinkUri = Uri.parse("http://wootric.com/admin"); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(10,"NPS", 0); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(3, "CSAT", 0); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(1, "CES", 0); + + Settings settings = new Settings(); + settings.setAdminPanelCustomThankYou(mockCustomThankYou); + settings.setSurveyType("NPS"); + + assertThat(settings.getThankYouLinkUri(EMAIL,10, "")).isEqualTo(adminPanelLinkUri); + assertThat(settings.getThankYouLinkUri(EMAIL,8, "")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,0, "")).isNull(); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getThankYouLinkUri(EMAIL,5, "")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,3, "")).isEqualTo(adminPanelLinkUri); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "")).isNull(); + + settings.setSurveyType("CES"); + + assertThat(settings.getThankYouLinkUri(EMAIL,7, "")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,5, "")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "")).isEqualTo(adminPanelLinkUri); + } + + @Test + public void whenCustomThankYouLinkUriIsSetAndAdminPanelIsSet_returnsLocalCustomThankYouLinkUri() { + Uri adminPanelLinkUri = Uri.parse("http://wootric.com/admin"); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(10, "NPS", 0); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(3, "CSAT", 0); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(1, "CES", 0); + + Uri linkUri = Uri.parse("http://wootric.com/"); + Settings settings = new Settings(); + WootricCustomThankYou customThankYou = new WootricCustomThankYou(); + customThankYou.setLinkUri(linkUri); + settings.setCustomThankYou(customThankYou); + settings.setAdminPanelCustomThankYou(mockCustomThankYou); + settings.setSurveyType("NPS"); + + assertThat(settings.getThankYouLinkUri(EMAIL,10, "")).isEqualTo(linkUri); + assertThat(settings.getThankYouLinkUri(EMAIL,8, "")).isEqualTo(linkUri); + assertThat(settings.getThankYouLinkUri(EMAIL,0, "")).isEqualTo(linkUri); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getThankYouLinkUri(EMAIL,5, "")).isEqualTo(linkUri); + assertThat(settings.getThankYouLinkUri(EMAIL,3, "")).isEqualTo(linkUri); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "")).isEqualTo(linkUri); + + settings.setSurveyType("CES"); + + assertThat(settings.getThankYouLinkUri(EMAIL,7, "")).isEqualTo(linkUri); + assertThat(settings.getThankYouLinkUri(EMAIL,5, "")).isEqualTo(linkUri); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "")).isEqualTo(linkUri); } + @Test + public void whenAddEmailParamToUriIsTrue_returnsUriWithEmailParam() { + Uri adminPanelLinkUri = Uri.parse("http://wootric.com/admin"); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(10,"NPS", 0); + doReturn(true).when(mockCustomThankYou).getEmailInUri(10, "NPS", 0); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(3,"CSAT", 0); + doReturn(true).when(mockCustomThankYou).getEmailInUri(3, "CSAT", 0); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(1,"CES", 0); + doReturn(true).when(mockCustomThankYou).getEmailInUri(1, "CES", 0); + + + Uri result = Uri.parse("http://wootric.com/admin?wootric_email=nps%40test.com"); + Settings settings = new Settings(); + settings.setAdminPanelCustomThankYou(mockCustomThankYou); + settings.setSurveyType("NPS"); + + assertThat(settings.getThankYouLinkUri(EMAIL,10, "")).isEqualTo(result); + assertThat(settings.getThankYouLinkUri(EMAIL,8, "")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,0, "")).isNull(); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getThankYouLinkUri(EMAIL,5, "")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,3, "")).isEqualTo(result); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "")).isNull(); + + settings.setSurveyType("CES"); + + assertThat(settings.getThankYouLinkUri(EMAIL,7, "")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,5, "")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "")).isEqualTo(result); + } + + @Test + public void whenAddScoreParamToUriIsTrue_returnsUriWithScoreParam() { + Uri adminPanelLinkUri = Uri.parse("http://wootric.com/admin"); + Uri resultNPS = Uri.parse("http://wootric.com/admin?wootric_score=10"); + Uri resultCSAT = Uri.parse("http://wootric.com/admin?wootric_score=3"); + Uri resultCES = Uri.parse("http://wootric.com/admin?wootric_score=1"); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(10,"NPS", 0); + doReturn(true).when(mockCustomThankYou).getScoreInUri(10, "NPS", 0); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(3,"CSAT", 0); + doReturn(true).when(mockCustomThankYou).getScoreInUri(3, "CSAT", 0); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(1,"CES", 0); + doReturn(true).when(mockCustomThankYou).getScoreInUri(1, "CES", 0); + + + Settings settings = new Settings(); + settings.setAdminPanelCustomThankYou(mockCustomThankYou); + settings.setSurveyType("NPS"); + + assertThat(settings.getThankYouLinkUri(EMAIL,10, "")).isEqualTo(resultNPS); + assertThat(settings.getThankYouLinkUri(EMAIL,8, "")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,0, "")).isNull(); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getThankYouLinkUri(EMAIL,5, "")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,3, "")).isEqualTo(resultCSAT); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "")).isNull(); + + settings.setSurveyType("CES"); + + assertThat(settings.getThankYouLinkUri(EMAIL,7, "")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,5, "")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "")).isEqualTo(resultCES); + } + + @Test + public void whenAddCommentParamToUriIsTrue_returnsUriWithCommentParam() { + Uri adminPanelLinkUri = Uri.parse("http://wootric.com/admin"); + Uri resultNPS = Uri.parse("http://wootric.com/admin?wootric_comment=abc"); + Uri resultCSAT = Uri.parse("http://wootric.com/admin?wootric_comment=bac"); + Uri resultCES = Uri.parse("http://wootric.com/admin?wootric_comment=cab"); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(10,"NPS", 0); + doReturn(true).when(mockCustomThankYou).getCommentInUri(10, "NPS", 0); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(3,"CSAT", 0); + doReturn(true).when(mockCustomThankYou).getCommentInUri(3, "CSAT", 0); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(1,"CES", 0); + doReturn(true).when(mockCustomThankYou).getCommentInUri(1, "CES", 0); + + + Settings settings = new Settings(); + settings.setAdminPanelCustomThankYou(mockCustomThankYou); + settings.setSurveyType("NPS"); + + assertThat(settings.getThankYouLinkUri(EMAIL,10, "abc")).isEqualTo(resultNPS); + assertThat(settings.getThankYouLinkUri(EMAIL,8, "abc")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,0, "abc")).isNull(); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getThankYouLinkUri(EMAIL,5, "bac")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,3, "bac")).isEqualTo(resultCSAT); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "bac")).isNull(); + + settings.setSurveyType("CES"); + + assertThat(settings.getThankYouLinkUri(EMAIL,7, "cab")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,5, "cab")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "cab")).isEqualTo(resultCES); + } + + @Test + public void whenAddEmailScoreParamToUriIsTrue_returnsUriWithEmailScoreParams() { + Uri adminPanelLinkUri = Uri.parse("http://wootric.com/admin"); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(10,"NPS", 0); + doReturn(true).when(mockCustomThankYou).getEmailInUri(10, "NPS", 0); + doReturn(true).when(mockCustomThankYou).getScoreInUri(10, "NPS", 0); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(3,"CSAT", 0); + doReturn(true).when(mockCustomThankYou).getEmailInUri(3, "CSAT", 0); + doReturn(true).when(mockCustomThankYou).getScoreInUri(3, "CSAT", 0); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(1,"CES", 0); + doReturn(true).when(mockCustomThankYou).getEmailInUri(1, "CES", 0); + doReturn(true).when(mockCustomThankYou).getScoreInUri(1, "CES", 0); + + Uri resultNPS = Uri.parse("http://wootric.com/admin?wootric_email=nps%40test.com&wootric_score=10"); + Uri resultCSAT = Uri.parse("http://wootric.com/admin?wootric_email=nps%40test.com&wootric_score=3"); + Uri resultCES = Uri.parse("http://wootric.com/admin?wootric_email=nps%40test.com&wootric_score=1"); + Settings settings = new Settings(); + settings.setAdminPanelCustomThankYou(mockCustomThankYou); + settings.setSurveyType("NPS"); + + assertThat(settings.getThankYouLinkUri(EMAIL,10, "")).isEqualTo(resultNPS); + assertThat(settings.getThankYouLinkUri(EMAIL,8, "")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,0, "")).isNull(); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getThankYouLinkUri(EMAIL,5, "")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,3, "")).isEqualTo(resultCSAT); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "")).isNull(); + + settings.setSurveyType("CES"); + + assertThat(settings.getThankYouLinkUri(EMAIL,7, "")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,5, "")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "")).isEqualTo(resultCES); + } + + @Test + public void whenAddEmailCommentToUriIsTrue_returnsUriWithEmailCommentParams() { + Uri adminPanelLinkUri = Uri.parse("http://wootric.com/admin"); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(10,"NPS", 0); + doReturn(true).when(mockCustomThankYou).getEmailInUri(10, "NPS", 0); + doReturn(true).when(mockCustomThankYou).getCommentInUri(10, "NPS", 0); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(3,"CSAT", 0); + doReturn(true).when(mockCustomThankYou).getEmailInUri(3, "CSAT", 0); + doReturn(true).when(mockCustomThankYou).getCommentInUri(3, "CSAT", 0); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(1,"CES", 0); + doReturn(true).when(mockCustomThankYou).getEmailInUri(1, "CES", 0); + doReturn(true).when(mockCustomThankYou).getCommentInUri(1, "CES", 0); + + Uri resultNPS = Uri.parse("http://wootric.com/admin?wootric_email=nps%40test.com&wootric_comment=abc"); + Uri resultCSAT = Uri.parse("http://wootric.com/admin?wootric_email=nps%40test.com&wootric_comment=abc"); + Uri resultCES = Uri.parse("http://wootric.com/admin?wootric_email=nps%40test.com&wootric_comment=abc"); + Settings settings = new Settings(); + settings.setAdminPanelCustomThankYou(mockCustomThankYou); + settings.setSurveyType("NPS"); + + assertThat(settings.getThankYouLinkUri(EMAIL,10, "abc")).isEqualTo(resultNPS); + assertThat(settings.getThankYouLinkUri(EMAIL,8, "abc")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,0, "abc")).isNull(); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getThankYouLinkUri(EMAIL,5, "abc")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,3, "abc")).isEqualTo(resultCSAT); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "abc")).isNull(); + + settings.setSurveyType("CES"); + + assertThat(settings.getThankYouLinkUri(EMAIL,7, "abc")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,5, "abc")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "abc")).isEqualTo(resultCES); + } + + @Test + public void whenAddScoreCommentToUriIsTrue_returnsUriWithScoreCommentParams() { + Uri adminPanelLinkUri = Uri.parse("http://wootric.com/admin"); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(10,"NPS", 0); + doReturn(true).when(mockCustomThankYou).getScoreInUri(10, "NPS", 0); + doReturn(true).when(mockCustomThankYou).getCommentInUri(10, "NPS", 0); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(3,"CSAT", 0); + doReturn(true).when(mockCustomThankYou).getScoreInUri(3, "CSAT", 0); + doReturn(true).when(mockCustomThankYou).getCommentInUri(3, "CSAT", 0); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(1,"CES", 0); + doReturn(true).when(mockCustomThankYou).getScoreInUri(1, "CES", 0); + doReturn(true).when(mockCustomThankYou).getCommentInUri(1, "CES", 0); + + Uri resultNPS = Uri.parse("http://wootric.com/admin?wootric_score=10&wootric_comment=abc"); + Uri resultCSAT = Uri.parse("http://wootric.com/admin?wootric_score=3&wootric_comment=abc"); + Uri resultCES = Uri.parse("http://wootric.com/admin?wootric_score=1&wootric_comment=abc"); + Settings settings = new Settings(); + settings.setAdminPanelCustomThankYou(mockCustomThankYou); + settings.setSurveyType("NPS"); + + assertThat(settings.getThankYouLinkUri(EMAIL,10, "abc")).isEqualTo(resultNPS); + assertThat(settings.getThankYouLinkUri(EMAIL,8, "abc")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,0, "abc")).isNull(); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getThankYouLinkUri(EMAIL,5, "abc")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,3, "abc")).isEqualTo(resultCSAT); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "abc")).isNull(); + + settings.setSurveyType("CES"); + + assertThat(settings.getThankYouLinkUri(EMAIL,7, "abc")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,5, "abc")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "abc")).isEqualTo(resultCES); + } + + @Test + public void whenAddEmailScoreCommentToUriIsTrue_returnsUriWithEmailScoreCommentParams() { + Uri adminPanelLinkUri = Uri.parse("http://wootric.com/admin"); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(10,"NPS", 0); + doReturn(true).when(mockCustomThankYou).getEmailInUri(10, "NPS", 0); + doReturn(true).when(mockCustomThankYou).getScoreInUri(10, "NPS", 0); + doReturn(true).when(mockCustomThankYou).getCommentInUri(10, "NPS", 0); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(3,"CSAT", 0); + doReturn(true).when(mockCustomThankYou).getEmailInUri(3, "CSAT", 0); + doReturn(true).when(mockCustomThankYou).getScoreInUri(3, "CSAT", 0); + doReturn(true).when(mockCustomThankYou).getCommentInUri(3, "CSAT", 0); + doReturn(adminPanelLinkUri).when(mockCustomThankYou).getLinkUri(1,"CES", 0); + doReturn(true).when(mockCustomThankYou).getEmailInUri(1, "CES", 0); + doReturn(true).when(mockCustomThankYou).getScoreInUri(1, "CES", 0); + doReturn(true).when(mockCustomThankYou).getCommentInUri(1, "CES", 0); + + Uri resultNPS = Uri.parse("http://wootric.com/admin?wootric_email=nps%40test.com&wootric_score=10&wootric_comment=abc"); + Uri resultCSAT = Uri.parse("http://wootric.com/admin?wootric_email=nps%40test.com&wootric_score=3&wootric_comment=abc"); + Uri resultCES = Uri.parse("http://wootric.com/admin?wootric_email=nps%40test.com&wootric_score=1&wootric_comment=abc"); + Settings settings = new Settings(); + settings.setAdminPanelCustomThankYou(mockCustomThankYou); + settings.setSurveyType("NPS"); + + assertThat(settings.getThankYouLinkUri(EMAIL,10, "abc")).isEqualTo(resultNPS); + assertThat(settings.getThankYouLinkUri(EMAIL,8, "abc")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,0, "abc")).isNull(); + + settings.setSurveyType("CSAT"); + + assertThat(settings.getThankYouLinkUri(EMAIL,5, "abc")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,3, "abc")).isEqualTo(resultCSAT); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "abc")).isNull(); + + settings.setSurveyType("CES"); + + assertThat(settings.getThankYouLinkUri(EMAIL,7, "abc")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,5, "abc")).isNull(); + assertThat(settings.getThankYouLinkUri(EMAIL,1, "abc")).isEqualTo(resultCES); + } + + private void mockLocalizedTexts() { doReturn("How likely").when(mockLocalizedTexts).getSurveyQuestion(); doReturn("likely").when(mockLocalizedTexts).getAnchorLikely(); doReturn("not likely").when(mockLocalizedTexts).getAnchorNotLikely(); doReturn("dismiss").when(mockLocalizedTexts).getDismiss(); doReturn("submit").when(mockLocalizedTexts).getSubmit(); - doReturn("Thank you!").when(mockLocalizedTexts).getFinalThankYou(); + doReturn(LOCALIZED_FINAL_THANK_YOU).when(mockLocalizedTexts).getFinalThankYou(); doReturn("followup question").when(mockLocalizedTexts).getFollowupQuestion(); doReturn("followup placeholder").when(mockLocalizedTexts).getFollowupPlaceholder(); - doReturn("social question").when(mockLocalizedTexts).getSocialShareQuestion(); + doReturn(LOCALIZED_THANK_YOU_SETUP).when(mockLocalizedTexts).getSocialShareQuestion(); doReturn("social decline").when(mockLocalizedTexts).getSocialShareDecline(); } } diff --git a/build.gradle b/build.gradle index ff69495..d8a2657 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.2' + classpath 'com.android.tools.build:gradle:3.5.2' classpath 'com.github.dcendents:android-maven-plugin:1.2' // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 07600cf..9e0a754 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Jul 15 16:35:52 ECT 2019 +#Mon Oct 14 17:44:36 ECT 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip