From 932464d0a0f572e256f6dea898196db1e3f66b50 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 24 Dec 2013 14:28:20 +1300 Subject: test passing, UI still not working --- test/test_console_contentview.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/test_console_contentview.py') diff --git a/test/test_console_contentview.py b/test/test_console_contentview.py index ef44f834..c2ed2ffa 100644 --- a/test/test_console_contentview.py +++ b/test/test_console_contentview.py @@ -250,3 +250,17 @@ if cv.ViewProtobuf.is_available(): def test_get_by_shortcut(): assert cv.get_by_shortcut("h") + +def test_search_highlights(): + # Default text in requests is content. We will search for nt once, and + # expect the first bit to be highlighted. We will do it again and expect the + # second to be. + f = tutils.tflowview() + + ui_elements = f.search("nt") + text_object = ui_elements.contents()[2] + assert text_object.get_text() == ('content', [(None, 2), ('dark red', 2)]) + + ui_elements = f.search("nt") + text_object = ui_elements.contents()[2] + assert text_object.get_text() == ('content', [(None, 5), ('dark red', 2)]) -- cgit v1.2.3 From 95406bd119d87ccc3e99ddffd11c92e92a7da34b Mon Sep 17 00:00:00 2001 From: root Date: Wed, 25 Dec 2013 16:50:29 +1300 Subject: Add focusing, and fixes non-clearance of prev searches. Add documentation. --- test/test_console_contentview.py | 55 +++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 6 deletions(-) (limited to 'test/test_console_contentview.py') diff --git a/test/test_console_contentview.py b/test/test_console_contentview.py index c2ed2ffa..95012657 100644 --- a/test/test_console_contentview.py +++ b/test/test_console_contentview.py @@ -257,10 +257,53 @@ def test_search_highlights(): # second to be. f = tutils.tflowview() - ui_elements = f.search("nt") - text_object = ui_elements.contents()[2] - assert text_object.get_text() == ('content', [(None, 2), ('dark red', 2)]) + f.search("nt") + text_object = tutils.get_body_line(f.last_displayed_body, 0) + assert text_object.get_text() == ('content', [(None, 2), (f.highlight_color, 2)]) + + f.search("nt") + text_object = tutils.get_body_line(f.last_displayed_body, 1) + assert text_object.get_text() == ('content', [(None, 5), (f.highlight_color, 2)]) + +def test_search_highlights_clears_prev(): + f = tutils.tflowview(request_contents="this is string\nstring is string") + + f.search("string") + text_object = tutils.get_body_line(f.last_displayed_body, 0) + assert text_object.get_text() == ('this is string', [(None, 8), (f.highlight_color, 6)]) + + # search again, it should not be highlighted again. + f.search("string") + text_object = tutils.get_body_line(f.last_displayed_body, 0) + assert text_object.get_text() != ('this is string', [(None, 8), (f.highlight_color, 6)]) + +def test_search_highlights_multi_line(): + f = tutils.tflowview(request_contents="this is string\nstring is string") + + # should highlight the first line. + f.search("string") + text_object = tutils.get_body_line(f.last_displayed_body, 0) + assert text_object.get_text() == ('this is string', [(None, 8), (f.highlight_color, 6)]) + + # should highlight second line, first appearance of string. + f.search("string") + text_object = tutils.get_body_line(f.last_displayed_body, 1) + assert text_object.get_text() == ('string is string', [(None, 0), ('key', 6)]) + + # should highlight third line, second appearance of string. + f.search("string") + text_object = tutils.get_body_line(f.last_displayed_body, 1) + assert text_object.get_text() == ('string is string', [(None, 10), (f.highlight_color, 6)]) + +def test_search_focuses(): + f = tutils.tflowview(request_contents="this is string\nstring is string") + + # should highlight the first line. + f.search("string") + + # should be focusing on the 2nd text line. + f.search("string") + text_object = tutils.get_body_line(f.last_displayed_body, 1) + assert f.last_displayed_body.focus == text_object + - ui_elements = f.search("nt") - text_object = ui_elements.contents()[2] - assert text_object.get_text() == ('content', [(None, 5), ('dark red', 2)]) -- cgit v1.2.3 From 9cf8a1a89dadfebedaf48258519c9a8953375597 Mon Sep 17 00:00:00 2001 From: Pedro Worcel Date: Wed, 25 Dec 2013 21:08:20 +1300 Subject: fix failing test --- test/test_console_contentview.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/test_console_contentview.py') diff --git a/test/test_console_contentview.py b/test/test_console_contentview.py index 95012657..32f4fad2 100644 --- a/test/test_console_contentview.py +++ b/test/test_console_contentview.py @@ -288,7 +288,8 @@ def test_search_highlights_multi_line(): # should highlight second line, first appearance of string. f.search("string") text_object = tutils.get_body_line(f.last_displayed_body, 1) - assert text_object.get_text() == ('string is string', [(None, 0), ('key', 6)]) + print text_object.get_text() + assert text_object.get_text() == ('string is string', [(None, 0), (f.highlight_color, 6)]) # should highlight third line, second appearance of string. f.search("string") -- cgit v1.2.3 From 21efe2f2c84cd0615d0b0f47a9007efe34abc5b9 Mon Sep 17 00:00:00 2001 From: Pedro Worcel Date: Thu, 26 Dec 2013 17:04:18 +1300 Subject: add looping around --- test/test_console_contentview.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/test_console_contentview.py') diff --git a/test/test_console_contentview.py b/test/test_console_contentview.py index 32f4fad2..d013d10d 100644 --- a/test/test_console_contentview.py +++ b/test/test_console_contentview.py @@ -265,6 +265,13 @@ def test_search_highlights(): text_object = tutils.get_body_line(f.last_displayed_body, 1) assert text_object.get_text() == ('content', [(None, 5), (f.highlight_color, 2)]) +def test_search_returns_useful_messages(): + f = tutils.tflowview() + + # original string is content. this string should not be in there. + response = f.search("oranges and other fruit.") + assert response == "no matches for 'oranges and other fruit.'" + def test_search_highlights_clears_prev(): f = tutils.tflowview(request_contents="this is string\nstring is string") @@ -296,6 +303,20 @@ def test_search_highlights_multi_line(): text_object = tutils.get_body_line(f.last_displayed_body, 1) assert text_object.get_text() == ('string is string', [(None, 10), (f.highlight_color, 6)]) +def test_search_loops(): + f = tutils.tflowview(request_contents="this is string\nstring is string") + + # get to the end. + f.search("string") + f.search("string") + f.search("string") + + # should highlight the first line. + message = f.search("string") + text_object = tutils.get_body_line(f.last_displayed_body, 0) + assert text_object.get_text() == ('this is string', [(None, 8), (f.highlight_color, 6)]) + assert message == "search hit BOTTOM, continuing at TOP" + def test_search_focuses(): f = tutils.tflowview(request_contents="this is string\nstring is string") -- cgit v1.2.3 From 799c87767684880469c12d75053fb860f4a0d3c9 Mon Sep 17 00:00:00 2001 From: Pedro Worcel Date: Thu, 26 Dec 2013 22:18:34 +1300 Subject: now really fix it + test --- test/test_console_contentview.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'test/test_console_contentview.py') diff --git a/test/test_console_contentview.py b/test/test_console_contentview.py index d013d10d..f581424b 100644 --- a/test/test_console_contentview.py +++ b/test/test_console_contentview.py @@ -295,7 +295,6 @@ def test_search_highlights_multi_line(): # should highlight second line, first appearance of string. f.search("string") text_object = tutils.get_body_line(f.last_displayed_body, 1) - print text_object.get_text() assert text_object.get_text() == ('string is string', [(None, 0), (f.highlight_color, 6)]) # should highlight third line, second appearance of string. @@ -328,4 +327,24 @@ def test_search_focuses(): text_object = tutils.get_body_line(f.last_displayed_body, 1) assert f.last_displayed_body.focus == text_object +def test_search_does_not_crash_on_bad(): + """ + this used to crash, kept for reference. + """ + + f = tutils.tflowview(request_contents="this is string\nstring is string\n"+("A" * cv.VIEW_CUTOFF)+"AFTERCUTOFF") + f.search("AFTERCUTOFF") + + # pretend F + f.state.add_flow_setting( + f.flow, + (f.state.view_flow_mode, "fullcontents"), + True + ) + f.master.refresh_flow(f.flow) + + # text changed, now this string will exist. can happen when user presses F + # for full text view + f.search("AFTERCUTOFF") + -- cgit v1.2.3