@@ -33,6 +33,8 @@
3333#include "combinedfilteroption.h"
3434#include "checkoptionfilter.h"
3535#include "radiooptionfilter.h"
36+#include "ratingsfilter.h"
37+#include "ratingfilteroption.h"
3638
3739void FiltersBindingsTest::initTestCase()
3840{
@@ -73,6 +75,30 @@ void FiltersBindingsTest::createCheckOptionFilter(DeeModel *model, const std::st
7375 createFilter(model, "filter-checkoption", id, name, optionCount);
7476}
7577
78+void FiltersBindingsTest::createRatingsFilter(DeeModel *model, const std::string &id, const std::string &name)
79+{
80+ GVariant* row[8];
81+
82+ row[0] = g_variant_new_string(id.c_str());
83+ row[1] = g_variant_new_string(name.c_str());
84+ row[2] = g_variant_new_string(""); // icon hint
85+ row[3] = g_variant_new_string("filter-ratings");
86+
87+ GVariant *children[2];
88+ GVariant *key1 = g_variant_new_string("show-all-button");
89+ GVariant *key2 = g_variant_new_string("rating");
90+ children[0] = g_variant_new_dict_entry(key1, g_variant_new_variant(g_variant_new_boolean(false)));
91+ children[1] = g_variant_new_dict_entry(key2, g_variant_new_variant(g_variant_new_double(0.0f)));
92+ auto fhints = g_variant_new_array(G_VARIANT_TYPE("{sv}"), children, 2);
93+
94+ row[4] = fhints;
95+ row[5] = g_variant_new_boolean(true); // visible
96+ row[6] = g_variant_new_boolean(false); // collapsed
97+ row[7] = g_variant_new_boolean(false); // filtering
98+
99+ dee_model_append_row(model, row);
100+}
101+
76102void FiltersBindingsTest::createFilter(DeeModel *model, const std::string &renderer, const std::string &id, const std::string &name, int optionCount)
77103{
78104 GVariant* row[8];
@@ -350,4 +376,61 @@ void FiltersBindingsTest::testRadioOptionFilter()
350376 }
351377}
352378
379+void FiltersBindingsTest::testRatingsFilter()
380+{
381+ auto model = createFilterModel();
382+
383+ createRatingsFilter(model, "f1", "Filter1");
384+
385+ // create filter out of 1st row
386+ auto iter = dee_model_get_first_iter(DEE_MODEL(model));
387+ {
388+ auto core_filter = unity::dash::Filter::FilterFromIter(model, iter);
389+ QVERIFY(core_filter != nullptr);
390+ auto bind_filter = Filter::newFromUnityFilter(core_filter);
391+ auto rating_filter = dynamic_cast<RatingsFilter*>(bind_filter);
392+ QVERIFY(rating_filter != nullptr);
393+ auto options = rating_filter->options();
394+ QCOMPARE(options->rowCount(), 5);
395+
396+ RatingFilterOption* opt[5];
397+ for (int i = 0; i<5; i++) {
398+ opt[i] = options->data(options->index(i)).value<RatingFilterOption*>();
399+ }
400+
401+ QSignalSpy opt0spy(opt[0], SIGNAL(activeChanged(bool)));
402+ QSignalSpy opt4spy(opt[4], SIGNAL(activeChanged(bool)));
403+
404+ QVERIFY(qAbs(opt[0]->value() - 0.2f) <= 0.0001f);
405+ QVERIFY(qAbs(opt[1]->value() - 0.4f) <= 0.0001f);
406+ QVERIFY(qAbs(opt[2]->value() - 0.6f) <= 0.0001f);
407+ QVERIFY(qAbs(opt[3]->value() - 0.8f) <= 0.0001f);
408+ QVERIFY(qAbs(opt[4]->value() - 1.0f) <= 0.0001f);
409+
410+ // all options initially inactive
411+ for (int i=0; i<5; i++) {
412+ QCOMPARE(opt[i]->active(), false);
413+ }
414+
415+ // verify activation for all options
416+ for (int i=0; i<5; i++) {
417+ opt[i]->setActive(true);
418+ QCOMPARE(opt[i]->active(), true);
419+
420+ // verify that all other options are inactive
421+ for (int j=0; j<5; j++) {
422+ if (i != j) {
423+ QCOMPARE(opt[j]->active(), false);
424+ }
425+ }
426+ }
427+
428+ QCOMPARE(opt0spy.count(), 2);
429+ QCOMPARE(opt4spy.count(), 1);
430+
431+ opt[4]->setActive(false);
432+ QCOMPARE(opt4spy.count(), 2);
433+ }
434+}
435+
353436QTEST_MAIN(FiltersBindingsTest)