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

fix and add : fix ConfirmFragment and add ConfirmFragmentTest #19

Merged
merged 8 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies {
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test:rules:1.2.0'

implementation 'euphony.lib:euphony:0.7.1.6'
implementation 'com.google.android.material:material:1.2.0-alpha02'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.eutophia.sound_helper;

import static androidx.test.espresso.action.ViewActions.*;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.RootMatchers.isDialog;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.junit.Assert.*;

import android.app.Activity;
import android.view.View;

import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentTransaction;
import androidx.test.espresso.Espresso;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.action.ViewActions;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.ActivityTestRule;

import junit.framework.TestCase;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class ConfirmFragmentTest extends TestCase {
@Rule
public ActivityTestRule activityRule = new ActivityTestRule<>(
InfoActivity.class);

@Test
public void testButtonClick(){
runFragment();

Espresso.onView(ViewMatchers.withId(R.id.confirm_button))
.perform(click());
}
@Test
public void testDialogDisplay() throws InterruptedException {
runFragment();

Espresso.onView(ViewMatchers.withId(R.id.confirm_button))
.perform(click());
Espresso.onView(ViewMatchers.withText(R.string.submit))
.check(matches(isDisplayed()));
}
@Test
public void testDialogPositiveButtonClick(){
runFragment();

Espresso.onView(ViewMatchers.withId(R.id.confirm_button))
.perform(click());
Espresso.onView(ViewMatchers.withText(R.string.submit))
.check(matches(isDisplayed()));
Espresso.onView(ViewMatchers.withText("confirm"))
.perform(click());
}
@Test
public void testDialogNegativeButtonClick(){
runFragment();

Espresso.onView(ViewMatchers.withId(R.id.confirm_button))
.perform(click());
Espresso.onView(ViewMatchers.withText(R.string.submit))
.check(matches(isDisplayed()));
Espresso.onView(ViewMatchers.withText("cancel"))
.perform(click());
}
public void runFragment(){
activityRule.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
ConfirmFragment fragment = startFragment();

}
});
}
private ConfirmFragment startFragment() {
InfoActivity activity = (InfoActivity) activityRule.getActivity();
FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
ConfirmFragment fragment = new ConfirmFragment();
transaction.add(fragment, "Confirm");
transaction.commit();
return fragment;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.eutophia.sound_helper;

import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static org.junit.Assert.*;

import androidx.test.espresso.Espresso;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.ActivityTestRule;

import junit.framework.TestCase;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class InfoActivityTest extends TestCase {
@Rule
public ActivityTestRule activityRule = new ActivityTestRule<>(
InfoActivity.class);

@Test
public void testTextDisplay(){
Espresso.onView(ViewMatchers.withId(R.id.enter_info_textView))
.check(matches(isDisplayed()));
}

@Test
public void testFragmentDisplay(){
Espresso.onView(ViewMatchers.withId(R.id.page_fragment))
.check(matches(isDisplayed()));
}
}
10 changes: 2 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:supportsRtl="true"
android:theme="@style/Theme.Soundhelper">
<activity
android:name=".MainActivity"
android:name=".InfoActivity"
android:exported="true">
</activity>
<activity
Expand All @@ -22,20 +22,14 @@
android:name=".ListenerActivity"
android:exported="true" />
<activity
android:name=".InfoActivity"
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ListenerActivity"
android:exported="true" />
<activity
android:name=".InformActivity"
android:exported="true" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@
public class ConfirmFragment extends Fragment {
private Button confirmBtn;
private String entireInfo = "";
Fragment mainFragment;
private Person person;
Fragment pageFragment;
private Person person = new Person();

@Override
public void onAttach(Context context) {
super.onAttach(context);
mainFragment = (PageFragment)getActivity().getSupportFragmentManager().findFragmentById(R.id.fragment_main);
pageFragment = (PageFragment)getActivity().getSupportFragmentManager().findFragmentById(R.id.page_fragment);
}

@Override
public void onDetach() {
super.onDetach();
mainFragment = null;
pageFragment = null;
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_confirm,container,false);
confirmBtn = (Button)rootView.findViewById(R.id.confirm);
confirmBtn = (Button)rootView.findViewById(R.id.confirm_button);

return rootView;
}
Expand All @@ -58,7 +58,7 @@ public void onClick(View view) {
return;

entireInfo += person.getName() + person.getTel() + person.getBirthOfDate() + person.getDiseaseName();
alert.setTitle("Do you want to submit it?").setMessage("\n" + entireInfo);
alert.setTitle(getString(R.string.submit)).setMessage("\n" + entireInfo);
alert.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/eutophia/sound_helper/DateFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ public class DateFragment extends Fragment {
DatePickerDialog.OnDateSetListener date;
Calendar calendar = Calendar.getInstance();
private Button dateBtn;
Fragment mainFragment;
Fragment pageFragment;
private Person person;

@Override
public void onAttach(Context context) {
super.onAttach(context);
mainFragment = (PageFragment)getActivity().getSupportFragmentManager().findFragmentById(R.id.fragment_main);
pageFragment = (PageFragment)getActivity().getSupportFragmentManager().findFragmentById(R.id.page_fragment);
}

@Override
public void onDetach() {
super.onDetach();
mainFragment = null;
pageFragment = null;
}


public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_date,container,false);
dateBtn = (Button)rootView.findViewById(R.id.editBirth);
birth = (TextView) rootView.findViewById(R.id.dateOfBirth);
dateBtn = (Button)rootView.findViewById(R.id.birth_editText);
birth = (TextView) rootView.findViewById(R.id.dateOfBirth_textView);

return rootView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class DiseaseFragment extends Fragment {
final boolean IN = true;
final boolean OTHER = false;
Fragment mainFragment;
Fragment pageFragment;
private Spinner spinner;
final CharSequence[] disease_list = {
"Diabetes", "Asthma", "Dementia", "Visual impairment", "Hearing impairment", "None", "Other"
Expand All @@ -33,13 +33,13 @@ public class DiseaseFragment extends Fragment {
@Override
public void onAttach(Context context) {
super.onAttach(context);
mainFragment = (PageFragment)getActivity().getSupportFragmentManager().findFragmentById(R.id.fragment_main);
pageFragment = (PageFragment)getActivity().getSupportFragmentManager().findFragmentById(R.id.page_fragment);
}

@Override
public void onDetach() {
super.onDetach();
mainFragment = null;
pageFragment = null;
}

public void showAlert(String title, String message, EditText text,
Expand Down Expand Up @@ -73,7 +73,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_disease,container,false);
list = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, disease_list);
spinner = (Spinner) rootView.findViewById(R.id.sp);
spinner = (Spinner) rootView.findViewById(R.id.select_disease_spinner);
list.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(list);
spinner.setSelection(0, false);
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/eutophia/sound_helper/InfoFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class InfoFragment extends Fragment {
@Override
public void onAttach(Context context) {
super.onAttach(context);
pageFragment = (PageFragment)getActivity().getSupportFragmentManager().findFragmentById(R.id.fragment_main);
pageFragment = (PageFragment)getActivity().getSupportFragmentManager().findFragmentById(R.id.page_fragment);
}

@Override
Expand Down Expand Up @@ -80,10 +80,10 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_info,container,false);
viewModel = new ViewModelProvider(requireActivity()).get(InfoViewModel.class);

name = (EditText)rootView.findViewById(R.id.editName);
tel = (EditText)rootView.findViewById(R.id.editTel);
btn1 = (Button) rootView.findViewById(R.id.confirmName);
btn2 = (Button) rootView.findViewById(R.id.confirmTel);
name = (EditText)rootView.findViewById(R.id.name_editText);
tel = (EditText)rootView.findViewById(R.id.tel_editText);
btn1 = (Button) rootView.findViewById(R.id.confirm_name_button);
btn2 = (Button) rootView.findViewById(R.id.confirm_tel_button);

return rootView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void onDetach() {

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_main,container,false);
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_page,container,false);

return rootView;
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
android:layout_height="match_parent"
tools:context="com.example.codestudio.myapplication.MainActivity">
<TextView
android:id="@+id/enter_info_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="21sp"
Expand All @@ -21,7 +22,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:id="@+id/fragment_main"
android:id="@+id/page_fragment"
android:name="com.eutophia.sound_helper.PageFragment"
/>
</RelativeLayout>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_confirm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
tools:context=".ConfirmFragment">

<Button
android:id="@+id/confirm"
android:id="@+id/confirm_button"
android:layout_marginTop="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/layout/fragment_date.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
android:layout_height="match_parent">

<TextView
android:id="@+id/birth"
android:id="@+id/birth_textView"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date of Birth" />

<Button
android:id="@+id/editBirth"
android:id="@+id/birth_editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/birth"
android:layout_below="@+id/birth_textView"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:ems="10"
android:text="Select Date of Birth" />

<TextView
android:id="@+id/dateOfBirth"
android:id="@+id/dateOfBirth_textView"
android:textSize="18sp"
android:layout_toRightOf="@id/editBirth"
android:layout_below="@id/birth"
android:layout_toRightOf="@id/birth_editText"
android:layout_below="@id/birth_textView"
android:layout_marginTop="25dp"
android:layout_marginStart="15dp"
android:layout_width="wrap_content"
Expand Down
Loading