package bou.amine.apps.readerforselfossv2.android.tests.robolectric

import android.view.Menu
import android.widget.TextView
import androidx.annotation.IdRes
import org.junit.Assert.assertTrue
import org.robolectric.shadows.ShadowDialog

fun dialogMessage(): String {
    val latestDialog = ShadowDialog.getLatestDialog()
    return latestDialog.findViewById<TextView>(android.R.id.message)?.text.toString()
}

fun Menu.assertClickable(@IdRes id: Int) {
    this.assertVisible(id)
    val item = this.findItem(id)
    assertTrue(item.isEnabled)
}

fun Menu.assertVisible(@IdRes id: Int) {
    val item = this.findItem(id)
    assertTrue(item.isVisible)
}