Completed regression test for school subscription

This commit is contained in:
Andrea Fazzi 2020-02-10 14:29:24 +01:00
parent 85f7e49636
commit b70ef2a07e
4 changed files with 212 additions and 84 deletions

View file

@ -4,6 +4,7 @@ import (
"fmt"
"testing"
"git.andreafazzi.eu/andrea/oef/orm"
"github.com/remogatto/prettytest"
"github.com/tebeka/selenium"
)
@ -96,63 +97,17 @@ func (t *testSuite) TestSchoolSubscription() {
panic(err)
}
err = findElement("#school_name").SendKeys("Liceo GALILEI")
if err != nil {
panic(err)
}
err = findElement("#school_code").SendKeys("FI12346789")
if err != nil {
panic(err)
}
err = findElement("#school_address").SendKeys("via Trieste 1, Milano")
if err != nil {
panic(err)
}
err = findElement("button.dropdown-toggle").Click()
if err != nil {
panic(err)
}
err = findElement(".bs-searchbox input").SendKeys("Friuli")
if err != nil {
panic(err)
}
err = findElement("a.dropdown-item.active").Click()
if err != nil {
panic(err)
}
err = findElement("#school_email").SendKeys("foo.bar@school.org")
if err != nil {
panic(err)
}
err = findElement("#school_contact_person_firstname").SendKeys("Mario")
if err != nil {
panic(err)
}
err = findElement("#school_contact_person_lastname").SendKeys("BROS")
if err != nil {
panic(err)
}
err = findElement("#school_contest_director_firstname").SendKeys("Luigi")
if err != nil {
panic(err)
}
err = findElement("#school_contest_director_lastname").SendKeys("BROS")
if err != nil {
panic(err)
}
err = findElement("button.btn.btn-primary").Click()
if err != nil {
panic(err)
}
addSchoolAsSubscriber(&orm.School{
Name: "Liceo GALILEI",
Code: "Fi12346789",
Address: "via Trieste 1, Milano",
Region: &orm.Region{Name: "Friuli"},
Email: "foo.bar@school.org",
SchoolContactPersonFirstname: "Mario",
SchoolContactPersonLastname: "BROS",
ContestDirectorFirstname: "Luigi",
ContestDirectorLastname: "BROS",
})
expected := []string{"Liceo GALILEI", "foo.bar@school.org"}
elements := findElements("p strong")
@ -183,31 +138,44 @@ func (t *testSuite) TestSchoolSubscription() {
login(username, password)
logout()
// Subscribe a participant
addParticipantAsSchool(&orm.Participant{
Firstname: "Mario",
Lastname: "ROSSI",
FiscalCode: "RSSMR1234567",
Category: &orm.Category{Name: "Junior"},
})
login("admin", "admin")
// Subscribe another participant
addParticipantAsSchool(&orm.Participant{
Firstname: "Serena",
Lastname: "BIANCA",
FiscalCode: "BNCSR1234567",
Category: &orm.Category{Name: "Senior"},
})
err = findElement("#schools_navbar_link").Click()
if err != nil {
panic(err)
}
err = findElement("#myInput").SendKeys("Liceo GALILEI")
if err != nil {
panic(err)
}
err = findElement("a.oef-selected-by-search").Click()
if err != nil {
panic(err)
}
err = findElement("button.karmen-ajax-delete").Click()
if err != nil {
panic(err)
}
err = findElement("#karmen-modal-btn-confirm").Click()
if err != nil {
panic(err)
alert, err := findElement(".alert").Text()
t.Nil(err)
t.Contain("Iscrizione completa", alert)
findElement("#school_navbar_link").Click()
expected = []string{"Mario ROSSI", "Serena BIANCA"}
elements = findElements("#partecipanti_list_group a")
t.True(len(elements) > 0)
for i, el := range elements {
text, err := el.Text()
if err != nil {
panic(err)
}
t.Contain(expected[i], text)
}
removeSchoolAsAdmin("Liceo GALILEI")
removeParticipantAsAdmin("ROSSI")
removeParticipantAsAdmin("BIANCA")
}
func findElement(selector string) selenium.WebElement {
@ -227,7 +195,12 @@ func findElements(selector string) []selenium.WebElement {
}
func login(username, password string) {
err := findElement("#username").SendKeys(username)
err := wd.Get("http://oef_regression_test:3000")
if err != nil {
panic(err)
}
err = findElement("#username").SendKeys(username)
if err != nil {
panic(err)
}
@ -249,3 +222,158 @@ func logout() {
panic(err)
}
}
func removeSchoolAsAdmin(name string) {
logout()
login("admin", "admin")
err := findElement("#schools_navbar_link").Click()
if err != nil {
panic(err)
}
err = findElement("#myInput").SendKeys(name)
if err != nil {
panic(err)
}
err = findElement("a.oef-selected-by-search").Click()
if err != nil {
panic(err)
}
err = findElement("button.karmen-ajax-delete").Click()
if err != nil {
panic(err)
}
err = findElement("#karmen-modal-btn-confirm").Click()
if err != nil {
panic(err)
}
}
func removeParticipantAsAdmin(name string) {
logout()
login("admin", "admin")
err := findElement("#participants_navbar_link").Click()
if err != nil {
panic(err)
}
err = findElement("#myInput").SendKeys(name)
if err != nil {
panic(err)
}
err = findElement("a.oef-selected-by-search").Click()
if err != nil {
panic(err)
}
err = findElement("button.karmen-ajax-delete").Click()
if err != nil {
panic(err)
}
err = findElement("#karmen-modal-btn-confirm").Click()
if err != nil {
panic(err)
}
}
func addSchoolAsSubscriber(school *orm.School) {
err := findElement("#school_name").SendKeys(school.Name)
if err != nil {
panic(err)
}
err = findElement("#school_code").SendKeys(school.Code)
if err != nil {
panic(err)
}
err = findElement("#school_address").SendKeys(school.Address)
if err != nil {
panic(err)
}
err = findElement("button.dropdown-toggle").Click()
if err != nil {
panic(err)
}
err = findElement(".bs-searchbox input").SendKeys(school.Region.Name)
if err != nil {
panic(err)
}
err = findElement("a.dropdown-item.active").Click()
if err != nil {
panic(err)
}
err = findElement("#school_email").SendKeys(school.Email)
if err != nil {
panic(err)
}
err = findElement("#school_contact_person_firstname").SendKeys(school.SchoolContactPersonFirstname)
if err != nil {
panic(err)
}
err = findElement("#school_contact_person_lastname").SendKeys(school.SchoolContactPersonLastname)
if err != nil {
panic(err)
}
err = findElement("#school_contest_director_firstname").SendKeys(school.ContestDirectorFirstname)
if err != nil {
panic(err)
}
err = findElement("#school_contest_director_lastname").SendKeys(school.ContestDirectorLastname)
if err != nil {
panic(err)
}
err = findElement("button.btn.btn-primary").Click()
if err != nil {
panic(err)
}
}
func addParticipantAsSchool(participant *orm.Participant) {
err := findElement("#new_participant_subscribe").Click()
if err != nil {
panic(err)
}
err = findElement("#participant_firstname").SendKeys(participant.Firstname)
if err != nil {
panic(err)
}
err = findElement("#participant_lastname").SendKeys(participant.Lastname)
if err != nil {
panic(err)
}
err = findElement("#participant_fiscalcode").SendKeys(participant.FiscalCode)
if err != nil {
panic(err)
}
err = findElement("button.dropdown-toggle").Click()
if err != nil {
panic(err)
}
err = findElement(".bs-searchbox input").SendKeys(participant.Category.Name)
if err != nil {
panic(err)
}
err = findElement("a.dropdown-item.active").Click()
if err != nil {
panic(err)
}
err = findElement("button.btn.btn-primary").Click()
if err != nil {
panic(err)
}
}

View file

@ -44,12 +44,12 @@
<a class="nav-item nav-link {{.Options|active "Question"}}" href="{{all "Question"}}">Domande</a>
<a class="nav-item nav-link {{.Options|active "Answer"}}" href="{{all "Answer"}}">Risposte</a>
<a id="schools_navbar_link" class="nav-item nav-link {{.Options|active "School"}}" href="{{all "School"}}">Scuole</a>
<a class="nav-item nav-link {{.Options|active "Participant"}}" href="{{all "Participant"}}">Partecipanti</a>
<a id="participants_navbar_link" class="nav-item nav-link {{.Options|active "Participant"}}" href="{{all "Participant"}}">Partecipanti</a>
<a class="nav-item nav-link {{.Options|active "Response"}}" href="{{all "Response"}}">Prove</a>
{{- end -}}
{{- if $isSchool -}}
<a class="nav-item nav-link {{.Options|active "School"}}" href="{{.Claims|modelId|show "School"}}">Scuola</a>
<a class="nav-item nav-link {{.Options|active "Participant"}}" href="{{all "Participant"}}">Partecipanti</a>
<a id="school_navbar_link" class="nav-item nav-link {{.Options|active "School"}}" href="{{.Claims|modelId|show "School"}}">Scuola</a>
<a id="participant_navbar_link" class="nav-item nav-link {{.Options|active "Participant"}}" href="{{all "Participant"}}">Partecipanti</a>
{{- end -}}
</ul>
<ul class="nav navbar-nav navbar-right">

View file

@ -130,7 +130,7 @@
{{if le (len .Data.School.Participants) 1}}
<p>
E' possibile iscrivere fino a due partecipanti alla gara (di diversa categoria).
<a href="{{create "Participant"}}" class="float-right btn btn-success btn-sm">
<a id="new_participant_subscribe" href="{{create "Participant"}}" class="float-right btn btn-success btn-sm">
<span class="fa fa-plus-circle" aria-hidden="true"></span>
Iscrivi un nuovo partecipante
</a>

View file

@ -100,7 +100,7 @@
{{if le (len .Data.Participants) 1}}
<p>
E' possibile iscrivere fino a due partecipanti alla gara (di diversa categoria).
<a href="{{create "Participant"}}" class="float-right btn btn-success btn-sm">
<a id="new_participant_subscribe" href="{{create "Participant"}}" class="float-right btn btn-success btn-sm">
<span class="fa fa-plus-circle" aria-hidden="true"></span>
Iscrivi un nuovo partecipante
</a>