Skip to content
Snippets Groups Projects
Verified Commit 60f1776e authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Fixes buffers not being added in the correct position, adds tests

parent 316d3e03
No related branches found
No related tags found
No related merge requests found
Pipeline #502 passed
......@@ -26,6 +26,7 @@ import de.kuschku.libquassel.quassel.syncables.interfaces.IBufferViewConfig
import de.kuschku.libquassel.session.SignalProxy
import de.kuschku.libquassel.util.flag.hasFlag
import de.kuschku.libquassel.util.helper.clampOf
import de.kuschku.libquassel.util.irc.IrcCaseMappers
import io.reactivex.Observable
import io.reactivex.subjects.BehaviorSubject
......@@ -327,12 +328,12 @@ class BufferViewConfig constructor(
fun insertBufferSorted(info: BufferInfo, bufferSyncer: BufferSyncer) {
if (!_buffers.contains(info.bufferId)) {
val position = if (_sortAlphabetically) {
val sortedBuffers = _buffers.mapNotNull { bufferSyncer.bufferInfo(it)?.bufferName }
-sortedBuffers.binarySearch(info.bufferName)
} else {
_buffers.size
}
val element = IrcCaseMappers.unicode.toLowerCaseNullable(info.bufferName)
val position =
if (_sortAlphabetically) -_buffers.mapNotNull {
IrcCaseMappers.unicode.toLowerCaseNullable(bufferSyncer.bufferInfo(it)?.bufferName)
}.binarySearch(element) - 1
else _buffers.size
requestAddBuffer(info.bufferId, position)
}
}
......
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2019 Janne Mareike Koschinski
* Copyright (c) 2019 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.integration
import de.kuschku.libquassel.protocol.BufferId
import de.kuschku.libquassel.protocol.QType
import de.kuschku.libquassel.protocol.QVariant_
import de.kuschku.libquassel.protocol.Type
import de.kuschku.libquassel.util.TestSession
import de.kuschku.libquassel.util.setupTestSession
import de.kuschku.libquassel.util.with
import org.junit.Before
import org.junit.Test
class BufferViewConfigTest {
lateinit var session: TestSession
@Before
fun setUp() {
session = setupTestSession()
}
// Test positioning of added channel
@Test
fun addChannelAutomatically() = session.with {
val bufferViewConfig = bufferViewManager.bufferViewConfig(0)!!
ensure {
bufferViewConfig.insertBufferSorted(bufferSyncer.bufferInfo(BufferId(4))!!, bufferSyncer)
}.does {
callSync(bufferViewConfig, "requestAddBuffer", listOf(
QVariant_.of(BufferId(4), QType.BufferId),
QVariant_.of(2, Type.Int)
))
}
}
}
......@@ -32,6 +32,15 @@ fun TestSession.with(f: TestSession.() -> Unit) = f.invoke(this)
fun withTestSession(f: TestSession.() -> Unit) = f.invoke(setupTestSession())
fun setupTestSession() = TestSession().provideTestData {
bufferViewConfigs = listOf(
buildBufferViewConfig(0) {
setBufferViewName("All Chats")
addBuffer(BufferId(1), 0)
addBuffer(BufferId(2), 1)
addBuffer(BufferId(3), 2)
}
)
identities = listOf(
buildIdentity(IdentityId(1)) {
setIdentityName("Default Identity")
......
......@@ -219,6 +219,13 @@ class TestSession : ProtocolHandler({ throw it }), ISession {
synchronize(network)
}
fun addBufferViewConfig(bufferViewConfig: BufferViewConfig, initialize: Boolean = false) {
if (!initialize)
bufferViewConfig.initialized = true
bufferViewManager.addBufferViewConfig(bufferViewConfig)
synchronize(bufferViewConfig)
}
override fun removeNetwork(networkId: NetworkId) {
val network = networks.remove(networkId)
stopSynchronize(network)
......@@ -244,6 +251,13 @@ class TestSession : ProtocolHandler({ throw it }), ISession {
return identity
}
fun buildBufferViewConfig(bufferViewConfigId: Int,
f: (BufferViewConfig.() -> Unit)? = null): BufferViewConfig {
val bufferViewConfig = BufferViewConfig(bufferViewConfigId, proxy)
f?.invoke(bufferViewConfig)
return bufferViewConfig
}
data class BufferTestData(
val bufferInfo: BufferInfo,
val activity: Message_Types = Message_Type.of(),
......@@ -254,11 +268,17 @@ class TestSession : ProtocolHandler({ throw it }), ISession {
data class TestData(
val session: TestSession,
var bufferViewConfigs: List<BufferViewConfig> = emptyList(),
var networks: List<Network> = emptyList(),
var identities: List<Identity> = emptyList(),
var buffers: List<BufferTestData> = emptyList(),
var aliases: List<IAliasManager.Alias> = emptyList()
) {
fun buildBufferViewConfig(bufferViewConfigId: Int,
f: (BufferViewConfig.() -> Unit)? = null): BufferViewConfig {
return session.buildBufferViewConfig(bufferViewConfigId, f)
}
fun buildNetwork(networkId: NetworkId, f: (Network.() -> Unit)? = null): Network {
return session.buildNetwork(networkId, f)
}
......@@ -287,6 +307,9 @@ class TestSession : ProtocolHandler({ throw it }), ISession {
fun provideTestData(f: TestData.() -> Unit): TestSession {
val data = TestData(this)
f.invoke(data)
for (bufferViewConfig in data.bufferViewConfigs) {
addBufferViewConfig(bufferViewConfig)
}
for (network in data.networks) {
addNetwork(network)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment