From 31d2c693414a9381ea84ad4de8697dbac97ecdbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Thu, 12 Dec 2013 21:01:07 +0100 Subject: [PATCH] Add a test to check if tag filter is working correctly. --- test/Sauce.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/Sauce.php b/test/Sauce.php index 1b44465..7c52811 100644 --- a/test/Sauce.php +++ b/test/Sauce.php @@ -137,4 +137,44 @@ class Cops extends Sauce\Sausage\WebDriverTestCase $search = $this->byName ("query"); $this->assertTrue ($search->displayed ()); } + + public function testFilter() + { + // Click on the wrench to enable tag filtering + $this->byClassName ("icon-wrench")->click (); + + $this->byId ("html_tag_filter")->click (); + + // Go back to home screen + $this->byClassName ("icon-home")->click (); + + $driver = $this; + $title_test = function($value) use ($driver) { + $text = $driver->byXPath('//h1')->text (); + return $text == $value; + }; + + // Go on the recent page + $author = $this->byXPath ('//h2[contains(text(), "Recent")]'); + $author->click (); + + $this->spinAssert("Recent book title", $title_test, [ "RECENT ADDITIONS" ]); + + // Click on the cog to show tag filters + $cog = $this->byId ("searchImage"); + $cog->click (); + sleep (1); + // Filter on War & Military + $filter = $this->byXPath ('//li[contains(text(), "War")]'); + $filter->click (); + sleep (1); + // Only one book + $filtered = $this->elements ($this->using('css selector')->value('*[class="books"]')); + $this->assertEquals (1, count($filtered)); + $filter->click (); + sleep (1); + // 13 book + $filtered = $this->elements ($this->using('css selector')->value('*[class="books"]')); + $this->assertEquals (13, count($filtered)); + } }