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

View file

@ -139,7 +139,7 @@ class TestApplication(MachineCase):
b.click("#player-play-pause")
def testSessionRecordingConf(self):
import json, configparser
import time, json, configparser
b, m = self._login()
# Ensure that the button leads to the config page
@ -173,6 +173,7 @@ class TestApplication(MachineCase):
b.set_checked("#journal_augment", False)
b.set_val("#writer", "file")
b.click("#btn-save-tlog-conf")
time.sleep(1)
m.download(conf_file, test_file)
# Revert to the previous config before testing to ensure test continuity
m.upload([save_file], conf_file_path)
@ -217,6 +218,7 @@ class TestApplication(MachineCase):
# Download test with scope 'All'
b.set_val("#scope", "all")
b.click("#btn-save-sssd-conf")
time.sleep(1)
m.download(conf_file, test_all_file)
# Revert to the previous config before testing to ensure test continuity
m.upload([save_file], conf_file_path)
@ -282,39 +284,72 @@ class TestApplication(MachineCase):
b.click("#player-zoom-out")
b.wait_present(play_scale_sel)
def testSearch(self):
def _filter(self, inp, occ_dict):
import time
b, _ = self._login()
# conduct searches that will return 2, 1, or 0 items
terms = {
0: {
"this should return nothing",
"this should also return nothing",
"0123456789",
},
1: {
"extra commands",
"whoami",
"ssh",
"thisisatest123",
"thisisanothertest456",
},
2: {
"id",
"contractor1",
"localhost",
"exit",
"actor",
"contractor1@localhost",
},
}
for num in terms:
for term in terms[num]:
# enter the search term and wait for results to return
b.set_input_text("#recording-search", term)
for occ in occ_dict:
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("contractor1") == num
assert b.text(".listing-ct").count("contractor") == occ
def testSearch(self):
self._filter(
"#recording-search",
{
0: {
"this should return nothing",
"this should also return nothing",
"0123456789",
},
1: {
"extra commands",
"whoami",
"ssh",
"thisisatest123",
"thisisanothertest456",
},
2: {
"id",
"localhost",
"exit",
"actor",
"contractor",
"contractor1@localhost",
},
},
)
def testFilterUsername(self):
self._filter(
"#username-search",
{
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__":