Skip to content

Commit

Permalink
Merge pull request #5476 from grzesiek2010/COLLECT-5400
Browse files Browse the repository at this point in the history
Remove ability to set Google account as server
  • Loading branch information
seadowg authored Mar 22, 2023
2 parents 740a7db + 92a6969 commit ef7e68d
Show file tree
Hide file tree
Showing 40 changed files with 304 additions and 428 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.junit.rules.RuleChain;
import org.junit.runner.RunWith;
import org.odk.collect.android.R;
import org.odk.collect.android.support.CollectHelpers;
import org.odk.collect.android.support.TestDependencies;
import org.odk.collect.android.support.pages.MainMenuPage;
import org.odk.collect.android.support.pages.OkDialog;
Expand All @@ -15,6 +16,7 @@
import org.odk.collect.android.support.rules.CollectTestRule;
import org.odk.collect.android.support.rules.TestRuleChain;
import org.odk.collect.androidtest.RecordedIntentsRule;
import org.odk.collect.projects.Project;

@RunWith(AndroidJUnit4.class)
public class SendFinalizedFormTest {
Expand Down Expand Up @@ -101,12 +103,20 @@ public void whenDeleteAfterSendIsEnabled_deletesFilledForm() {

@Test
public void whenGoogleUsedAsServer_sendsSubmissionToSheet() {
testDependencies.googleAccountPicker.setDeviceAccount("dani@davey.com");
testDependencies.googleApi.setAccount("dani@davey.com");
CollectHelpers.addGDProject(
new Project.New(
"GD Project",
"G",
"#3e9fcc"
),
"dani@davey.com",
testDependencies
);

rule.startAtMainMenu()
.setGoogleAccount("dani@davey.com")
.copyForm("one-question-google.xml")
.openProjectSettingsDialog()
.selectProject("GD Project")
.copyForm("one-question-google.xml", null, false, "GD Project")
.startBlankForm("One Question Google")
.answerQuestion("what is your age", "47")
.swipeToEndScreen()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,6 @@ class AddNewProjectTest {
.assertInactiveProject("Demo project", "demo.getodk.org")
}

@Test
fun addingGdriveProjectManually_addsNewProject() {
val googleAccount = "steph@curry.basket"
testDependencies.googleAccountPicker.setDeviceAccount(googleAccount)

rule.startAtMainMenu()
.openProjectSettingsDialog()
.clickAddProject()
.switchToManualMode()
.openGooglePickerAndSelect(googleAccount)

.openProjectSettingsDialog()
.assertCurrentProject(googleAccount, "$googleAccount / Google Drive")
.assertInactiveProject("Demo project", "demo.getodk.org")
}

@Test
fun addingProjectFromQrCode_addsNewProject() {
val page = rule.startAtMainMenu()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,35 @@ import org.junit.Test
import org.junit.rules.RuleChain
import org.odk.collect.android.R
import org.odk.collect.android.activities.WebViewActivity
import org.odk.collect.android.support.CollectHelpers
import org.odk.collect.android.support.TestDependencies
import org.odk.collect.android.support.pages.MainMenuPage
import org.odk.collect.android.support.rules.CollectTestRule
import org.odk.collect.android.support.rules.TestRuleChain
import org.odk.collect.androidtest.RecordedIntentsRule
import org.odk.collect.projects.Project

class GoogleDriveDeprecationBannerTest {
val rule = CollectTestRule()
class GoogleDriveDeprecationTest {
private val rule = CollectTestRule()
private val testDependencies = TestDependencies()

@get:Rule
val chain: RuleChain = TestRuleChain.chain(testDependencies)
.around(RecordedIntentsRule())
.around(rule)

private val gdProject1 = Project.New(
"GD Project 1",
"G",
"#3e9fcc"
)

private val gdProject2 = Project.New(
"GD Project 2",
"G",
"#3e9fcc"
)

@Test
fun bannerIsNotVisibleInNonGoogleDriveProjects() {
rule
Expand All @@ -33,27 +47,21 @@ class GoogleDriveDeprecationBannerTest {

@Test
fun bannerIsVisibleInGoogleDriveProjects() {
val googleAccount = "steph@curry.basket"
testDependencies.googleAccountPicker.setDeviceAccount(googleAccount)
CollectHelpers.addGDProject(gdProject1, "steph@curry.basket", testDependencies)

rule.startAtMainMenu()
.openProjectSettingsDialog()
.clickAddProject()
.switchToManualMode()
.openGooglePickerAndSelect(googleAccount)
.selectProject(gdProject1.name)
.assertText(R.string.google_drive_deprecation_message)
}

@Test
fun forumThreadIsOpenedAfterClickingLearnMore() {
val googleAccount = "steph@curry.basket"
testDependencies.googleAccountPicker.setDeviceAccount(googleAccount)
CollectHelpers.addGDProject(gdProject1, "steph@curry.basket", testDependencies)

rule.startAtMainMenu()
.openProjectSettingsDialog()
.clickAddProject()
.switchToManualMode()
.openGooglePickerAndSelect(googleAccount)
.selectProject(gdProject1.name)
.clickOnString(R.string.learn_more_button_text)

intended(
Expand All @@ -66,14 +74,11 @@ class GoogleDriveDeprecationBannerTest {

@Test
fun dismissButtonIsVisibleOnlyAfterClickingLearnMore() {
val googleAccount = "steph@curry.basket"
testDependencies.googleAccountPicker.setDeviceAccount(googleAccount)
CollectHelpers.addGDProject(gdProject1, "steph@curry.basket", testDependencies)

rule.startAtMainMenu()
.openProjectSettingsDialog()
.clickAddProject()
.switchToManualMode()
.openGooglePickerAndSelect(googleAccount)
.selectProject(gdProject1.name)
.assertTextDoesNotExist(R.string.dismiss_button_text)
.clickOnString(R.string.learn_more_button_text)
.pressBack(MainMenuPage())
Expand All @@ -82,14 +87,11 @@ class GoogleDriveDeprecationBannerTest {

@Test
fun afterClickingDismissTheBannerDisappears() {
val googleAccount = "steph@curry.basket"
testDependencies.googleAccountPicker.setDeviceAccount(googleAccount)
CollectHelpers.addGDProject(gdProject1, "steph@curry.basket", testDependencies)

rule.startAtMainMenu()
.openProjectSettingsDialog()
.clickAddProject()
.switchToManualMode()
.openGooglePickerAndSelect(googleAccount)
.selectProject(gdProject1.name)
.clickOnString(R.string.learn_more_button_text)
.pressBack(MainMenuPage())
.clickOnString(R.string.dismiss_button_text)
Expand All @@ -100,22 +102,44 @@ class GoogleDriveDeprecationBannerTest {

@Test
fun dismissingTheBannerInOneProjectDoesNotAffectOtherProjects() {
val googleAccount = "steph@curry.basket"
testDependencies.googleAccountPicker.setDeviceAccount(googleAccount)
CollectHelpers.addGDProject(gdProject1, "steph@curry.basket", testDependencies)
CollectHelpers.addGDProject(gdProject2, "john@curry.basket", testDependencies)

rule.startAtMainMenu()
.openProjectSettingsDialog()
.clickAddProject()
.switchToManualMode()
.openGooglePickerAndSelect(googleAccount)
.selectProject(gdProject1.name)
.clickOnString(R.string.learn_more_button_text)
.pressBack(MainMenuPage())
.clickOnString(R.string.dismiss_button_text)
.assertTextDoesNotExist(R.string.google_drive_deprecation_message)
.openProjectSettingsDialog()
.clickAddProject()
.switchToManualMode()
.openGooglePickerAndSelect(googleAccount, true)
.selectProject(gdProject2.name)
.assertText(R.string.google_drive_deprecation_message)
}

@Test
fun additionalWarningShouldNotBeDisplayedWhenRemovingNonGDProject() {
rule
.startAtMainMenu()
.openProjectSettingsDialog()
.clickSettings()
.clickProjectManagement()
.clickOnDeleteProject()
.assertTextDoesNotExist(R.string.delete_google_drive_project_confirm_message)
}

@Test
fun additionalWarningShouldBeDisplayedWhenRemovingGDProject() {
CollectHelpers.addGDProject(gdProject1, "steph@curry.basket", testDependencies)

rule
.startAtMainMenu()
.openProjectSettingsDialog()
.selectProject(gdProject1.name)
.openProjectSettingsDialog()
.clickSettings()
.clickProjectManagement()
.clickOnDeleteProject()
.assertText(R.string.delete_google_drive_project_confirm_message)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,4 @@ class FormManagementSettingsTest {
assertThat(deferredTasks[0].tag, `is`(previouslyDownloadedTag))
assertThat(deferredTasks[0].repeatPeriod, `is`(1000L * 60 * 60))
}

@Test
fun whenGoogleDriveUsingAsServer_disablesPrefsAndOnlyAllowsManualUpdates() {
testDependencies.googleAccountPicker.setDeviceAccount("steph@curry.basket")

MainMenuPage().assertOnPage()
.enablePreviouslyDownloadedOnlyUpdates() // Enabled a different mode before setting up Google
.setGoogleAccount("steph@curry.basket")
.openProjectSettingsDialog()
.clickSettings()
.clickFormManagement()
.assertDisabled(R.string.form_update_mode_title)
.assertDisabled(R.string.form_update_frequency_title)
.assertDisabled(R.string.automatic_download)
.assertText(R.string.manual)

assertThat(testDependencies.scheduler.deferredTasks.size, `is`(0))
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package org.odk.collect.android.feature.settings;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.runner.RunWith;
import org.odk.collect.android.R;
import org.odk.collect.android.gdrive.sheets.DriveHelper;
import org.odk.collect.android.support.TestDependencies;
import org.odk.collect.android.support.pages.MainMenuPage;
import org.odk.collect.android.support.pages.ProjectSettingsPage;
import org.odk.collect.android.support.pages.ServerSettingsPage;
import org.odk.collect.android.support.rules.CollectTestRule;
import org.odk.collect.android.support.rules.TestRuleChain;
import org.odk.collect.androidtest.RecordedIntentsRule;
Expand Down Expand Up @@ -61,32 +56,13 @@ public void whenUsingODKServer_canAddCredentialsForServer() {
.clickOKOnDialog(new MainMenuPage());
}

/**
* This test could definitely be extended to cover form download/submit with the creation
* of a stub
* {@link DriveHelper} and
* {@link org.odk.collect.android.gdrive.GoogleAccountsManager}
*/
@Test
public void selectingGoogleAccount_showsGoogleAccountSettings() {
public void selectingServerTypeIsDisabled() {
new MainMenuPage().assertOnPage()
.openProjectSettingsDialog()
.clickSettings()
.clickServerSettings()
.clickOnServerType()
.clickOnButtonInDialog(R.string.server_platform_google_sheets, new ServerSettingsPage())
.assertText(R.string.selected_google_account_text)
.assertText(R.string.google_sheets_url);
}

@Test
public void selectingGoogleAccount_disablesAutomaticUpdates() {
MainMenuPage mainMenu = new MainMenuPage().assertOnPage()
.enablePreviouslyDownloadedOnlyUpdates();
assertThat(testDependencies.scheduler.getDeferredTasks().size(), is(1));

testDependencies.googleAccountPicker.setDeviceAccount("steph@curry.basket");
mainMenu.setGoogleAccount("steph@curry.basket");
assertThat(testDependencies.scheduler.getDeferredTasks().size(), is(0));
.assertTextDoesNotExist(R.string.cancel);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package org.odk.collect.android.support

import android.app.Application
import androidx.test.core.app.ApplicationProvider
import org.odk.collect.android.application.Collect
import org.odk.collect.android.injection.DaggerUtils
import org.odk.collect.android.injection.config.AppDependencyComponent
import org.odk.collect.android.injection.config.AppDependencyModule
import org.odk.collect.android.injection.config.DaggerAppDependencyComponent
import org.odk.collect.projects.Project
import org.odk.collect.settings.keys.ProjectKeys

object CollectHelpers {
fun overrideAppDependencyModule(appDependencyModule: AppDependencyModule): AppDependencyComponent {
Expand All @@ -16,4 +20,23 @@ object CollectHelpers {
application.component = testComponent
return testComponent
}

@JvmStatic
fun addGDProject(gdProject: Project.New, accountName: String, testDependencies: TestDependencies) {
testDependencies.googleAccountPicker.setDeviceAccount(accountName)
testDependencies.googleApi.setAccount(accountName)

val project = DaggerUtils
.getComponent(ApplicationProvider.getApplicationContext<Application>())
.projectsRepository()
.save(gdProject)

DaggerUtils
.getComponent(ApplicationProvider.getApplicationContext<Application>())
.settingsProvider().getUnprotectedSettings(project.uuid)
.also {
it.save(ProjectKeys.KEY_PROTOCOL, ProjectKeys.PROTOCOL_GOOGLE_SHEETS)
it.save(ProjectKeys.KEY_SELECTED_GOOGLE_ACCOUNT, accountName)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.scrollTo;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.intent.Intents.intending;
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasAction;
import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
import static androidx.test.espresso.matcher.ViewMatchers.isClickable;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
Expand All @@ -14,11 +12,6 @@
import static org.hamcrest.core.AllOf.allOf;
import static org.hamcrest.core.StringContains.containsString;

import android.accounts.AccountManager;
import android.app.Activity;
import android.app.Instrumentation;
import android.content.Intent;

import org.odk.collect.android.R;
import org.odk.collect.android.support.WaitFor;

Expand Down Expand Up @@ -170,22 +163,6 @@ public MainMenuPage enableAutoSend() {
.pressBack(new MainMenuPage());
}

public MainMenuPage setGoogleAccount(String account) {
Intent data = new Intent();
data.putExtra(AccountManager.KEY_ACCOUNT_NAME, account);
Instrumentation.ActivityResult activityResult = new Instrumentation.ActivityResult(Activity.RESULT_OK, data);
intending(hasAction("com.google.android.gms.common.account.CHOOSE_ACCOUNT")).respondWith(activityResult);

return openProjectSettingsDialog()
.clickSettings()
.clickServerSettings()
.clickOnServerType()
.clickOnString(R.string.server_platform_google_sheets)
.clickOnString(R.string.selected_google_account_text)
.pressBack(new ProjectSettingsPage())
.pressBack(new MainMenuPage());
}

public MainMenuPage addAndSwitchToProject(String serverUrl) {
return openProjectSettingsDialog()
.clickAddProject()
Expand Down
Loading

0 comments on commit ef7e68d

Please sign in to comment.