aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/androidTest/java/com/zeapo/pwdstore/GitActivityTest.java
blob: 83995b516330883ca6aed7eb15d4b722764a2139 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.zeapo.pwdstore;

import android.app.Activity;
import android.app.Instrumentation;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.test.ActivityInstrumentationTestCase2;
import android.test.ActivityTestCase;
import android.test.InstrumentationTestCase;
import android.util.Log;
import android.widget.EditText;
import android.widget.Spinner;

import com.zeapo.pwdstore.git.GitActivity;

public class GitActivityTest extends ActivityInstrumentationTestCase2<GitActivity> {
    private Activity gitActivity;
    private Instrumentation mInstrumentation;
    private SharedPreferences settings;

    private Spinner protocolSpinner;
    private Spinner connectionModeSpinner;
    private EditText uri;
    private EditText server_url;
    private EditText server_port;
    private EditText server_path;
    private EditText server_user;

    public GitActivityTest() {
        super(GitActivity.class);
    }

    protected void setUp() throws Exception {
        super.setUp();
        mInstrumentation = getInstrumentation();

        Intent intent = new Intent();
        intent.putExtra("Operation", GitActivity.EDIT_SERVER);
        setActivityIntent(intent);

        gitActivity = getActivity(); // get a references to the app under test
        assertNotNull(gitActivity);

        settings = PreferenceManager.getDefaultSharedPreferences(gitActivity.getApplicationContext());

        uri = (EditText) gitActivity.findViewById(R.id.clone_uri);
        server_url = ((EditText) gitActivity.findViewById(R.id.server_url));
        server_port = ((EditText) gitActivity.findViewById(R.id.server_port));
        server_path = ((EditText) gitActivity.findViewById(R.id.server_path));
        server_user = ((EditText) gitActivity.findViewById(R.id.server_user));
        protocolSpinner = (Spinner) gitActivity.findViewById(R.id.clone_protocol);
        connectionModeSpinner = (Spinner) gitActivity.findViewById(R.id.connection_mode);

        assertEquals(protocolSpinner.getSelectedItem(), settings.getString("git_remote_protocol", "ssh://"));
        assertEquals(connectionModeSpinner.getSelectedItem(), settings.getString("git_remote_auth", "ssh-key"));
    }

    /**
     * If we change from ssh protocol to https we automatically switch to username/password auth
     * @throws Exception
     */
    public void testSpinnerChange() throws Exception{
        gitActivity.runOnUiThread(new Runnable() {
            public void run() {
                protocolSpinner.requestFocus();
                protocolSpinner.setSelection(1); // 1 < is https://
            }
        });
        mInstrumentation.waitForIdleSync();

        assertEquals(connectionModeSpinner.getSelectedItem(), "username/password"); // 1 < is username/password
    }
}