beautusg 7 роки тому
батько
коміт
75256a3abc

+ 53 - 4
app/src/androidTest/java/com/sduduzog/slimlauncher/DBTest.kt

@@ -8,6 +8,8 @@ import androidx.test.platform.app.InstrumentationRegistry
 import com.sduduzog.slimlauncher.data.BaseDao
 import com.sduduzog.slimlauncher.data.BaseDatabase
 import com.sduduzog.slimlauncher.data.model.HomeApp
+import com.sduduzog.slimlauncher.data.model.Note
+import com.sduduzog.slimlauncher.data.model.Task
 import org.hamcrest.CoreMatchers.equalTo
 import org.junit.After
 import org.junit.Assert.assertThat
@@ -15,13 +17,14 @@ import org.junit.Before
 import org.junit.Rule
 import org.junit.Test
 import org.junit.runner.RunWith
+import java.util.*
 import java.util.concurrent.CountDownLatch
 import java.util.concurrent.TimeUnit
 
 @RunWith(AndroidJUnit4ClassRunner::class)
 class DBTest {
 
-    private var mAppDao: BaseDao? = null
+    private var baseDao: BaseDao? = null
     private var mDb: BaseDatabase? = null
 
     @get:Rule
@@ -31,7 +34,7 @@ class DBTest {
     fun createDb() {
         val context = InstrumentationRegistry.getInstrumentation().targetContext
         mDb = Room.inMemoryDatabaseBuilder(context, BaseDatabase::class.java).build()
-        mAppDao = mDb!!.baseDao()
+        baseDao = mDb!!.baseDao()
     }
 
     @After
@@ -43,13 +46,13 @@ class DBTest {
     @Throws(InterruptedException::class)
     fun testInsertLiveDataApps() {
         val app = HomeApp("TestApp", "com.test.test.app", "TestMainActivity", 0)
-        mAppDao!!.add(app)
+        baseDao!!.add(app)
 
         var appsInstalled: List<HomeApp> = listOf()
 
         val latch = CountDownLatch(1)
 
-        val appsLiveData = mAppDao!!.apps
+        val appsLiveData = baseDao!!.apps
 
         val observer = Observer<List<HomeApp>> {
             appsInstalled = it
@@ -61,4 +64,50 @@ class DBTest {
         appsLiveData.removeObserver(observer)
         assertThat(appsInstalled.size, equalTo(1))
     }
+
+    @Test
+    @Throws(InterruptedException::class)
+    fun testInsertLiveDataNotes() {
+        val note = Note("TestNote", Date().time)
+        baseDao!!.add(note)
+
+        var notes: List<Note> = listOf()
+
+        val latch = CountDownLatch(1)
+
+        val notesLiveData = baseDao!!.notes
+
+        val observer = Observer<List<Note>> {
+            notes = it
+            latch.countDown()
+        }
+
+        notesLiveData.observeForever(observer)
+        latch.await(2, TimeUnit.SECONDS)
+        notesLiveData.removeObserver(observer)
+        assertThat(notes.size, equalTo(1))
+    }
+
+    @Test
+    @Throws(InterruptedException::class)
+    fun testInsertLiveDataTasks() {
+        val task = Task("TestTask", false, 0)
+        baseDao!!.add(task)
+
+        var tasks: List<Task> = listOf()
+
+        val latch = CountDownLatch(1)
+
+        val tasksLiveData = baseDao!!.tasks
+
+        val observer = Observer<List<Task>> {
+            tasks = it
+            latch.countDown()
+        }
+
+        tasksLiveData.observeForever(observer)
+        latch.await(2, TimeUnit.SECONDS)
+        tasksLiveData.removeObserver(observer)
+        assertThat(tasks.size, equalTo(1))
+    }
 }

+ 19 - 25
app/src/androidTest/java/com/sduduzog/slimlauncher/SetupFragmentTest.kt → app/src/androidTest/java/com/sduduzog/slimlauncher/TasksFragmentTest.kt

@@ -1,57 +1,51 @@
 package com.sduduzog.slimlauncher
 
 
-import android.content.Context.MODE_PRIVATE
-import android.content.SharedPreferences
+import android.view.KeyEvent
 import androidx.test.espresso.Espresso.onView
-import androidx.test.espresso.action.ViewActions
-import androidx.test.espresso.action.ViewActions.click
+import androidx.test.espresso.action.ViewActions.*
 import androidx.test.espresso.assertion.ViewAssertions.matches
 import androidx.test.espresso.matcher.RootMatchers
 import androidx.test.espresso.matcher.ViewMatchers.*
 import androidx.test.filters.LargeTest
 import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
-import androidx.test.platform.app.InstrumentationRegistry
 import androidx.test.rule.ActivityTestRule
 import org.hamcrest.CoreMatchers.allOf
 import org.hamcrest.Matchers
-import org.junit.Before
 import org.junit.Rule
 import org.junit.Test
 import org.junit.runner.RunWith
 
 @LargeTest
 @RunWith(AndroidJUnit4ClassRunner::class)
-class SetupFragmentTest {
+class TasksFragmentTest {
 
     @Rule
     @JvmField
     var mActivityTestRule = ActivityTestRule(MainActivity::class.java)
 
-    private lateinit var sharedPreferences: SharedPreferences
+//    private lateinit var sharedPreferences: SharedPreferences
 
-    @Before
-    fun clearPreferences() {
-        val context = InstrumentationRegistry.getInstrumentation().targetContext
-        sharedPreferences = context.getSharedPreferences(context.getString(R.string.prefs_settings), MODE_PRIVATE)
-        sharedPreferences.edit().clear().commit()
-    }
+//    @Before
+//    fun clearPreferences() {
+//        val context = InstrumentationRegistry.getInstrumentation().targetContext
+//        sharedPreferences = context.getSharedPreferences(context.getString(R.string.prefs_settings), MODE_PRIVATE)
+//        sharedPreferences.edit().clear().commit()
+//    }
 
 
     @Test
-    fun isAlertDialogShown() {
-        val appCompatButton = onView(
-                allOf(withText(R.string.setup_button_start), isDisplayed()))
-        appCompatButton.perform(click())
+    fun userCanAddTask() {
+        val taskButton = onView(allOf(withText(R.string.home_fragment_tasks), isDisplayed()))
+        taskButton.perform(click())
+        val inputField = onView(allOf(withHint(R.string.tasks_fragment_enter_a_new_task), isDisplayed()))
 
+        inputField.perform(typeText("Testing"))
+        inputField.perform(pressKey(KeyEvent.KEYCODE_ENTER))
 
-        val frameLayout = onView(
-                allOf(withId(android.R.id.content), isDisplayed()))
-        frameLayout.check(matches(isDisplayed()))
+        val checkBox = onView(allOf(withText("Testing"), isDisplayed()))
 
-        val alertDialogTitle = onView(
-                allOf(withText(R.string.choose_apps_title)))
-        alertDialogTitle.check(matches(isDisplayed()))
+        checkBox.check(matches(isNotChecked()))
     }
 
     @Test
@@ -67,7 +61,7 @@ class SetupFragmentTest {
 
         val appCompatButton2 = onView(
                 allOf(withText("DONE")))
-        appCompatButton2.perform(ViewActions.scrollTo(), click())
+        appCompatButton2.perform(scrollTo(), click())
 
         onView(withText(R.string.no_app_selected_toast_msg)).inRoot(
                 RootMatchers.withDecorView(Matchers.not(Matchers.`is`(mActivityTestRule.activity.window.decorView))))

+ 12 - 7
docs/index.html

@@ -1,10 +1,15 @@
 <!DOCTYPE html>
 <html lang="en">
-  <head>
-    <meta charset="UTF-8" />
-    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
-    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
+
+<head>
+    <meta charset="UTF-8"/>
+    <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
+    <meta content="ie=edge" http-equiv="X-UA-Compatible"/>
     <title>Slim Launcher</title>
-  </head>
-  <body></body>
-</html>
+</head>
+
+<body>
+Hello there
+</body>
+
+</html>