Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve FolderStatusModel tests #7855

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

ArtiomKhachaturian
Copy link

@ArtiomKhachaturian ArtiomKhachaturian commented Feb 13, 2025

The task depends on #7842 and should be possible to tackle without deeper knowledge of the desktop client code base. #7842 will give you the code skeleton.

The task would be to remove the QSKIP macro, fix the code to not fail and if time allows improve the coverage and see how far you get there within a timeframe of 4 hours.
Any improvement to that coverage would be a win.

Copy link
Collaborator

@mgallien mgallien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see the inline comments

@@ -100,6 +100,7 @@ void FolderStatusModel::setAccountState(const AccountState *accountState)
}

endResetModel();
// TODO: maybe we need to analyze the previous state of _dirty before signal emitting?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would something needed to do here or not ?
I would prefer not to have comments with TODO that will still be there in 10 years (I am pretty sure we have such comments already)

Copy link
Author

@ArtiomKhachaturian ArtiomKhachaturian Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my comment below

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the added value of this comment ?
we do not really want to clutter the code base with comments that will have to be maintained unless they bring value now and likely in the future

Comment on lines 399 to 401
// TODO: think about that maybe better to introduce a separate setter for [_dirty] var with emitting of signal if changed
// TODO: maybe we need to analyze the previous state of _dirty before signal emitting?
_dirty = true;;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds like a nice idea
is there a reason not to do it ?

Copy link
Author

@ArtiomKhachaturian ArtiomKhachaturian Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it is risky changes on my sight, because I don't know the logic of signal consumers, maybe their logic depends from this signal frequency, but ok, will fixed with introducing of setDirty method

Copy link
Author

@ArtiomKhachaturian ArtiomKhachaturian Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consumer of this signal is here:

void AccountSettings::refreshSelectiveSyncStatus()

connection declared here:
connect(_model, &FolderStatusModel::dirtyChanged, this, &AccountSettings::refreshSelectiveSyncStatus);

Right approach for emitting of signal is very simple:

void FolderStatusModel::setDirty(bool dirty)
{
	if (_dirty != dirty) {
            _dirty = dirty;
            emit dirtyChanged();
	}
}

but as I mentioned I'm not sure that changes in frequency of the emitted signal will not affect the consumer's logic for the worse

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is maybe something I do not get.
is this change needed to get the automated tests to pass ?
if it is needed by the automated tests then they should specify/document the expected behavior
if not then why changing it ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added question
why did you decided not to change it after review but changing it before review ?

test/testfolderstatusmodel.cpp Outdated Show resolved Hide resolved
src/gui/folderstatusmodel.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@claucambra claucambra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment on lines -117 to +118
if (!_accountState) {
if (!_accountState || !index.isValid()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to use checkIndex

https://doc.qt.io/qt-6/qabstractitemmodel.html#checkIndex

Copy link
Author

@ArtiomKhachaturian ArtiomKhachaturian Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe, but I didn't anything about this method, but why is it better? I don't see the advantages in comparing with simple QModelIndex::isValid, according to QT6 sources https://codebrowser.dev/qt6/qtbase/src/corelib/itemmodels/qabstractitemmodel.cpp.html#3590 this method is convenient for complex verification of model index with possible logging, but it's not our case, I'm sure that QModelIndex::isValid is enough for fast index validation

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @claucambra is referring to the recommended way to test indexes within the model classes from Qt
I am convinced that checkIndex was added for some good reasons

src/gui/folderstatusmodel.cpp Outdated Show resolved Hide resolved
src/gui/folderstatusmodel.cpp Outdated Show resolved Hide resolved
return FetchLabel;
} else {
return SubFolder;
if (index.isValid()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use checkIndex

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think checking if it is valid and doing an early return instead would be cleaner

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disagree, sorry, see my comment above

src/gui/folderstatusmodel.cpp Outdated Show resolved Hide resolved
test/testfolderstatusmodel.cpp Outdated Show resolved Hide resolved
test/testfolderstatusmodel.cpp Outdated Show resolved Hide resolved
test/testfolderstatusmodel.cpp Outdated Show resolved Hide resolved
test/testfolderstatusmodel.cpp Outdated Show resolved Hide resolved
test/testfolderstatusmodel.cpp Outdated Show resolved Hide resolved
@mgallien mgallien changed the title Code challenge/artiom khachaturian Improve FolderStatusModel tests Feb 14, 2025
Artiom Khachaturian and others added 12 commits February 14, 2025 09:56
Co-authored-by: Claudio Cambra <[email protected]>
Signed-off-by: Artiom Khachaturian <[email protected]>
Co-authored-by: Claudio Cambra <[email protected]>
Signed-off-by: Artiom Khachaturian <[email protected]>
Co-authored-by: Claudio Cambra <[email protected]>
Signed-off-by: Artiom Khachaturian <[email protected]>
Co-authored-by: Claudio Cambra <[email protected]>
Signed-off-by: Artiom Khachaturian <[email protected]>
Co-authored-by: Claudio Cambra <[email protected]>
Signed-off-by: Artiom Khachaturian <[email protected]>
Co-authored-by: Claudio Cambra <[email protected]>
Signed-off-by: Artiom Khachaturian <[email protected]>
Co-authored-by: Claudio Cambra <[email protected]>
Signed-off-by: Artiom Khachaturian <[email protected]>
Co-authored-by: Claudio Cambra <[email protected]>
Signed-off-by: Artiom Khachaturian <[email protected]>
@@ -100,6 +100,7 @@ void FolderStatusModel::setAccountState(const AccountState *accountState)
}

endResetModel();
// TODO: maybe we need to analyze the previous state of _dirty before signal emitting?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the added value of this comment ?
we do not really want to clutter the code base with comments that will have to be maintained unless they bring value now and likely in the future

Artiom Khachaturian added 4 commits February 14, 2025 13:10
…mKhachaturian/next_cloud_desktop into code_challenge/artiom_khachaturian
…dices verification (when expected that index should be valid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants