Example #1
0
// RegionsHome renders regions home page.
//
//
//		Method           GET
//
//		Route            /jobs/regions
//
//		Restrictions     None
//
// 		Template         base/regions.html
//
func RegionsHome(ctx *echo.Context) error {
	regs, err := query.GetAllRegions()
	if err != nil {
		utils.SetData(ctx, "Message", tmpl.NotFoundMessage)
		return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, utils.GetData(ctx))
	}
	utils.SetData(ctx, settings.RegionsListKey, regs)
	return ctx.Render(http.StatusOK, tmpl.BaseRegionsTpl, utils.GetData(ctx))
}
Example #2
0
func TestJobsRegionsByShortName(t *testing.T) {
	regs, err := query.GetAllRegions()
	if err != nil {
		t.Errorf("retriving regions %v", err)
	}
	for _, v := range regs {
		regHome := fmt.Sprintf("%s/jobs/regions/%s", ts.URL, v.Short)
		b, err := com.HttpGetBytes(client, regHome, nil)
		if err != nil {
			t.Errorf("getting regions home page %v", err)
		}
		doc, err := goquery.NewDocumentFromReader(strings.NewReader(string(b)))
		if err != nil {
			t.Errorf("loading document %v", err)
		}
		s := doc.Find(".job-item")
		if s.Length() != 4 {
			t.Errorf("expected 4 got %d", s.Length())
		}
	}
}
Example #3
0
func TestHome(t *testing.T) {

	// Migrate, this is going to be used by all subsequent tests.
	for _, v := range regionsSample {
		q := db.Conn.FirstOrCreate(&models.Region{}, models.Region{Name: v.name, Short: v.short})
		if q.Error != nil {
			t.Errorf("migrating regios %v", q.Error)
		}
	}
	regs, err := query.GetAllRegions()
	if err != nil {
		t.Errorf("retrieving regions %v", err)
	}
	for _, v := range regs {
		for _, job := range JobsSample {
			j := &models.Job{}
			j.Title = job.title
			j.Description = job.desc
			j.Region = *v
			q := db.Conn.Create(j)
			if q.Error != nil {
				t.Errorf("creating jobs %v", q.Error)
			}
		}
	}

	b, err := com.HttpGetBytes(client, ts.URL, nil)
	if err != nil {
		t.Errorf("getting home page %v", err)
	}

	// Yes a home page should contain zedlist tittle
	if !bytes.Contains(b, []byte("<title>zedlist</title>")) {
		t.Errorf("expected home page got %s", b)
	}
}