Skip to content

Commit 4770f2b

Browse files
committed
Merge branch 'save_book_filter_state' into develop
2 parents f5fa74f + aab04df commit 4770f2b

File tree

6 files changed

+49
-3
lines changed

6 files changed

+49
-3
lines changed

lute/templates/book/tablelisting.html

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
</form>
1616

1717
<script>
18-
18+
19+
/* The book listing. */
20+
var book_listing_table;
21+
1922
let setup_text_datatable = function(initial_search) {
20-
var table = $('#booktable').DataTable({
23+
book_listing_table = $('#booktable').DataTable({
2124
{% if status != 'Archived' %}
2225
"language": {
2326
"emptyTable": "No books available. <a href='/book/new'>Create one?</a>"
@@ -32,6 +35,7 @@
3235
searching: true,
3336
processing: true,
3437
serverSide: true,
38+
stateSave: true,
3539
search: { search: initial_search },
3640
columnDefs: [
3741
{
@@ -156,4 +160,16 @@
156160
do_action_post('delete', bookid);
157161
}
158162

163+
/**
164+
* Clearing the state is required for acceptance tests,
165+
* because otherwise state is accidentally applied to
166+
* following tests, messing up test results.
167+
* I tried various things such as setting and clearing
168+
* the filter input box, but this was the only method
169+
* that worked reliably.
170+
* This is called from the lute_test_client.py.
171+
*/
172+
function clear_datatable_state() {
173+
book_listing_table.state.clear();
174+
}
159175
</script>

tasks.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,15 @@ def black(c):
206206
c.run("python -m black .")
207207

208208

209-
@task(pre=[test, accept, playwright, black, lint])
209+
@task(pre=[test, accept, playwright])
210+
def fulltest(c): # pylint: disable=unused-argument
211+
"""
212+
Run full tests check.
213+
"""
214+
print("Done.")
215+
216+
217+
@task(pre=[fulltest, black, lint])
210218
def full(c): # pylint: disable=unused-argument
211219
"""
212220
Run full check and lint.
@@ -215,6 +223,7 @@ def full(c): # pylint: disable=unused-argument
215223

216224

217225
ns = Collection()
226+
ns.add_task(fulltest)
218227
ns.add_task(full)
219228
ns.add_task(lint)
220229
ns.add_task(test)

tests/acceptance/conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def given_running_site(luteclient):
139139
resp = requests.get(luteclient.home, timeout=5)
140140
assert resp.status_code == 200, f"{luteclient.home} is up"
141141
luteclient.visit("/")
142+
luteclient.clear_book_filter()
142143
assert luteclient.browser.is_text_present("Lute")
143144

144145

@@ -188,7 +189,17 @@ def given_demo_langs_loaded(luteclient):
188189

189190
@given("the demo stories are loaded")
190191
def given_demo_stories_loaded(luteclient):
192+
"Load the demo stories."
191193
luteclient.load_demo_stories()
194+
luteclient.visit("/")
195+
luteclient.clear_book_filter()
196+
197+
198+
@given("I clear the book filter")
199+
def given_clear_book_filter(luteclient):
200+
"clear filter."
201+
luteclient.visit("/")
202+
luteclient.clear_book_filter()
192203

193204

194205
@given(parsers.parse("I update the {lang} language:\n{content}"))

tests/acceptance/lute_test_client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def __init__(self, b, home):
4444
def load_demo_stories(self):
4545
"Load the demo stories."
4646
self.visit("dev_api/load_demo_stories")
47+
self.visit("/")
48+
self.clear_book_filter()
4749

4850
def change_parser_registry_key(self, key, replacement):
4951
"""
@@ -67,6 +69,11 @@ def index(self):
6769
"Go to home page."
6870
self.browser.visit("")
6971

72+
def clear_book_filter(self):
73+
"Clear all state. Normally state is saved."
74+
self.browser.execute_script("clear_datatable_state()")
75+
time.sleep(0.1)
76+
7077
def click_link(self, linktext):
7178
self.browser.links.find_by_text(linktext).click()
7279

tests/acceptance/reading.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ Feature: User can actually read and stuff.
105105
When I click the "Tutorial" link
106106
And I click the footer next page
107107
Given I visit "/"
108+
And I clear the book filter
108109
And the book table loads "Tutorial"
109110
Then the page contains "Tutorial (2/"
110111

tests/acceptance/test_smoke.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
def test_smoke_test(chromebrowser, luteclient):
77
"Hit the main page, create a book, update a term."
88
luteclient.visit("/")
9+
luteclient.clear_book_filter()
910
assert chromebrowser.is_text_present("Lute"), "have main page."
1011
luteclient.make_book("Hola", "Hola. Adios amigo.", "Spanish")
1112
assert chromebrowser.title == 'Reading "Hola"', "title"
@@ -26,6 +27,7 @@ def test_unsupported_language_not_shown(luteclient, _restore_jp_parser):
2627

2728
luteclient.change_parser_registry_key("japanese", "disabled_japanese")
2829
luteclient.visit("/")
30+
luteclient.clear_book_filter()
2931
assert not luteclient.browser.is_text_present("Japanese"), "no Japanese demo book."
3032
assert luteclient.browser.is_text_present(
3133
"Tutorial"

0 commit comments

Comments
 (0)