Skip to content

Commit

Permalink
added 2 more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jakopako committed Dec 4, 2022
1 parent 501f88e commit fc6c493
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion automate/config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package automate

import "testing"
import (
"testing"

"github.com/jakopako/goskyr/scraper"
)

func TestPathToSelector(t *testing.T) {
path := []string{"body.home", "div.wrapper.schedule", "div.event-list", "a.item"}
Expand Down Expand Up @@ -43,3 +47,45 @@ func TestNotNodesEqual(t *testing.T) {
}
}
}

func TestFilter(t *testing.T) {
l := []*locationProps{
{
loc: scraper.ElementLocation{},
count: 4,
},
{
loc: scraper.ElementLocation{},
count: 8,
},
}
nl := filter(l, 8, false)
if len(nl) != 1 {
t.Fatalf("expected only 1 element to remain after filtering but got %+v", nl)
}
if nl[0].count != 8 {
t.Fatal("wrong element filtered.")
}
}

func TestNoStaticFieldsFilter(t *testing.T) {
l := []*locationProps{
{
loc: scraper.ElementLocation{},
count: 4,
examples: []string{"a", "a"},
},
{
loc: scraper.ElementLocation{},
count: 8,
examples: []string{"a", "b"},
},
}
nl := filter(l, 4, true)
if len(nl) != 1 {
t.Fatalf("expected only 1 element to remain after filtering but got %+v", nl)
}
if nl[0].count != 8 { // the remaining element should have count 8
t.Fatal("wrong element filtered.")
}
}

0 comments on commit fc6c493

Please sign in to comment.