spec/lib/under_os/page/matcher_spec.rb in under-os-1.1.0 vs spec/lib/under_os/page/matcher_spec.rb in under-os-1.2.0

- old
+ new

@@ -48,10 +48,14 @@ end it "should not add score if the css-rule is wrong" do score_for(@view, 'view.some-class').should == 0 end + + it "should handle the * as the tag name" do + score_for(@view, '*').should == 1 + end end describe 'IDs matching' do it "should add score for IDs matches" do @view.id = 'my-id' @@ -105,11 +109,94 @@ @view.className = 'my-class' score_for(@view, '#another-id.my-class').should == 0 end end - describe 'multiple matches' do + describe "attribute matchers" do + before do + @view.id = "my-view" + end + + def score_for(view, css_rule) + UnderOs::Page::StylesMatcher.new(css_rule).score_for(view) + end + + describe "with the '=' operator" do + it "scores when the value matches exactly" do + score_for(@view, '[id="my-view"]').should == 1 + end + + it "doesn't count when the value does not match" do + score_for(@view, "[id='my']").should == 0 + end + end + + describe "with the '*=' operator" do + it "scores when the attribute includes the value" do + score_for(@view, '[id*=vie]').should == 1 + end + + it "doesn't count when the value doesn't match attribute" do + score_for(@view, '[id*=mismatch]').should == 0 + end + end + + describe "with the ^= operator" do + it "scores when the attribute starts with the value" do + score_for(@view, '[id^=my]').should == 1 + end + + it "doesn't count when the attribute doesn't start with the value" do + score_for(@view, '[id^=view]').should == 0 + end + end + + describe "with the $= operator" do + it "scores when the attribute ends with the value" do + score_for(@view, '[id$=view]').should == 1 + end + + it "doesn't count when the attribute doesn't ends with the value" do + score_for(@view, '[id$=my]').should == 0 + end + end + + describe "with the ~= operator" do + before { @view.id = "one two three" } + + it "scores when the value is a token from the attribute" do + score_for(@view, '[id~=one]').should == 1 + score_for(@view, '[id~=two]').should == 1 + score_for(@view, '[id~=three]').should == 1 + end + + it "doesn't trigger on completely different strings" do + score_for(@view, '[id~=four]').should == 0 + end + + it "doesn't trigger on partial substrings" do + score_for(@view, '[id~=tw]').should == 0 + end + end + + describe "with the |= operator" do + it "scores when value is a dashed token of the attribute" do + score_for(@view, '[id|=my]').should == 1 + score_for(@view, '[id|=view]').should == 1 + end + + it "doesn't trigger on completely different values" do + score_for(@view, '[id|=mismatch]').should == 0 + end + + it "doesn't trigger on partial matches" do + score_for(@view, '[id|=vie]').should == 0 + end + end + end + + describe 'multiple nested matches' do it "should count in all the matches" do @view.id = 'my-id' @view.className = 'class1 class2' score_for(@view, 'view#my-id.class1.class2').should == 4 end @@ -146,9 +233,28 @@ score_for(@view, '.v1 .v3 #my-view').should == 3 end it "should return 0 if no matching parent found" do score_for(@view, '.non-existing #my-view').should == 0 + end + end + + describe "multiple different matchers" do + before do + @view.id = 'my-view' + @view.className = 'classy' + end + + it "gets score out of multiple matchers if one of them is matching" do + score_for(@view, "view, input, form").should == 1 + end + + it "return 0 if none of the matchers are matching" do + score_for(@view, "input,select").should == 0 + end + + it "gets the max score if there are multiple matches" do + score_for(@view, "view,.classy,view#my-view").should == 2 end end end end