From b6909adca11d73003c0fdab7dbd8cf225b6f478c Mon Sep 17 00:00:00 2001 From: Jonas Kalderstam Date: Sun, 3 Jul 2016 15:05:25 +0200 Subject: [PATCH] Failing tests for pathnames --- .../filepicker/sample/SelectNewFile.java | 244 ++++++++++++++++++ ...java => SelectNewFileStartPathIsFile.java} | 2 +- 2 files changed, 245 insertions(+), 1 deletion(-) rename sample/src/androidTest/java/com/nononsenseapps/filepicker/sample/{SelectNewFileStartPathisFile.java => SelectNewFileStartPathIsFile.java} (98%) diff --git a/sample/src/androidTest/java/com/nononsenseapps/filepicker/sample/SelectNewFile.java b/sample/src/androidTest/java/com/nononsenseapps/filepicker/sample/SelectNewFile.java index 6528c53..1b7ce55 100644 --- a/sample/src/androidTest/java/com/nononsenseapps/filepicker/sample/SelectNewFile.java +++ b/sample/src/androidTest/java/com/nononsenseapps/filepicker/sample/SelectNewFile.java @@ -159,4 +159,248 @@ public class SelectNewFile { editText.check(matches(withText("file-3.txt"))); } + @Test + public void enterFileNameWithPathWhichExists() throws IOException { + ViewInteraction radioButton = onView( + allOf(withId(R.id.radioNewFile), withText("Select new file"), + withParent(withId(R.id.radioGroup)), + isDisplayed())); + radioButton.perform(click()); + + ViewInteraction checkBox = onView( + allOf(withId(R.id.checkAllowExistingFile), + withText("Allow selection of existing (new) file"), isDisplayed())); + checkBox.perform(click()); + + ViewInteraction button = onView( + allOf(withId(R.id.button_sd), withText("Pick SD-card"), isDisplayed())); + button.perform(click()); + + ViewInteraction recyclerView = onView( + allOf(withId(android.R.id.list), isDisplayed())); + + // Refresh view (into dir, and out again) + recyclerView.perform(actionOnItemAtPosition(1, click())); + recyclerView.perform(actionOnItemAtPosition(0, click())); + + // Click on test dir + recyclerView.perform(actionOnItemAtPosition(1, click())); + + // Enter path in filename + ViewInteraction appCompatEditText = onView( + allOf(withId(R.id.nnf_text_filename), + withParent(allOf(withId(R.id.nnf_newfile_button_container), + withParent(withId(R.id.nnf_buttons_container)))), + isDisplayed())); + // new file name + appCompatEditText.perform(replaceText("B-dir/file-3.txt")); + + // Click ok + ViewInteraction appCompatImageButton = onView( + allOf(withId(R.id.nnf_button_ok_newfile), + withParent(allOf(withId(R.id.nnf_newfile_button_container), + withParent(withId(R.id.nnf_buttons_container)))), + isDisplayed())); + appCompatImageButton.perform(click()); + + // Should have returned + ViewInteraction textView = onView(withId(R.id.text)); + textView.check(matches(withText("file:///storage/emulated/0/000000_nonsense-tests/B-dir/file-3.txt"))); + } + + @Test + public void enterFileNameWithPathWhichDoesNotExist() throws IOException { + ViewInteraction radioButton = onView( + allOf(withId(R.id.radioNewFile), withText("Select new file"), + withParent(withId(R.id.radioGroup)), + isDisplayed())); + radioButton.perform(click()); + + ViewInteraction checkBox = onView( + allOf(withId(R.id.checkAllowExistingFile), + withText("Allow selection of existing (new) file"), isDisplayed())); + checkBox.perform(click()); + + ViewInteraction button = onView( + allOf(withId(R.id.button_sd), withText("Pick SD-card"), isDisplayed())); + button.perform(click()); + + ViewInteraction recyclerView = onView( + allOf(withId(android.R.id.list), isDisplayed())); + + // Refresh view (into dir, and out again) + recyclerView.perform(actionOnItemAtPosition(1, click())); + recyclerView.perform(actionOnItemAtPosition(0, click())); + + // Click on test dir + recyclerView.perform(actionOnItemAtPosition(1, click())); + + // Enter path in filename + ViewInteraction appCompatEditText = onView( + allOf(withId(R.id.nnf_text_filename), + withParent(allOf(withId(R.id.nnf_newfile_button_container), + withParent(withId(R.id.nnf_buttons_container)))), + isDisplayed())); + // new file name + appCompatEditText.perform(replaceText("path/to/file")); + + // Click ok + ViewInteraction appCompatImageButton = onView( + allOf(withId(R.id.nnf_button_ok_newfile), + withParent(allOf(withId(R.id.nnf_newfile_button_container), + withParent(withId(R.id.nnf_buttons_container)))), + isDisplayed())); + appCompatImageButton.perform(click()); + + // Should have returned + ViewInteraction textView = onView(withId(R.id.text)); + textView.check(matches(withText("file:///storage/emulated/0/000000_nonsense-tests/path/to/file"))); + } + + @Test + public void enterFileNameWithDotDot() throws IOException { + ViewInteraction radioButton = onView( + allOf(withId(R.id.radioNewFile), withText("Select new file"), + withParent(withId(R.id.radioGroup)), + isDisplayed())); + radioButton.perform(click()); + + ViewInteraction checkBox = onView( + allOf(withId(R.id.checkAllowExistingFile), + withText("Allow selection of existing (new) file"), isDisplayed())); + checkBox.perform(click()); + + ViewInteraction button = onView( + allOf(withId(R.id.button_sd), withText("Pick SD-card"), isDisplayed())); + button.perform(click()); + + ViewInteraction recyclerView = onView( + allOf(withId(android.R.id.list), isDisplayed())); + + // Refresh view (into dir, and out again) + recyclerView.perform(actionOnItemAtPosition(1, click())); + recyclerView.perform(actionOnItemAtPosition(0, click())); + + // Click on test dir + recyclerView.perform(actionOnItemAtPosition(1, click())); + + // Enter path in filename + ViewInteraction appCompatEditText = onView( + allOf(withId(R.id.nnf_text_filename), + withParent(allOf(withId(R.id.nnf_newfile_button_container), + withParent(withId(R.id.nnf_buttons_container)))), + isDisplayed())); + // new file name + appCompatEditText.perform(replaceText("../file.txt")); + + // Click ok + ViewInteraction appCompatImageButton = onView( + allOf(withId(R.id.nnf_button_ok_newfile), + withParent(allOf(withId(R.id.nnf_newfile_button_container), + withParent(withId(R.id.nnf_buttons_container)))), + isDisplayed())); + appCompatImageButton.perform(click()); + + // Should have returned + ViewInteraction textView = onView(withId(R.id.text)); + textView.check(matches(withText("file:///storage/emulated/0/file.txt"))); + } + + @Test + public void enterFileNameWithDot() throws IOException { + ViewInteraction radioButton = onView( + allOf(withId(R.id.radioNewFile), withText("Select new file"), + withParent(withId(R.id.radioGroup)), + isDisplayed())); + radioButton.perform(click()); + + ViewInteraction checkBox = onView( + allOf(withId(R.id.checkAllowExistingFile), + withText("Allow selection of existing (new) file"), isDisplayed())); + checkBox.perform(click()); + + ViewInteraction button = onView( + allOf(withId(R.id.button_sd), withText("Pick SD-card"), isDisplayed())); + button.perform(click()); + + ViewInteraction recyclerView = onView( + allOf(withId(android.R.id.list), isDisplayed())); + + // Refresh view (into dir, and out again) + recyclerView.perform(actionOnItemAtPosition(1, click())); + recyclerView.perform(actionOnItemAtPosition(0, click())); + + // Click on test dir + recyclerView.perform(actionOnItemAtPosition(1, click())); + + // Enter path in filename + ViewInteraction appCompatEditText = onView( + allOf(withId(R.id.nnf_text_filename), + withParent(allOf(withId(R.id.nnf_newfile_button_container), + withParent(withId(R.id.nnf_buttons_container)))), + isDisplayed())); + // new file name + appCompatEditText.perform(replaceText("./file.txt")); + + // Click ok + ViewInteraction appCompatImageButton = onView( + allOf(withId(R.id.nnf_button_ok_newfile), + withParent(allOf(withId(R.id.nnf_newfile_button_container), + withParent(withId(R.id.nnf_buttons_container)))), + isDisplayed())); + appCompatImageButton.perform(click()); + + // Should have returned + ViewInteraction textView = onView(withId(R.id.text)); + textView.check(matches(withText("file:///storage/emulated/0/000000_nonsense-tests/file.txt"))); + } + + @Test + public void enterFileNameWithRoot() throws IOException { + ViewInteraction radioButton = onView( + allOf(withId(R.id.radioNewFile), withText("Select new file"), + withParent(withId(R.id.radioGroup)), + isDisplayed())); + radioButton.perform(click()); + + ViewInteraction checkBox = onView( + allOf(withId(R.id.checkAllowExistingFile), + withText("Allow selection of existing (new) file"), isDisplayed())); + checkBox.perform(click()); + + ViewInteraction button = onView( + allOf(withId(R.id.button_sd), withText("Pick SD-card"), isDisplayed())); + button.perform(click()); + + ViewInteraction recyclerView = onView( + allOf(withId(android.R.id.list), isDisplayed())); + + // Refresh view (into dir, and out again) + recyclerView.perform(actionOnItemAtPosition(1, click())); + recyclerView.perform(actionOnItemAtPosition(0, click())); + + // Click on test dir + recyclerView.perform(actionOnItemAtPosition(1, click())); + + // Enter path in filename + ViewInteraction appCompatEditText = onView( + allOf(withId(R.id.nnf_text_filename), + withParent(allOf(withId(R.id.nnf_newfile_button_container), + withParent(withId(R.id.nnf_buttons_container)))), + isDisplayed())); + // new file name + appCompatEditText.perform(replaceText("/file.txt")); + + // Click ok + ViewInteraction appCompatImageButton = onView( + allOf(withId(R.id.nnf_button_ok_newfile), + withParent(allOf(withId(R.id.nnf_newfile_button_container), + withParent(withId(R.id.nnf_buttons_container)))), + isDisplayed())); + appCompatImageButton.perform(click()); + + // Should have returned + ViewInteraction textView = onView(withId(R.id.text)); + textView.check(matches(withText("file:///file.txt"))); + } } diff --git a/sample/src/androidTest/java/com/nononsenseapps/filepicker/sample/SelectNewFileStartPathisFile.java b/sample/src/androidTest/java/com/nononsenseapps/filepicker/sample/SelectNewFileStartPathIsFile.java similarity index 98% rename from sample/src/androidTest/java/com/nononsenseapps/filepicker/sample/SelectNewFileStartPathisFile.java rename to sample/src/androidTest/java/com/nononsenseapps/filepicker/sample/SelectNewFileStartPathIsFile.java index ebdec88..e276af0 100644 --- a/sample/src/androidTest/java/com/nononsenseapps/filepicker/sample/SelectNewFileStartPathisFile.java +++ b/sample/src/androidTest/java/com/nononsenseapps/filepicker/sample/SelectNewFileStartPathIsFile.java @@ -34,7 +34,7 @@ import static org.hamcrest.Matchers.allOf; */ @LargeTest @RunWith(AndroidJUnit4.class) -public class SelectNewFileStartPathisFile { +public class SelectNewFileStartPathIsFile { @Rule public ActivityTestRule mActivityTestRule =