Search in sources :

Example 1 with DataInteraction

use of androidx.test.espresso.DataInteraction in project kiwix-android by kiwix.

the class NetworkTest method networkTest.

@Test
// TODO: Fix in 3.0
@Ignore("Broken in 2.5")
public void networkTest() {
    mActivityTestRule.launchActivity(null);
    BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
    BaristaMenuClickInteractions.clickMenu(getResourceString(R.string.library));
    TestUtils.allowPermissionsIfNeeded();
    onData(withContent("wikipedia_ab_all_2017-03")).inAdapterView(withId(R.id.libraryList)).perform(click());
    try {
        onView(withId(android.R.id.button1)).perform(click());
    } catch (RuntimeException e) {
    }
    clickOn(R.string.local_zims);
    try {
        onData(allOf(withId(R.id.zim_swiperefresh)));
        refresh(R.id.zim_swiperefresh);
        Thread.sleep(500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    // Find matching zim files on the device
    try {
        DataInteraction dataInteraction = onData(withContent("wikipedia_ab_all_2017-03")).inAdapterView(withId(R.id.zimfilelist));
        // TODO how can we get a count of the items matching the dataInteraction?
        dataInteraction.atPosition(0).perform(click());
        clickMenu(R.string.library);
        DataInteraction dataInteraction1 = onData(withContent("wikipedia_ab_all_2017-03")).inAdapterView(withId(R.id.zimfilelist));
        // to delete the zim file
        dataInteraction1.atPosition(0).perform(longClick());
        clickDialogPositiveButton();
    } catch (Exception e) {
        Log.w(NETWORK_TEST_TAG, "failed to interact with local ZIM file: " + e.getLocalizedMessage());
    }
}
Also used : DataInteraction(androidx.test.espresso.DataInteraction) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with DataInteraction

use of androidx.test.espresso.DataInteraction in project popstellar by dedis.

the class ElectionStartFragmentTest method displayWithUpdatesIsCorrect.

@Test
public void displayWithUpdatesIsCorrect() throws DataHandlingException {
    setupViewModel(PAST_TIME);
    // Election start time has passed, should display that it's ready and start button enabled
    displayAssertions(STATUS_READY, START_START, true);
    DataInteraction grid = nodesGrid();
    nodeAssertions(grid, ownPos, "Waiting\n" + publicKey, false);
    nodeAssertions(grid, node2Pos, "Waiting\n" + node2, false);
    nodeAssertions(grid, node3Pos, "Waiting\n" + node3, false);
    // Nodes 3 try to start
    MessageGeneral elect3Msg = createMsg(node3KeyPair, elect);
    messageHandler.handleMessage(laoRepository, messageSender, consensusChannel, elect3Msg);
    nodeAssertions(grid, node3Pos, "Approve Start by\n" + node3, true);
    // We try to start (it should disable the start button)
    MessageGeneral elect1Msg = createMsg(mainKeyPair, elect);
    messageHandler.handleMessage(laoRepository, messageSender, consensusChannel, elect1Msg);
    displayAssertions(STATUS_READY, START_START, false);
    nodeAssertions(grid, ownPos, "Approve Start by\n" + publicKey, true);
    // We accepted node 3 (it should disable button for node3)
    ConsensusElectAccept electAccept3 = new ConsensusElectAccept(INSTANCE_ID, elect3Msg.getMessageId(), true);
    MessageGeneral accept3Msg = createMsg(mainKeyPair, electAccept3);
    messageHandler.handleMessage(laoRepository, messageSender, consensusChannel, accept3Msg);
    nodeAssertions(grid, node3Pos, "Approve Start by\n" + node3, false);
    // Receive a learn message => node3 was accepted and has started the election
    ConsensusLearn learn3 = new ConsensusLearn(INSTANCE_ID, elect3Msg.getMessageId(), PAST_TIME, true, Collections.emptyList());
    MessageGeneral learn3Msg = createMsg(node3KeyPair, learn3);
    messageHandler.handleMessage(laoRepository, messageSender, consensusChannel, learn3Msg);
    displayAssertions(STATUS_STARTED, START_STARTED, false);
    nodeAssertions(grid, node3Pos, "Started by\n" + node3, false);
}
Also used : ConsensusElectAccept(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) ConsensusLearn(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusLearn) DataInteraction(androidx.test.espresso.DataInteraction) HiltAndroidTest(dagger.hilt.android.testing.HiltAndroidTest) Test(org.junit.Test)

Aggregations

DataInteraction (androidx.test.espresso.DataInteraction)2 Test (org.junit.Test)2 MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)1 ConsensusElectAccept (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept)1 ConsensusLearn (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusLearn)1 HiltAndroidTest (dagger.hilt.android.testing.HiltAndroidTest)1 Ignore (org.junit.Ignore)1