Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial num scanning espresso test #90

Merged
merged 5 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void testDeleteExistingPhoto() {
onView(withId(R.id.delete_photo_button)).perform(click());

// Check that photo was deleted from the gallery
onView(withId(R.id.add_photo_grid)).check(matches(hasChildCount(1)));
waitFor(() -> onView(withId(R.id.add_photo_grid)).check(matches(hasChildCount(1))));
onView(withId(R.id.add_photo_grid)).check(matches(not((hasDescendant(allOf(withId(R.id.gallery_image_view), isDisplayed()))))));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.example.househomey;

import static androidx.test.espresso.Espresso.onView;
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.intended;
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasAction;
import static androidx.test.espresso.matcher.ViewMatchers.hasChildCount;
import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static com.example.househomey.testUtils.TestHelpers.mockImageUri;
import static com.example.househomey.testUtils.TestHelpers.waitFor;
import static org.hamcrest.CoreMatchers.allOf;

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

import androidx.test.espresso.intent.Intents;
import androidx.test.espresso.intent.matcher.IntentMatchers;

import com.example.househomey.testUtils.TestSetup;

import org.junit.Before;
import org.junit.Test;

public class SerialNumScannerTest extends TestSetup {
@Before
public void navigateToAddItemFragment() {
onView(withId(R.id.action_add)).perform(click());
}

@Test
public void testScanPhoto() {
// Mock a result for the system's gallery
Intents.init();
Intent resultData = new Intent();
resultData.setData(mockImageUri(R.raw.serial_num));
Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData);
Intents.intending(IntentMatchers.hasAction(Intent.ACTION_PICK)).respondWith(result);

onView(withId(R.id.add_item_scan_button)).perform(scrollTo());
onView(withId(R.id.add_item_scan_button)).perform(click());
onView(withId(R.id.serialNum_button)).perform(click());

// Click the gallery option and ensure intent was fired
onView(withId(R.id.gallery_button)).perform(click());
intended(hasAction(Intent.ACTION_PICK));
Intents.release();

waitFor(() -> onView(withText("YES")).perform(click()));

// Check that the serial number
onView(withId(R.id.add_item_serial_number)).check(matches(withText("7730002690")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public void onImagePicked(String imageUri) {
}

/**
* Sets the result of the Serial Number scanning in the serial numbner text view
* Sets the result of the Serial Number scanning in the serial number text view
* @param serialNumber the scanned serial number to set
*/
@Override
Expand Down
Binary file added app/src/main/res/raw/serial_num.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading