Add test cases for rocketchataccountsettings
ClosedPublic

Authored by velurimithun on Dec 18 2017, 6:51 AM.

Details

Summary

Add defaultValues test case

Add Assign/get test cases for all the methods

Test Plan

Use QsignalSpy to test signals

Diff Detail

Repository
R865 Ruqola
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
velurimithun requested review of this revision.Dec 18 2017, 6:51 AM
velurimithun created this revision.
mlaurent requested changes to this revision.Dec 18 2017, 7:56 AM

+ close other request as you changed it

autotests/rocketchataccountsettingstest.cpp
41

Verify that it doesn't emit signal when you set same serverurl

50

Verify it as we don't emit signal when we assign same username

73

Verify that password/authtoken/userId is cleared after that.

> you must verify before that you have a password/authtoken/userId otherwise you can't verify it :)

> assign values before to call logout.

105

coding style " = "

151

it's not true as serverUrl is not empty :)

This revision now requires changes to proceed.Dec 18 2017, 7:56 AM
  • Create new test for logout

update the code according to comments in D9390

velurimithun marked 4 inline comments as done.Dec 18 2017, 9:00 AM
velurimithun added inline comments.
autotests/rocketchataccountsettingstest.cpp
73

Currently, loginstatusChanged() signal is emitted nowhere in rocketchataccountsettings

  • New test is created to check logout().
151

I think After calling loadsettings() on a RocketChatAccountSetting object, serverUrl is set to (demo.rocket.chat) and before calling it has empty sting....!

mlaurent requested changes to this revision.Dec 18 2017, 10:51 AM
mlaurent added inline comments.
autotests/rocketchataccountsettingstest.cpp
43

same as new test.
You don't test after applying that applying same name doesn't emit signal

55

you verify that when it's empty, signal is not emitting (ok)
but you don't verify that when you assign 'QStringLiteral("Donal Knuth")' after line 58 it's not emitting new signal.

This revision now requires changes to proceed.Dec 18 2017, 10:51 AM
velurimithun marked an inline comment as done.
  • Split test cases for username and serverUrl

write different methods for shouldEmit and shouldNotEmit
to check signals in setUsername and setServerUrl methods

velurimithun added inline comments.Dec 18 2017, 2:14 PM
autotests/rocketchataccountsettingstest.cpp
43

tests are written in different methods.

55

Tests are written in different methods.

mlaurent added inline comments.Dec 18 2017, 3:40 PM
autotests/rocketchataccountsettingstest.cpp
61

There is still the same problem.
As I want that you test is:
const QString username = QStringLiteral("foo");
sampleChat->setUserName(username);
QCOMPARE(spyname.count(), 1); => normal it emits signal

and after:
sampleChat->setUserName(username);
QCOMPARE(spyname.count(), 1); => normal it doesn't emit new signal
but we are sure that username is not empty.
At the moment you don't assign value to username => it will compare with empty string it's a special case.
I want to compare with real case

same for other method.

But it's the last changes to do :)

92

Why it's empty ? not finish yet ?
or you mustn't test it
if you mustn't test it better to remove it.

184

still not for serverurl => comment is not correct (and it will not correct as by default we will fallback to demo...)

velurimithun marked an inline comment as done.
  • Add empty string case in setServerUrl, SetUsername

Test setServerUrl and setUsername methods by passing empty
strings to them.

They should emit signals

velurimithun marked an inline comment as done.Dec 18 2017, 4:49 PM
velurimithun added inline comments.
autotests/rocketchataccountsettingstest.cpp
92

that signal( LoginStatusChanged() ) is triggered nowhere in the rocketchataccountsettings.cpp file!!

I thought that you will do some modifications in the rocketchataccountsettings.cpp file and then we can add tests for that..

If you say there is no need to test it, I will remove it.

184

Comment removed!!

209

Here it is empty that means before we call loadSetting(), chat.serverUrl() is returning an empty string. That's why I wrote by default it should return empty.

Anyways I removed the comment, It should not create confusion in future:)

mlaurent added inline comments.Dec 18 2017, 6:59 PM
autotests/rocketchataccountsettingstest.cpp
82

ok with empty but why you don't want to test twice same no empty username and look at that we don't emit twice the signal ?

  • Signal should not be emitted when same url,name is passed

Test whether it is emitting or not when we pass same url, name

Actually this is verified in shouldNotEmitSignal method!

velurimithun marked an inline comment as done.Dec 19 2017, 2:59 AM
velurimithun added inline comments.
autotests/rocketchataccountsettingstest.cpp
51

Here one signal should be emitted, Since we are assigining a new Url("bla bla").

This emission of the signal will append one item to the list(SpyURL) => count is 1.

55

Here one more signal is emitted when we assign a new Url(emptyString).

This emission of the signal will append one more item to the same the list(SpyURL) =>total count is = prevCount + 1 that is 2.

58

Here signal is not emitted when we assign same Url as prv.(emptyString).

There no emission and item will not be appended to lis(SpyURL) => total count is = prevCount + 0 that is 2.

mlaurent added inline comments.Dec 19 2017, 5:55 AM
autotests/rocketchataccountsettingstest.cpp
58

ok I know that you use 2 empty string
but why you don't change it as non empty serverUrl ? it's more realistic value no ?
by default we use no empty serverurl :)

88

same here why emptystring and not 'no empty string' ?

in some code we can evaluate empty string as special case

it's for that that I ask you to use no empty string.

> you can use same code with no empty string :)

velurimithun added inline comments.Dec 19 2017, 6:06 AM
autotests/rocketchataccountsettingstest.cpp
40

Here in this method(shouldNotEmitSignalWhenNewServerUrlIsSamaAsOld() ),

is it checked with non-empty string!!, and that is why I didn't check is that method:)

same idea is implemented for userNameChanged also...!

velurimithun marked 2 inline comments as done.Dec 19 2017, 6:06 AM
mlaurent added inline comments.Dec 19 2017, 7:03 AM
autotests/rocketchataccountsettingstest.cpp
40

ok for here as default servername is not empty by default ok.

but I don't see it in:

void RocketChatAccountSettingsTest::shouldEmitSignalWhenUserNameChanged()
{

RocketChatAccountSettings *SampleChat = new RocketChatAccountSettings;

QSignalSpy SpyName(SampleChat, &RocketChatAccountSettings::userNameChanged);
SampleChat->setUserName(QStringLiteral("Donald Knuth"));
QCOMPARE(SpyName.count(), 1);

QString emptyString;
SampleChat->setUserName(emptyString);
QCOMPARE(SpyName.count(), 2);

SampleChat->setServerUrl(emptyString);
QCOMPARE(SpyName.count(), 2);

}

where do you test "value is not empty here ?
otherwise its not in this method
but here you test:

string not empty =>emit signal

after that you use emptyString

> no empty -> empty => signal

but after that you test 'empty -> empty' ok no signal

but I ask you 'non empty -> no empty' (with same value)

it's still not the case here no ?
otherwise give me the good method perhaps I didn't see the good method.

mlaurent added inline comments.Dec 19 2017, 7:04 AM
autotests/rocketchataccountsettingstest.cpp
87

it's serverUrl here not setUserName

velurimithun marked an inline comment as done.
  • Modify the shouldNotEmit methods

modify shouldNotEmit method and test it with non-empty strings..!

velurimithun marked an inline comment as done.Dec 19 2017, 7:35 AM
velurimithun added inline comments.
autotests/rocketchataccountsettingstest.cpp
40

I modified the code in shouldNotEmit method.

87

Sorry, It's my mistake !!

I corrected it :)

mlaurent accepted this revision.Dec 19 2017, 7:56 AM

Yep now it's ok :)
Cooll.
Thanks

This revision is now accepted and ready to land.Dec 19 2017, 7:56 AM
velurimithun marked an inline comment as done.Dec 19 2017, 8:10 AM

Thank you very much :)

Are you able to commit or I will do for you ?

Still, I don't know how to commit, better you only commit!!

Thanks.

ok I will do after lunch
thanks

This revision was automatically updated to reflect the committed changes.