Added testing for username and time filtering

Gave search box ids for ease of access, fixed date input bug, and added tests
`testFilterUsername`, `testFilterSince`, and `testFilterUntil`
This commit is contained in:
Benjamin Graham 2020-06-09 16:48:22 -04:00 committed by Justin Stephenson
parent 0a85319c5e
commit 7d9391da3f
2 changed files with 69 additions and 35 deletions

View file

@ -145,8 +145,7 @@ class Datetimepicker extends React.Component {
} }
handleDateChange() { handleDateChange() {
const date = $(this.refs.datepicker_input).val() const date = $(this.refs.datepicker_input).val();
.trim();
this.setState({invalid: false, date: date}); this.setState({invalid: false, date: date});
if (!parseDate(date)) { if (!parseDate(date)) {
this.setState({invalid: true}); this.setState({invalid: true});
@ -924,13 +923,13 @@ class View extends React.Component {
<td className="top"> <td className="top">
<label className="control-label" htmlFor="date_since">{_("Since")}</label> <label className="control-label" htmlFor="date_since">{_("Since")}</label>
</td> </td>
<td> <td id="since-search">
<Datetimepicker value={this.state.date_since} onChange={this.handleDateSinceChange} /> <Datetimepicker value={this.state.date_since} onChange={this.handleDateSinceChange} />
</td> </td>
<td className="top"> <td className="top">
<label className="control-label" htmlFor="date_until">{_("Until")}</label> <label className="control-label" htmlFor="date_until">{_("Until")}</label>
</td> </td>
<td> <td id="until-search">
<Datetimepicker value={this.state.date_until} onChange={this.handleDateUntilChange} /> <Datetimepicker value={this.state.date_until} onChange={this.handleDateUntilChange} />
</td> </td>
</tr> </tr>
@ -949,7 +948,7 @@ class View extends React.Component {
</td> </td>
<td> <td>
<div className="input-group"> <div className="input-group">
<input type="text" className="form-control" name="username" value={this.state.username} <input type="text" id="username-search" className="form-control" name="username" value={this.state.username}
onChange={this.handleInputChange} /> onChange={this.handleInputChange} />
</div> </div>
</td> </td>

View file

@ -139,7 +139,7 @@ class TestApplication(MachineCase):
b.click("#player-play-pause") b.click("#player-play-pause")
def testSessionRecordingConf(self): def testSessionRecordingConf(self):
import json, configparser import time, json, configparser
b, m = self._login() b, m = self._login()
# Ensure that the button leads to the config page # Ensure that the button leads to the config page
@ -173,6 +173,7 @@ class TestApplication(MachineCase):
b.set_checked("#journal_augment", False) b.set_checked("#journal_augment", False)
b.set_val("#writer", "file") b.set_val("#writer", "file")
b.click("#btn-save-tlog-conf") b.click("#btn-save-tlog-conf")
time.sleep(1)
m.download(conf_file, test_file) m.download(conf_file, test_file)
# Revert to the previous config before testing to ensure test continuity # Revert to the previous config before testing to ensure test continuity
m.upload([save_file], conf_file_path) m.upload([save_file], conf_file_path)
@ -217,6 +218,7 @@ class TestApplication(MachineCase):
# Download test with scope 'All' # Download test with scope 'All'
b.set_val("#scope", "all") b.set_val("#scope", "all")
b.click("#btn-save-sssd-conf") b.click("#btn-save-sssd-conf")
time.sleep(1)
m.download(conf_file, test_all_file) m.download(conf_file, test_all_file)
# Revert to the previous config before testing to ensure test continuity # Revert to the previous config before testing to ensure test continuity
m.upload([save_file], conf_file_path) m.upload([save_file], conf_file_path)
@ -282,12 +284,21 @@ class TestApplication(MachineCase):
b.click("#player-zoom-out") b.click("#player-zoom-out")
b.wait_present(play_scale_sel) b.wait_present(play_scale_sel)
def testSearch(self): def _filter(self, inp, occ_dict):
import time import time
b, _ = self._login() b, _ = self._login()
# conduct searches that will return 2, 1, or 0 items for occ in occ_dict:
terms = { for term in occ_dict[occ]:
# enter the search term and wait for the results to return
b.set_input_text(inp, term)
time.sleep(0.5)
assert b.text(".listing-ct").count("contractor") == occ
def testSearch(self):
self._filter(
"#recording-search",
{
0: { 0: {
"this should return nothing", "this should return nothing",
"this should also return nothing", "this should also return nothing",
@ -302,19 +313,43 @@ class TestApplication(MachineCase):
}, },
2: { 2: {
"id", "id",
"contractor1",
"localhost", "localhost",
"exit", "exit",
"actor", "actor",
"contractor",
"contractor1@localhost", "contractor1@localhost",
}, },
} },
for num in terms: )
for term in terms[num]:
# enter the search term and wait for results to return def testFilterUsername(self):
b.set_input_text("#recording-search", term) self._filter(
time.sleep(0.5) "#username-search",
assert b.text(".listing-ct").count("contractor1") == num {
0: {"test", "contact", "contractor", "contractor11", "contractor4"},
2: {"contractor1"},
},
)
def testFilterSince(self):
self._filter(
"#since-search .bootstrap-datepicker",
{
0: {"2020-06-02", "2020-06-01 12:31:00"},
1: {"2020-06-01 12:17:01", "2020-06-01 12:30:50"},
2: {"2020-06-01", "2020-06-01 12:17:00"},
},
)
def testFilterUntil(self):
self._filter(
"#until-search .bootstrap-datepicker",
{
0: {"2020-06-01", "2020-06-01 12:16:00"},
1: {"2020-06-01 12:17:00", "2020-06-01 12:29:42"},
2: {"2020-06-02", "2020-06-01 12:31:00"},
},
)
if __name__ == "__main__": if __name__ == "__main__":