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

Greatest espresso Tests ever #70

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Changes from all 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
@@ -0,0 +1,63 @@
package com.example.househomey;

import static androidx.test.espresso.Espresso.onData;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
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.hasListLength;
import static com.example.househomey.testUtils.TestHelpers.waitFor;
import static org.hamcrest.CoreMatchers.anything;

import com.example.househomey.testUtils.TestSetup;
import com.google.common.collect.ImmutableMap;
import com.google.firebase.Timestamp;

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

import java.util.Date;
import java.util.Map;

public class ViewItemFragmentTest extends TestSetup {
private final Map<String, Object> mockData = ImmutableMap.of(
"description", "Test Item",
"acquisitionDate", new Timestamp(new Date()),
"cost", "99.99",
"make", "oldMake",
"model", "oldModel",
"serialNumber", "020202020",
"comment", "original comment"
);

@Test
public void testDetailsVisible() {
waitFor(() -> onView(withId(R.id.total_count_text)).check(matches(withText("15"))));
// Click to view the item page
onData(anything())
.inAdapterView(withId(R.id.item_list))
.atPosition(0)
.onChildView(withId(R.id.action_view))
.perform(click());
onView(withId(R.id.view_item_make)).check(matches(withText("North Face")));
onView(withId(R.id.view_item_model)).check(matches(withText("Recon")));
onView(withId(R.id.view_item_serial_number)).check(matches(withText("7654982345678901")));
onView(withId(R.id.view_item_cost)).check(matches(withText("52.00")));
onView(withId(R.id.view_item_comment)).check(matches(withText("Spacious backpack for travel")));
}

@Test
public void testDeleteItemWithNewUser() throws Exception {
database.addTestItem(mockData);
waitFor(() -> onData(anything())
.inAdapterView(withId(R.id.item_list))
.atPosition(0)
.onChildView(withId(R.id.action_view))
.perform(click()));
onView(withId(R.id.delete_button)).perform(click());

waitFor(() -> onView(withId(R.id.total_count_text)).check(matches(withText("0"))));
}
}