Commit 3dba3b0d authored by Christian Sadilek's avatar Christian Sadilek
Browse files

Closes #3561: Add default (empty) state to BrowserStore

parent 6d4d5aa4
......@@ -5,7 +5,6 @@
package mozilla.components.browser.session
import mozilla.components.browser.state.selector.selectedTab
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.support.test.mock
import org.junit.Assert.assertEquals
......@@ -20,8 +19,7 @@ import org.junit.Test
class SessionManagerMigrationTest {
@Test
fun `Add session`() {
val state = BrowserState()
val store = BrowserStore(state)
val store = BrowserStore()
val sessionManager = SessionManager(engine = mock(), store = store)
......@@ -41,8 +39,7 @@ class SessionManagerMigrationTest {
@Test
fun `Remove session`() {
val state = BrowserState()
val store = BrowserStore(state)
val store = BrowserStore()
val sessionManager = SessionManager(engine = mock(), store = store)
......@@ -62,8 +59,7 @@ class SessionManagerMigrationTest {
@Test
fun `Selecting session`() {
val state = BrowserState()
val store = BrowserStore(state)
val store = BrowserStore()
val sessionManager = SessionManager(engine = mock(), store = store)
......@@ -81,8 +77,7 @@ class SessionManagerMigrationTest {
@Test
fun `Remove session and update selection`() {
val state = BrowserState()
val store = BrowserStore(state)
val store = BrowserStore()
val manager = SessionManager(engine = mock(), store = store)
......@@ -133,8 +128,7 @@ class SessionManagerMigrationTest {
@Test
fun `Remove private session and select nearby session`() {
val state = BrowserState()
val store = BrowserStore(state)
val store = BrowserStore()
val manager = SessionManager(engine = mock(), store = store)
assertNull(manager.selectedSession)
......@@ -171,8 +165,7 @@ class SessionManagerMigrationTest {
@Test
fun `Remove normal session and select nearby session`() {
val state = BrowserState()
val store = BrowserStore(state)
val store = BrowserStore()
val manager = SessionManager(engine = mock(), store = store)
assertNull(manager.selectedSession)
......
......@@ -16,7 +16,7 @@ import mozilla.components.lib.state.Store
* The only way to change the [BrowserState] inside [BrowserStore] is to dispatch an [Action] on it.
*/
class BrowserStore(
initialState: BrowserState
initialState: BrowserState = BrowserState()
) : Store<BrowserState, BrowserAction>(
initialState,
BrowserStateReducer::reduce
......
......@@ -14,8 +14,7 @@ import org.junit.Test
class CustomTabListActionTest {
@Test
fun `AddCustomTabAction - Adds provided tab`() {
val state = BrowserState()
val store = BrowserStore(state)
val store = BrowserStore()
assertEquals(0, store.state.tabs.size)
assertEquals(0, store.state.customTabs.size)
......
......@@ -14,10 +14,10 @@ import org.junit.Assert.assertNull
import org.junit.Test
class TabListActionTest {
@Test
fun `AddTabAction - Adds provided SessionState`() {
val state = BrowserState()
val store = BrowserStore(state)
val store = BrowserStore()
assertEquals(0, store.state.tabs.size)
assertNull(store.state.selectedTabId)
......@@ -57,8 +57,7 @@ class TabListActionTest {
fun `AddTabAction - Select first tab automatically`() {
val existingTab = createTab("https://www.mozilla.org")
val state = BrowserState()
val store = BrowserStore(state)
val store = BrowserStore()
assertEquals(0, store.state.tabs.size)
assertNull(existingTab.id, store.state.selectedTabId)
......
......@@ -19,8 +19,7 @@ import org.junit.Test
class SelectorsKtTest {
@Test
fun `selectedTab extension property`() {
val state = BrowserState()
val store = BrowserStore(state)
val store = BrowserStore()
assertNull(store.state.selectedTab)
......
......@@ -6,17 +6,23 @@ package mozilla.components.browser.state.store
import kotlinx.coroutines.runBlocking
import mozilla.components.browser.state.action.TabListAction
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.createTab
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
class BrowserStoreTest {
@Test
fun `Initial state is empty`() {
val store = BrowserStore()
assertEquals(0, store.state.tabs.size)
assertNull(store.state.selectedTabId)
}
@Test
fun `Adding a tab`() = runBlocking {
val state = BrowserState()
val store = BrowserStore(state)
val store = BrowserStore()
assertEquals(0, store.state.tabs.size)
assertNull(store.state.selectedTabId)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment