2 Copyright (c) 2014-2016 Montel Laurent <montel@kde.org>
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include "storageservicenavigationbuttontest.h"
22 #include "../storageservicenavigationbuttons.h"
25 #include <qtestmouse.h>
26 #include <qtestkeyboard.h>
29 Q_DECLARE_METATYPE(InformationUrl
)
30 StorageServiceNavigationButtonTest::StorageServiceNavigationButtonTest()
32 qRegisterMetaType
<InformationUrl
>();
35 void StorageServiceNavigationButtonTest::shouldHaveDefaultValuesOnCreation()
37 StorageServiceNavigationButtons buttons
;
38 QVERIFY(buttons
.goBack());
39 QVERIFY(buttons
.goForward());
40 QVERIFY(buttons
.home());
42 QCOMPARE(buttons
.goBack()->isEnabled(), false);
43 QCOMPARE(buttons
.goForward()->isEnabled(), false);
44 QCOMPARE(buttons
.home()->isEnabled(), true);
46 QCOMPARE(buttons
.backUrls().isEmpty(), true);
47 QCOMPARE(buttons
.forwardUrls().isEmpty(), true);
50 void StorageServiceNavigationButtonTest::shouldEnabledBackButtonWhenWeListUrlIsNotEmpty()
52 StorageServiceNavigationButtons buttons
;
53 QList
<InformationUrl
> lst
;
56 buttons
.setBackUrls(lst
);
57 QCOMPARE(buttons
.backUrls().isEmpty(), false);
58 QCOMPARE(buttons
.goBack()->isEnabled(), true);
60 buttons
.setForwardUrls(lst
);
61 QCOMPARE(buttons
.forwardUrls().isEmpty(), false);
62 QCOMPARE(buttons
.goForward()->isEnabled(), true);
65 void StorageServiceNavigationButtonTest::shouldDisableButtonWhenClearList()
67 StorageServiceNavigationButtons buttons
;
68 QList
<InformationUrl
> lst
;
71 buttons
.setBackUrls(lst
);
72 QCOMPARE(buttons
.goBack()->isEnabled(), true);
74 buttons
.setForwardUrls(lst
);
75 QCOMPARE(buttons
.goForward()->isEnabled(), true);
77 QCOMPARE(buttons
.goBack()->isEnabled(), false);
78 QCOMPARE(buttons
.goForward()->isEnabled(), false);
81 void StorageServiceNavigationButtonTest::shouldEmitSignalWhenClickOnButtonAndListNotEmpty()
83 StorageServiceNavigationButtons buttons
;
84 QList
<InformationUrl
> lst
;
87 buttons
.setBackUrls(lst
);
88 QSignalSpy
spy(&buttons
, SIGNAL(changeUrl(InformationUrl
)));
89 buttons
.goBack()->trigger();
90 QCOMPARE(spy
.count(), 1);
94 QSignalSpy
spy2(&buttons
, SIGNAL(changeUrl(InformationUrl
)));
95 buttons
.goForward()->trigger();
96 QCOMPARE(spy2
.count(), 0);
97 QSignalSpy
spy3(&buttons
, SIGNAL(changeUrl(InformationUrl
)));
98 buttons
.goBack()->trigger();
99 QCOMPARE(spy3
.count(), 0);
101 buttons
.setForwardUrls(lst
);
102 QSignalSpy
spy4(&buttons
, SIGNAL(changeUrl(InformationUrl
)));
103 buttons
.goForward()->trigger();
104 QCOMPARE(spy4
.count(), 1);
107 void StorageServiceNavigationButtonTest::shouldEmitSignalWhenClickOnHome()
109 StorageServiceNavigationButtons buttons
;
110 QSignalSpy
spy(&buttons
, SIGNAL(goHome()));
111 buttons
.home()->trigger();
112 QCOMPARE(spy
.count(), 1);
115 void StorageServiceNavigationButtonTest::shouldEnabledBackButtonWhenAndInfoAndItValids()
117 StorageServiceNavigationButtons buttons
;
118 QCOMPARE(buttons
.backUrls().isEmpty(), true);
119 QCOMPARE(buttons
.forwardUrls().isEmpty(), true);
121 InformationUrl urlInvalid
;
122 buttons
.addBackUrl(urlInvalid
);
123 buttons
.addForwadUrl(urlInvalid
);
124 QCOMPARE(buttons
.backUrls().isEmpty(), true);
125 QCOMPARE(buttons
.forwardUrls().isEmpty(), true);
127 InformationUrl urlValid
;
128 urlValid
.currentUrl
= QStringLiteral("Foo");
129 urlValid
.parentUrl
= QStringLiteral("Foo1");
130 buttons
.addBackUrl(urlValid
);
131 buttons
.addForwadUrl(urlValid
);
132 QCOMPARE(buttons
.backUrls().isEmpty(), false);
133 QCOMPARE(buttons
.forwardUrls().isEmpty(), false);
136 void StorageServiceNavigationButtonTest::shouldEnabledBackButtonWhenAddNewInfo()
138 StorageServiceNavigationButtons buttons
;
139 QCOMPARE(buttons
.backUrls().isEmpty(), true);
140 InformationUrl urlValid
;
141 urlValid
.currentUrl
= QStringLiteral("Foo");
142 urlValid
.parentUrl
= QStringLiteral("Foo1");
143 buttons
.addNewUrl(urlValid
);
144 QCOMPARE(buttons
.backUrls().isEmpty(), false);
147 void StorageServiceNavigationButtonTest::shouldIncreaseNumberOfElement()
149 StorageServiceNavigationButtons buttons
;
150 InformationUrl urlValid
;
151 urlValid
.currentUrl
= QStringLiteral("Foo");
152 urlValid
.parentUrl
= QStringLiteral("Foo1");
153 buttons
.addNewUrl(urlValid
);
154 buttons
.addNewUrl(urlValid
);
155 buttons
.addNewUrl(urlValid
);
156 buttons
.addNewUrl(urlValid
);
157 buttons
.addNewUrl(urlValid
);
158 buttons
.addNewUrl(urlValid
);
159 QCOMPARE(buttons
.backUrls().count(), 6);
162 void StorageServiceNavigationButtonTest::shouldMoveInfoInGoForwardWhenClickOnGoBack()
164 StorageServiceNavigationButtons buttons
;
165 InformationUrl urlValid
;
166 urlValid
.currentUrl
= QStringLiteral("Foo");
167 urlValid
.parentUrl
= QStringLiteral("Foo1");
168 buttons
.addNewUrl(urlValid
);
169 QCOMPARE(buttons
.backUrls().count(), 1);
170 buttons
.goBack()->trigger();
171 QCOMPARE(buttons
.backUrls().count(), 0);
172 QCOMPARE(buttons
.forwardUrls().count(), 1);
174 //Compare that button goback is disable, goforward is enable after that
175 QCOMPARE(buttons
.goBack()->isEnabled(), false);
176 QCOMPARE(buttons
.goForward()->isEnabled(), true);
179 void StorageServiceNavigationButtonTest::shouldMoveInfoInGoBackWhenClickOnGoForward()
181 StorageServiceNavigationButtons buttons
;
182 InformationUrl urlValid
;
183 urlValid
.currentUrl
= QStringLiteral("Foo");
184 urlValid
.parentUrl
= QStringLiteral("Foo1");
185 buttons
.addNewUrl(urlValid
);
186 buttons
.goBack()->trigger();
188 buttons
.goForward()->trigger();
190 QCOMPARE(buttons
.backUrls().count(), 1);
191 QCOMPARE(buttons
.forwardUrls().count(), 0);
193 //Compare that button goback is disable, goforward is enable after that
194 QCOMPARE(buttons
.goBack()->isEnabled(), true);
195 QCOMPARE(buttons
.goForward()->isEnabled(), false);
198 void StorageServiceNavigationButtonTest::shouldMoveInfoToTopWhenClickOnBack()
200 StorageServiceNavigationButtons buttons
;
201 InformationUrl urlValid
;
203 urlValid
.currentUrl
= QStringLiteral("Foo1");
204 urlValid
.parentUrl
= QStringLiteral("Foo1");
205 buttons
.addNewUrl(urlValid
);
207 urlValid
.currentUrl
= QStringLiteral("Foo2");
208 urlValid
.parentUrl
= QStringLiteral("Foo2");
209 buttons
.addNewUrl(urlValid
);
211 urlValid
.currentUrl
= QStringLiteral("Foo3");
212 urlValid
.parentUrl
= QStringLiteral("Foo3");
213 buttons
.addNewUrl(urlValid
);
215 buttons
.goBack()->trigger();
216 InformationUrl forwardUrl
= buttons
.forwardUrls().at(0);
217 QCOMPARE(forwardUrl
.currentUrl
, QStringLiteral("Foo3"));
219 buttons
.goBack()->trigger();
220 forwardUrl
= buttons
.forwardUrls().at(0);
221 QCOMPARE(forwardUrl
.currentUrl
, QStringLiteral("Foo2"));
223 buttons
.goBack()->trigger();
224 forwardUrl
= buttons
.forwardUrls().at(0);
225 QCOMPARE(forwardUrl
.currentUrl
, QStringLiteral("Foo1"));
229 void StorageServiceNavigationButtonTest::shouldMoveInfoToTopWhenClickOnBackAndAfterForward()
231 StorageServiceNavigationButtons buttons
;
232 InformationUrl urlValid
;
234 urlValid
.currentUrl
= QStringLiteral("Foo1");
235 urlValid
.parentUrl
= QStringLiteral("Foo1");
236 buttons
.addNewUrl(urlValid
);
238 urlValid
.currentUrl
= QStringLiteral("Foo2");
239 urlValid
.parentUrl
= QStringLiteral("Foo2");
240 buttons
.addNewUrl(urlValid
);
242 urlValid
.currentUrl
= QStringLiteral("Foo3");
243 urlValid
.parentUrl
= QStringLiteral("Foo3");
244 buttons
.addNewUrl(urlValid
);
246 buttons
.goBack()->trigger();
247 InformationUrl forwardUrl
= buttons
.forwardUrls().at(0);
248 QCOMPARE(forwardUrl
.currentUrl
, QStringLiteral("Foo3"));
250 buttons
.goForward()->trigger();
251 forwardUrl
= buttons
.backUrls().at(0);
252 QCOMPARE(forwardUrl
.currentUrl
, QStringLiteral("Foo3"));
255 QTEST_MAIN(StorageServiceNavigationButtonTest
)