-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DeckOption request the user to confirm whether to discard only if there are local changes #17315
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love the idea, implementation seems good but will defer to anyone better at Kotlin for taste and to Brayan for idea-consistency with what he was thinking
@voczi FYI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works for me, but I agree with David's comments.
And, I expect that when we'll use more webview, more
bridgeCommand
will arrive.
About that, @dae himself said that he wants to avoid bridgeCommand
in new code.
If this is new code and still uses bridgeCommand
, I'm honestly disappointed.
I was referring to https://github.com/ankitects/anki/pull/3410/files , which introduces changes in svelte I wanted to use (and then I realize that, even if it’s available in ankidroid-backend, it’s not in ankidroid yet). It does not introduce new But I guess I can just ignore this bridge command, assume that when the page is loaded, it can accept request. And any result that is not a boolean means the page was not loaded so we can’t close it. Still, given that bridgeCommand already exists and does not seems to be going to be deleted soon, I still suspect this PR is useful. I’ll apply David’s change when I’m on my home computer |
oh, I finally figured out why I was confused. New bridge commands were added in https://github.com/ankitects/anki/pull/3495/files |
efa539c
to
761263b
Compare
So I applied @david-allison 's requested change, and then added an extra commit to solve the deck option issue. If we eventually move away from the bridge, this will need to be updated. |
Given the extra commit, I removed @mikehardy 's approval. |
c02bb90
to
90cdf03
Compare
Does anyone know whether PageFragments actually load their webcontent in RobolectricTest ? I tried adding
after pressing back, and it does not solve anything. So I assume it's a problem with the JS part |
As discussed on Discord, the WebView is a "shadow" (that is: fake) implementation in robolectric. |
90cdf03
to
d56a2ac
Compare
d56a2ac
to
26752dd
Compare
I removed the unit test then. There is no relevant way to do them. Unless I I start to mock the webview behavior, and that does not seems interesting things to do. In particular because this would break as soon as the deck option's TS code change For some reason I don't understand, when I am in the deck picker, with instrumented tests, long click fail to open the menu. I don't know whether it just entirely fail to be registered, or whether the instrumented test don't open the menu for some reason. |
66092be
to
38bbf5d
Compare
Rebased on top of #17419 so that I can reuse some deck picker instrumented tests function |
38bbf5d
to
d815373
Compare
Please add some |
Done, sorry |
06efeab
to
7a57ae0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Main question is regarding functionality + manual testing
And potential issues two classes with the same JavaScriptInterface
, I'd avoid this by renaming the "ankidroid"
interface we add in DeckOptions
Really appreciate the effort which went into re-testing this, thanks!!
|
||
@Before | ||
fun before() { | ||
assumeFalse("Test flaky in CI - #9282, skipping", wasBuiltOnCI()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This issue is closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reopened it. There are still multiple disabled tests referring to this issue
AnkiDroid/src/androidTest/java/com/ichi2/anki/DeckOptionsTest.kt
Outdated
Show resolved
Hide resolved
} | ||
|
||
@Test | ||
fun testDeckOptionsWithChangeShowAlert() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test has no assertions, and is therefore difficult to understand the intention
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually there are assertions in openDeckOptions.
But the most important one is that the click can occurs, which means the buttons indeed exists. I don't know exactly how to state this with assertion
|
||
// Close without change | ||
pressBack() | ||
assertWebViewDoesNotExists() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you want to assert that either: the fragment/activity is no longer loaded, or the user has gone back to the previous screen.
The WebView not existing doesn't seem to be a good proxy for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that at first. But somehow searching for the presence of a view whose id is R.layout.page_fragment
does not work. It is never found. Instead, the log displaying the current view on the screen just shows me a WebView without PageFragment
anywhere
* 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 com.ichi2.anki |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like it should be in a utility package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Actually it was done in the PR #17419 that I use in two PRs.
try { | ||
check(viewAssertion) | ||
return | ||
} catch (e: Throwable) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: is this a bug. I would expect a ViewNotFound
to be retried, but an assertion failure should exit the loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I suggest moving the discussion to #17419. As this is the commit that is common to two PRs where I need to do instrumented test.
This function is not changed at all. If it must be corrected, I think this is out of scope here.
What mattered to me is that I could use it without having to be in a subclass of InstrumentedTest
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class DeckOptionsTest : InstrumentedTest() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests don't seem to handle either of the following cases. Did you manually test these:
- User navigated to the Anki Manual via a link, and pressed 'back'
- WebView should navigate back to options (changes are persisted), options should remain open
- User opened up a modal on the svelte page and pressed 'back'
- modal should close, options should remain open
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently html generated by svelte has no id. It's pretty hard to select something at least if I want to be sure that random change in svelte code won't break the test.
As far as I can tell, it's not even tested upstream.
I manually tested it. When the manual or a link from it is opened, and I press back, either on the screen or the phone button, the deck options remain open and the manual get closed.
I asked about test upstream. Maybe I'll have to ask permission to add id. Right now, I don't think writing those test is worth it.
7a57ae0
to
4902897
Compare
I also remove `OnPageFinishedCallback` because I don't really see the point in this list in Kotlin. I keep the interface as it's used in AbstractFlashcardViewer.
The names were far from clear
`bridgeCommand` is the general process by which Anki's webview send command to the webview's owner. In Anki, it's interpreted by Python. In AnkiDroid it must be interpreted by Kotlin. Currently, the only `bridgeCommand` we listen to are in CongratsPage. And I'm really thankful `@BrayanDSO` for creating this first usage! When anki 24.10 beta 2 is used in ankidroid, the DeckOptions will also send `bridgeCommand`. And, I expect that when we'll use more webview, more `bridgeCommand` will arrive. So, I decided to generalize Brayan's code and ensure that there is a simple map that any PageFragment can override that would allow to declare its `bridgeCommand` without needing to add copy `CongratsPage`'s code. I tested this manually, and the CongratsPage's button still works.
This use a recent change introduced upstream. Unit test can't run the webview. So it has to be replaced by instrumented tests. Test fails on CI while working locally, so I have to assume it's not CI.
4902897
to
488031b
Compare
NF: Simplify the usage of bridgeCommand in PageFragment
bridgeCommand
is the general process by which Anki's webview sendcommand to the webview's owner. In Anki, it's interpreted by
Python. In AnkiDroid it must be interpreted by Kotlin.
Currently, the only
bridgeCommand
we listen to are inCongratsPage. And I'm really thankful @BrayanDSO for creating this
first usage!
When anki 24.10 beta 2 is used in ankidroid, the DeckOptions will also
send
bridgeCommand
. And, I expect that when we'll use more webview,more
bridgeCommand
will arrive.So, I decided to generalize Brayan's code and ensure that there is a
simple map that any PageFragment can override that would allow to
declare its
bridgeCommand
without needing to add copyCongratsPage
's code.I tested this manually, and the CongratsPage's button still works.