@@ -12,7 +12,7 @@ namespace BasicPlainTextReaderApp.UITests
1212 public class Tests
1313 {
1414 IApp app ;
15- Platform platform ;
15+ readonly Platform platform ;
1616
1717 public Tests ( Platform platform )
1818 {
@@ -29,12 +29,82 @@ public void BeforeEachTest()
2929 public void WelcomeTextIsDisplayed ( )
3030 {
3131 AppResult [ ] results = app . WaitForElement ( c => c . Marked ( "Basic Text Reader App" ) ) ;
32- //app.Screenshot("Welcome screen.");
33-
34- Assert . IsTrue ( results . Any ( ) ) ;
3532
33+ Assert . IsTrue ( results . Any ( ) ) ;
34+ var elem = app . Query ( "Made by @jonwolfdev" ) . FirstOrDefault ( ) ;
35+ Assert . IsNotNull ( elem ) ;
36+ }
37+
38+ [ Test ]
39+ public void OpenFileIsDisplayedAndSearchWorks ( )
40+ {
41+ string fileContents = "Test file\n Test file line 2\n " ;
42+ string filePath = "/data/user/0/dev.jonwolf.basicplaintextreaderapp/files/test.txt" ;
43+ string searchPopupText = "Enter the text to search for" ;
44+ string firstSearch = "file" ;
45+ string secondSearch = "line" ;
46+ string buttonPopupInfoClose = "button2" ;
47+ string buttonPopupSearchSearch = "button1" ;
3648 app . Invoke ( "OpenTextFile" ) ;
37- AppResult [ ] results2 = app . WaitForElement ( c => c . Id ( "InfoItemAi" ) ) ;
49+
50+ AppResult [ ] results2 = app . WaitForElement ( c => c . Marked ( filePath ) ) ;
51+ Assert . AreEqual ( 1 , results2 . Count ( ) ) ;
52+
53+
54+ var label = app . Query ( fileContents ) . FirstOrDefault ( ) ;
55+ Assert . IsNotNull ( label ) ;
56+ Assert . AreEqual ( fileContents , label . Text ) ;
57+ app . Tap ( "Info" ) ;
58+
59+ // Popup message
60+ AppResult [ ] resultsMsg = app . WaitForElement ( c => c . Marked ( "message" ) ) ;
61+ Assert . AreEqual ( 1 , resultsMsg . Length ) ;
62+
63+ Assert . IsTrue ( resultsMsg [ 0 ] . Text . Contains ( "Type: text/plain" ) ) ;
64+ Assert . IsTrue ( resultsMsg [ 0 ] . Text . Contains ( "DataPath: " + filePath ) ) ;
65+
66+ // Close button
67+ app . Tap ( buttonPopupInfoClose ) ;
68+ app . WaitForNoElement ( "message" ) ;
69+ {
70+ app . Tap ( "Search" ) ;
71+ // Popup search
72+ var searchPopup = app . WaitForElement ( "message" ) ;
73+ Assert . IsTrue ( searchPopup . Any ( ) ) ;
74+
75+ Assert . AreEqual ( searchPopupText , searchPopup [ 0 ] . Text ) ;
76+ app . EnterText ( firstSearch ) ;
77+ // Search button
78+ app . Tap ( buttonPopupSearchSearch ) ;
79+
80+ app . WaitForElement ( "Found 2 matches" ) ;
81+
82+ var elemMatches = app . WaitForElement ( fileContents ) ;
83+ Assert . AreEqual ( 2 , elemMatches . Length ) ;
84+ }
85+
86+ // Search again but within the same search page
87+ {
88+ app . Tap ( "Search" ) ;
89+ // Popup search
90+ var searchPopup = app . WaitForElement ( "message" ) ;
91+ Assert . IsTrue ( searchPopup . Any ( ) ) ;
92+
93+ Assert . AreEqual ( searchPopupText , searchPopup [ 0 ] . Text ) ;
94+ app . EnterText ( secondSearch ) ;
95+ // Search button
96+ app . Tap ( buttonPopupSearchSearch ) ;
97+
98+ app . WaitForElement ( "Found 1 matches" ) ;
99+
100+ var elemMatches = app . WaitForElement ( fileContents ) ;
101+ Assert . AreEqual ( 1 , elemMatches . Length ) ;
102+ }
103+
104+ app . Back ( ) ;
105+
106+ AppResult [ ] resultsBack = app . WaitForElement ( c => c . Marked ( filePath ) ) ;
107+ Assert . AreEqual ( 1 , resultsBack . Count ( ) ) ;
38108 }
39109
40110
0 commit comments