Working on regression tests

This commit is contained in:
Andrea Fazzi 2020-02-07 13:05:48 +01:00
parent 1e1dc1754a
commit e8a345bad0
5 changed files with 86 additions and 11 deletions

View file

@ -6,6 +6,7 @@ RUN mkdir -p /srv/oef
COPY oef /srv/oef/
COPY dist /srv/oef/dist
COPY templates /srv/oef/templates
COPY VERSION /srv/oef/
WORKDIR /srv/oef/

View file

@ -23,5 +23,6 @@ regression_test:
go build .
docker-compose -f docker/oef_regression_test/docker-compose.yaml down
docker-compose -f docker/oef_regression_test/docker-compose.yaml up --build -d
cd regression_test && make
all: prod

View file

@ -3,7 +3,6 @@ package regression_test
import (
"fmt"
"testing"
"time"
"github.com/remogatto/prettytest"
"github.com/tebeka/selenium"
@ -38,13 +37,6 @@ func (t *testSuite) BeforeAll() {
panic(err)
}
wd.SetImplicitWaitTimeout(time.Second * 5)
// Navigate to the simple playground interface.
if err = wd.Get("http://oef_regression_test:3000"); err != nil {
panic(err)
}
}
func (t *testSuite) AfterAll() {
@ -52,6 +44,10 @@ func (t *testSuite) AfterAll() {
}
func (t *testSuite) TestLogin() {
if err := wd.Get("http://oef_regression_test:3000"); err != nil {
panic(err)
}
err := findElement("#username").SendKeys("admin")
if err != nil {
panic(err)
@ -76,6 +72,76 @@ func (t *testSuite) TestLogin() {
}
t.Contain(expected[i], text)
}
logout()
}
func (t *testSuite) TestSchoolSubscription() {
if err := wd.Get("http://oef_regression_test:3000"); err != nil {
panic(err)
}
err := findElement("#school_subscription_link").Click()
if err != nil {
panic(err)
}
err = findElement("#password").SendKeys("subscribe")
if err != nil {
panic(err)
}
err = findElement("button").Click()
if err != nil {
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("button.btn.btn-primary").Click()
if err != nil {
panic(err)
}
expected := []string{"JUNIOR Contest", "SENIOR Contest"}
elements := findElements(".list-group a")
for i, el := range elements {
text, err := el.Text()
if err != nil {
panic(err)
}
t.Contain(expected[i], text)
}
logout()
}
func findElement(selector string) selenium.WebElement {
@ -93,3 +159,10 @@ func findElements(selector string) []selenium.WebElement {
}
return elements
}
func logout() {
err := findElement("a#logout").Click()
if err != nil {
panic(err)
}
}

View file

@ -54,9 +54,9 @@
</ul>
<ul class="nav navbar-nav navbar-right">
{{- if .Claims|isSubscriber -}}
<li><a class="nav-link" href="/logout">Esci</a></li>
<li><a id="logout" class="nav-link" href="/logout">Esci</a></li>
{{- else -}}
<li><a class="nav-link" href="/logout">Disconnetti {{.Claims|username}}</a></li>
<li><a id="logout" class="nav-link" href="/logout">Disconnetti {{.Claims|username}}</a></li>
{{- end -}}
</ul>
</div><!--/.nav-collapse -->

View file

@ -20,7 +20,7 @@
{{if .Options.Get "failed"}}
<p class="text-center text-danger">Autenticazione fallita!</p>
{{end}}
<p class="text-center">Per iscrivere la tua scuola clicca <a href="/subscribe?tpl_content=login_subscribe&tpl_layout=login">qui</a>.</p>
<p class="text-center">Per iscrivere la tua scuola clicca <a id="school_subscription_link" href="/subscribe?tpl_content=login_subscribe&tpl_layout=login">qui</a>.</p>
</div>
</div>
{{ end }}