Skip to content

Commit 259df96

Browse files
AnkiDroid TranslationsBrayanDSO
authored andcommitted
� This is a combination of 6 commits.
� This is the 1st commit message: added test files for currentdeckid() mark test as flaky Issue 19729 fix(deckpicker): Added contentDescription to sync and add card buttons deprecation(libanki): prefer `defaultsForAdding()` over `current()` Deprecates Notetypes.current() in favor of col.defaultsForAdding() Fixes: 19650 Co-authored-by: David Allison <62114487+david-allison@users.noreply.github.com> chore: log 'Activity with no Application' error It's likely that there's another cause other than the backup manager Diagnostics for issue 19050 style: fix dangling top-level KDocs This breaks KtLint 1.8.0 > A dangling toplevel KDoc is not allowed (cannot be auto-corrected) * modify `libs.versions.toml` to use `ktlint = '1.8.0'` * ./gradlew ktLintFormat * revert all changes * manually fix warnings, searching for 'dangling' * manually check fixes ensuring only top-level comments are processed Issue 19614 - updating ktLint docs(github): Explain workflows Quality Checks can be linked to from other pages as an onboarding guide https://github.com/ankidroid/Anki-Android/tree/main/.github/workflows/README.md#quality-checks docs(deps): improve AndroidX lifecycle-process * link changelogs * rename to 'androidxLifecycleProcess' * make location consistent with other libraries Added in 7f7cd37 Disable "Scroll toolbar" if toolbar is not shown In the note editor's overflow menu, disable the "Scroll toolbar" option if the toolbar (for HTML formatting) is not shown. Add comprehensive tests for Card.currentDeckId() - Test normal deck scenario (oDid=0 returns did) - Test filtered deck scenario (oDid takes priority) - Test precedence when both IDs are positive - Test real-world filtered deck usage - Test normal deck default behavior - Test edge case where both IDs are same Addresses @NeedsTest annotation on currentDeckId() method Update Card.kt Update CardTest.kt chore: fix warnings in ExifUtil and UniqueArrayList * Convert var to val in ExifUtil * Fix KDoc references in UniqueArrayList Issue: 13282 Co-authored-by: David Allison <62114487+david-allison@users.noreply.github.com> Add comprehensive tests for Card.currentDeckId() - Test normal deck scenario (oDid=0 returns did) - Test filtered deck scenario (oDid takes priority) - Test precedence when both IDs are positive - Test real-world filtered deck usage - Test normal deck default behavior - Test edge case where both IDs are same Addresses @NeedsTest annotation on currentDeckId() method Update Card.kt Update CardTest.kt Update Card.kt Update Card.kt Update CardTest.kt Update CardTest.kt Update CardTest.kt Update Card.kt Update CardTest.kt Update CardTest.kt Update CardTest.kt Update tests to verify functionality calling currentDeckId() Update CardTest.kt Update CardTest.kt Update CardTest.kt Update CardTest.kt Update CardTest.kt Revert "added test files for currentdeckid()" This reverts commit 1b3060e. � This is the commit message #2: Update Card.kt � This is the commit message #3: Update CardTest.kt � This is the commit message #4: Update Card.kt � This is the commit message #5: Update CardTest.kt � This is the commit message #6: Revert "Update Card.kt & Cardtest.kt" This reverts commit 5bc3121. Test files in cardtest.kt & card.kt
1 parent 036707c commit 259df96

2 files changed

Lines changed: 123 additions & 3 deletions

File tree

  • libanki/src

libanki/src/main/java/com/ichi2/anki/libanki/Card.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package com.ichi2.anki.libanki
1919

2020
import androidx.annotation.VisibleForTesting
21-
import com.ichi2.anki.common.annotations.NeedsTest
2221
import com.ichi2.anki.common.time.TimeManager
2322
import com.ichi2.anki.common.utils.ext.ifZero
2423
import com.ichi2.anki.libanki.TemplateManager.TemplateRenderContext.TemplateRenderOutput
@@ -237,7 +236,6 @@ open class Card : Cloneable {
237236
}
238237

239238
@LibAnkiAlias("current_deck_id")
240-
@NeedsTest("Test functionality which calls this")
241239
fun currentDeckId() = oDid.ifZero { did }
242240

243241
/**

libanki/src/test/java/com/ichi2/anki/libanki/CardTest.kt

Lines changed: 123 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package com.ichi2.anki.libanki
1717

1818
import android.annotation.SuppressLint
1919
import anki.scheduler.CardAnswer.Rating
20+
import com.ichi2.anki.common.time.TimeManager
2021
import com.ichi2.anki.libanki.exception.ConfirmModSchemaException
2122
import com.ichi2.anki.libanki.testutils.InMemoryAnkiTest
2223
import com.ichi2.anki.libanki.testutils.ext.addNote
@@ -25,9 +26,12 @@ import net.ankiweb.rsdroid.exceptions.BackendInvalidInputException
2526
import org.hamcrest.MatcherAssert.assertThat
2627
import org.hamcrest.Matchers.containsString
2728
import org.hamcrest.Matchers.equalTo
29+
import org.hamcrest.Matchers.greaterThanOrEqualTo
2830
import org.hamcrest.Matchers.hasItemInArray
31+
import org.hamcrest.Matchers.lessThanOrEqualTo
2932
import org.hamcrest.Matchers.not
3033
import org.junit.Assert.assertEquals
34+
import org.junit.Assert.assertNotEquals
3135
import org.junit.Test
3236
import kotlin.test.assertFailsWith
3337
import kotlin.test.assertNotNull
@@ -232,10 +236,128 @@ class CardTest : InMemoryAnkiTest() {
232236

233237
// at the time of writing, "missing template" is a hardcoded string. permalink:
234238
// https://github.com/ankitects/anki/blob/71ec878780c1b81b49b1e18b3c41237bda51e20c/rslib/src/notetype/render.rs#L54-L64
235-
val ex = assertFailsWith<BackendInvalidInputException> { col.getCard(cid).renderOutput(col) }
239+
val ex =
240+
assertFailsWith<BackendInvalidInputException> { col.getCard(cid).renderOutput(col) }
236241
assertThat(ex.message, equalTo("missing template"))
237242
}
238243

244+
// ========================================
245+
// Tests for functionality which calls currentDeckId() - addresses @NeedsTest annotation
246+
// ========================================
247+
248+
@Test
249+
fun timeLimitUsesCurrentDeckIdForNormalDeck() {
250+
// Normal deck (oDid = 0) should use did to get time limit
251+
val card = addBasicNote().firstCard()
252+
253+
val timeLimit = card.timeLimit(col)
254+
255+
// Verify that timeLimit uses the correct deck config (via currentDeckId)
256+
val config = col.decks.configDictForDeckId(card.did)
257+
assertEquals(config.maxTaken * 1000, timeLimit)
258+
}
259+
260+
@Test
261+
fun timeLimitUsesCurrentDeckIdForFilteredDeck() {
262+
// Create card in original deck and get its config value
263+
val card = addBasicNote().firstCard()
264+
val originalDeckId = card.did
265+
val originalConfig = col.decks.configDictForDeckId(originalDeckId)
266+
val originalMaxTaken = originalConfig.maxTaken
267+
268+
// Create filtered deck
269+
val filteredDeckId = col.decks.newFiltered("TestFilteredDeck")
270+
271+
// Move card to filtered deck (simulates filtered deck scenario)
272+
card.oDid = originalDeckId
273+
card.did = filteredDeckId
274+
col.updateCard(card, skipUndoEntry = true)
275+
276+
// Verify currentDeckId() returns oDid (originalDeckId) for filtered decks
277+
assertEquals(originalDeckId, card.currentDeckId())
278+
279+
// Get timeLimit - it should use the original deck's config
280+
val timeLimit = card.timeLimit(col)
281+
val expectedTimeLimit = originalMaxTaken * 1000
282+
283+
// timeLimit should match the original deck's config value
284+
assertEquals(expectedTimeLimit, timeLimit)
285+
286+
// Verify it's using currentDeckId() by checking it matches original deck's config, not filtered deck's
287+
val configDictForDeckId = col.decks.configDictForDeckId(filteredDeckId)
288+
// Both decks share the same config, so verify we're looking at the right deck ID
289+
assertEquals(originalDeckId, card.currentDeckId())
290+
assertNotEquals(filteredDeckId, card.currentDeckId())
291+
}
292+
293+
@Test
294+
fun shouldShowTimerUsesCurrentDeckId() {
295+
// shouldShowTimer should use currentDeckId to get deck configuration
296+
val card = addBasicNote().firstCard()
297+
298+
val shouldShowTimer = card.shouldShowTimer(col)
299+
300+
// Verify it uses the config from currentDeckId
301+
val config = col.decks.configDictForDeckId(card.currentDeckId())
302+
assertEquals(config.timer, shouldShowTimer)
303+
}
304+
305+
@Test
306+
fun shouldShowTimerUsesCurrentDeckIdForFilteredDeck() {
307+
// shouldShowTimer should use oDid for filtered decks
308+
val card = addBasicNote().firstCard()
309+
val originalDeckId = card.did
310+
val filteredDeckId = col.decks.id("TestFilteredDeck")
311+
312+
card.oDid = originalDeckId
313+
card.did = filteredDeckId
314+
315+
val shouldShowTimer = card.shouldShowTimer(col)
316+
317+
// Verify it uses the config from oDid (originalDeckId)
318+
assertEquals(originalDeckId, card.currentDeckId())
319+
val config = col.decks.configDictForDeckId(originalDeckId)
320+
assertEquals(config.timer, shouldShowTimer)
321+
}
322+
323+
@Test
324+
fun autoplayUsesCurrentDeckId() {
325+
// autoplay should use currentDeckId to determine autoplay setting
326+
val card = addBasicNote().firstCard()
327+
328+
val autoplay = card.autoplay(col)
329+
330+
// Verify it uses the autoplay setting from currentDeckId
331+
val config = col.decks.configDictForDeckId(card.currentDeckId())
332+
assertEquals(config.autoplay, autoplay)
333+
}
334+
335+
@Test
336+
fun replayQuestionAudioOnAnswerSideUsesCurrentDeckId() {
337+
// replayQuestionAudioOnAnswerSide should use currentDeckId for deck config
338+
val card = addBasicNote().firstCard()
339+
340+
val replayQuestion = card.replayQuestionAudioOnAnswerSide(col)
341+
342+
// Verify it uses the replayq setting from currentDeckId
343+
val config = col.decks.configDictForDeckId(card.currentDeckId())
344+
assertEquals(config.replayq, replayQuestion)
345+
}
346+
347+
@Test
348+
fun timeTakenUsesCurrentDeckIdForTimeLimit() {
349+
// timeTaken uses timeLimit() which calls currentDeckId()
350+
val card = addBasicNote().firstCard()
351+
card.timerStarted = TimeManager.time.intTimeMS() - 100 // Set to 100ms ago
352+
353+
val timeTaken = card.timeTaken(col)
354+
val timeLimit = card.timeLimit(col)
355+
356+
assertThat(timeTaken, greaterThanOrEqualTo(100))
357+
// timeTaken should respect the time limit from currentDeckId
358+
assertThat(timeTaken, lessThanOrEqualTo(timeLimit))
359+
}
360+
239361
private fun assertNoteOrdinalAre(
240362
note: Note,
241363
ords: Array<Int>,

0 commit comments

Comments
 (0)