Skip to content

Commit

Permalink
Added more Screenshots "Tests", #39
Browse files Browse the repository at this point in the history
  • Loading branch information
UriahShaulMandel committed Aug 15, 2019
1 parent e3c32c1 commit 0f676e5
Show file tree
Hide file tree
Showing 18 changed files with 526 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public Bitmap screenShot(View view) {

protected abstract void test();

protected void cleanupAfterTest() {
}

;

@Before
public void setUp() {
BPrefs
Expand All @@ -103,10 +108,9 @@ public void after() {
.edit()
.clear()
.commit();

cleanupAfterTest();
}


protected int theme() {
return BPrefs.Themes.LIGHT;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.bald.uriah.baldphone.screenshots;

import android.content.Intent;
import android.os.Handler;

import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;

import com.bald.uriah.baldphone.R;
import com.bald.uriah.baldphone.activities.contacts.ContactsActivity;
import com.tomash.androidcontacts.contactgetter.main.ContactDataFactory;
import com.tomash.androidcontacts.contactgetter.main.contactsSaver.ContactsSaverBuilder;

import org.junit.runner.RunWith;

import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

@LargeTest
@RunWith(AndroidJUnit4.class)
public class ContactsActivityScreenshot extends BaseScreenshotTakerTest<ContactsActivity> {

public void test() {
mActivityTestRule.launchActivity(new Intent());
getInstrumentation().waitForIdleSync();
new Handler(mActivityTestRule.getActivity().getMainLooper())
.post(() -> {
final ContactsActivity dis = mActivityTestRule.getActivity();
final String[] names = dis.getResources().getStringArray(R.array.names_for_screenshots);
for (final String name : names) {
new ContactsSaverBuilder(dis).saveContact(ContactDataFactory.createEmpty().setCompositeName(name));
}
dis.applyFilter();

});
getInstrumentation().waitForIdleSync();

}

@Override
protected void cleanupAfterTest() {
super.cleanupAfterTest();
TestUtils.deleteAllContactsInEmulator(getInstrumentation().getTargetContext().getApplicationContext());
}

@Override
protected Class<ContactsActivity> activity() {
return ContactsActivity.class;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.bald.uriah.baldphone.screenshots;

import android.content.Intent;
import android.os.Handler;

import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;

import com.bald.uriah.baldphone.activities.DialerActivity;

import org.junit.runner.RunWith;

import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

@LargeTest
@RunWith(AndroidJUnit4.class)
public class DialerActivityScreenshot extends BaseScreenshotTakerTest<DialerActivity> {

public void test() {
mActivityTestRule.launchActivity(new Intent());
getInstrumentation().waitForIdleSync();
new Handler(mActivityTestRule.getActivity().getMainLooper())
.post(() -> mActivityTestRule.getActivity().setNumber("0594508160"));
getInstrumentation().waitForIdleSync();

}

@Override
protected Class<DialerActivity> activity() {
return DialerActivity.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.bald.uriah.baldphone.screenshots;

import android.content.Intent;
import android.graphics.Color;
import android.os.Handler;

import androidx.core.app.ActivityCompat;
import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;

import com.bald.uriah.baldphone.R;
import com.bald.uriah.baldphone.activities.pills.AddPillActivity;
import com.bald.uriah.baldphone.activities.pills.PillsActivity;
import com.bald.uriah.baldphone.databases.reminders.Reminder;
import com.bald.uriah.baldphone.databases.reminders.RemindersDatabase;
import com.bald.uriah.baldphone.utils.D;

import org.junit.runner.RunWith;

import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

@LargeTest
@RunWith(AndroidJUnit4.class)
public class PillsActivityScreenshot extends BaseScreenshotTakerTest<PillsActivity> {

public void test() {
mActivityTestRule.launchActivity(new Intent());
getInstrumentation().waitForIdleSync();
new Handler(mActivityTestRule.getActivity().getMainLooper())
.post(() -> {
final PillsActivity dis = mActivityTestRule.getActivity();

final Reminder medication_1 = new Reminder();
medication_1.setStartingTime(Reminder.TIME_MORNING);
medication_1.setDays(D.Days.ALL ^ D.Days.SUNDAY);
medication_1.setTextualContent(dis.getString(R.string.medication_1));
medication_1.setBinaryContentType(Reminder.BINARY_RGB);
medication_1.setReminderType(Reminder.TYPE_PILL);
final int color_1 = ActivityCompat.getColor(dis, AddPillActivity.COLORS[0]);
medication_1.setBinaryContent(new byte[]{(byte) Color.red(color_1), (byte) Color.green(color_1), (byte) Color.blue(color_1)});

final Reminder medication_2 = new Reminder();
medication_2.setStartingTime(Reminder.TIME_MORNING);
medication_2.setDays(D.Days.SUNDAY);
medication_2.setTextualContent(dis.getString(R.string.medication_2));
medication_2.setBinaryContentType(Reminder.BINARY_RGB);
medication_2.setReminderType(Reminder.TYPE_PILL);
final int color_2 = ActivityCompat.getColor(dis, AddPillActivity.COLORS[4]);
medication_2.setBinaryContent(new byte[]{(byte) Color.red(color_2), (byte) Color.green(color_2), (byte) Color.blue(color_2)});
RemindersDatabase.getInstance(dis).remindersDatabaseDao().insertAll(medication_1, medication_2);

dis.refreshViews();
});
getInstrumentation().waitForIdleSync();

}

@Override
protected void cleanupAfterTest() {
super.cleanupAfterTest();
RemindersDatabase.getInstance(getInstrumentation().getTargetContext().getApplicationContext()).remindersDatabaseDao().deleteAll();
}

@Override
protected Class<PillsActivity> activity() {
return PillsActivity.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.bald.uriah.baldphone.screenshots;

import android.content.Intent;
import android.os.Handler;

import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;

import com.bald.uriah.baldphone.activities.pills.PillsActivity;
import com.bald.uriah.baldphone.databases.reminders.RemindersDatabase;

import org.junit.runner.RunWith;

import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

@LargeTest
@RunWith(AndroidJUnit4.class)
public class PillsEmptyActivityScreenshot extends BaseScreenshotTakerTest<PillsActivity> {

public void test() {
mActivityTestRule.launchActivity(new Intent());
getInstrumentation().waitForIdleSync();
new Handler(mActivityTestRule.getActivity().getMainLooper())
.post(() -> {
final PillsActivity dis = mActivityTestRule.getActivity();
RemindersDatabase.getInstance(dis).remindersDatabaseDao().deleteAll();
dis.refreshViews();
});
getInstrumentation().waitForIdleSync();

}

@Override
protected Class<PillsActivity> activity() {
return PillsActivity.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.bald.uriah.baldphone.screenshots;

import android.content.Intent;
import android.os.Handler;

import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;

import com.bald.uriah.baldphone.activities.RecentActivity;

import org.junit.runner.RunWith;

import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

@LargeTest
@RunWith(AndroidJUnit4.class)
public class RecentCallsActivityScreenshot extends BaseScreenshotTakerTest<RecentActivity> {

public void test() {
mActivityTestRule.launchActivity(new Intent());
getInstrumentation().waitForIdleSync();
new Handler(mActivityTestRule.getActivity().getMainLooper())
.post(() -> {
// final RecentActivity dis = mActivityTestRule.getActivity();
//
// final String[] names = dis.getResources().getStringArray(R.array.names_for_screenshots);
// final ContactData[] contacts = new ContactData[names.length];
// for (int i = 0; i < names.length; i++) {
// contacts[i] = new ContactsGetterBuilder(dis).getById(new ContactsSaverBuilder(dis).saveContact(ContactDataFactory.createEmpty().setCompositeName(names[i])));
// }
//
// List<CallLog.Calls> callsList= new ArrayList<>();
// callsList.add(new Call(contacts[0].get));
//
//
// dis.recyclerView.setAdapter(
// new CallsRecyclerViewAdapter(Arrays.asList(
// new Call()
// ), dis)
// );

});
getInstrumentation().waitForIdleSync();

}

@Override
protected void cleanupAfterTest() {
super.cleanupAfterTest();
TestUtils.deleteAllContactsInEmulator(getInstrumentation().getTargetContext().getApplicationContext());
}

@Override
protected Class<RecentActivity> activity() {
return RecentActivity.class;
}
}
Loading

0 comments on commit 0f676e5

Please sign in to comment.