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

Stop filtering out all categories that have a year in it #4902

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sivaraam
Copy link
Member

Description (required)

Fixes #4901

What changes did you make and why?

Made the conditional tighter so that it only checks for the cases needed by #750 and not more than that.

Tests performed (required)

Tested ProdDebug on Nexus 4 emulator with API level 30.

As a fix for commons-app#750, a validation was added to filter out categories
that were of form "... taken on ... 1990" or "... needing ... 2005".
The conditional added for the fix was a bit loose than it should be
as a result of which it filtered out all categories that had a year
in its name. This is incorrect.

Fix this by tigheting the conditional so that only categories that
have a year, is not the present or previous year AND (contains
"taken on" OR "needing") is filtered out.

While doing so, turn an implicit precedence into an explicit one.
We are in the 2020s now. So, adjust fix for issue 1029 to include
2020s too.
@codecov
Copy link

codecov bot commented Mar 19, 2022

Codecov Report

Merging #4902 (64a54ec) into master (1078c70) will decrease coverage by 0.00%.
The diff coverage is 0.00%.

❗ Current head 64a54ec differs from pull request most recent head d89b936. Consider uploading reports for the commit d89b936 to get more accurate results

@@             Coverage Diff              @@
##             master    #4902      +/-   ##
============================================
- Coverage     50.59%   50.58%   -0.01%     
- Complexity     2228     2229       +1     
============================================
  Files           338      338              
  Lines         15599    15599              
  Branches       1370     1370              
============================================
- Hits           7892     7891       -1     
+ Misses         7114     7112       -2     
- Partials        593      596       +3     
Impacted Files Coverage Δ
...va/fr/free/nrw/commons/category/CategoriesModel.kt 59.32% <0.00%> (+1.69%) ⬆️
...fr/free/nrw/commons/review/ReviewPagerAdapter.java 30.76% <0.00%> (-38.47%) ⬇️
...r/free/nrw/commons/explore/media/MediaConverter.kt 71.11% <0.00%> (-17.78%) ⬇️
...a/fr/free/nrw/commons/review/ReviewController.java 79.06% <0.00%> (-8.14%) ⬇️
.../java/fr/free/nrw/commons/review/ReviewHelper.java 77.77% <0.00%> (-5.56%) ⬇️
...ns/upload/categories/UploadCategoriesFragment.java 88.40% <0.00%> (+1.44%) ⬆️
...w/commons/upload/categories/BaseDelegateAdapter.kt 47.05% <0.00%> (+11.76%) ⬆️
.../nrw/commons/category/CategoryContentProvider.java 26.78% <0.00%> (+14.28%) ⬆️
...a/fr/free/nrw/commons/OkHttpConnectionFactory.java 72.72% <0.00%> (+20.45%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1078c70...d89b936. Read the comment docs.

Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

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

I think this feature would greatly benefit from a unit test :-)

  • Photographs taken on 2015-11-08 -> Hide
  • Amavenita (ship, 2014) -> Do not hide

@sivaraam
Copy link
Member Author

I think this feature would greatly benefit from a unit test :-)

Good point. I'll look into adding the tests. I must mention that I'm not so used to adding unit tests for Android. So, it might take me some time. I'll update here once I'm done with adding the required tests.

@sivaraam
Copy link
Member Author

Just wanted to update here regarding the test. I was trying to cook up a test for the mentioned case but somehow the test keeps failing. I think I'll need to look more deeply to write the test properly. Meanwhile, if anyone has any good pointers on what I'm getting wrong, do let me know.

@devarsh-mavani-19
Copy link
Contributor

devarsh-mavani-19 commented Mar 20, 2022

Just wanted to update here regarding the test. I was trying to cook up a test for the mentioned case but somehow the test keeps failing. I think I'll need to look more deeply to write the test properly. Meanwhile, if anyone has any good pointers on what I'm getting wrong, do let me know.

Hey I think the checkIrrelevantCategoryIsFilteredOut should be inside categoriespresentertest class.
Please check the below code I think it tests the functionality of filtering out well

        doReturn(Observable.just<List<CategoryItem>>(
            listOf(CategoryItem("taken on 2014", "Desc", "Thumb", false)
                ,CategoryItem("test 2014", "Desc", "Thumb", false)
                ,CategoryItem("japan in 660s", "Desc", "Thumb", false))))
            .`when`(repository).searchAll(ArgumentMatchers.anyString()
                , ArgumentMatchers.any(), ArgumentMatchers.any())

        `when`(repository.containsYear(anyString())).thenCallRealMethod()

        val categoriesModel = Mockito.mock(CategoriesModel::class.java)
        `when`(categoriesModel.containsYear(anyString())).thenCallRealMethod()
        Whitebox.setInternalState(repository, "categoriesModel", categoriesModel)

        repository.searchAll(ArgumentMatchers.anyString()
            , ArgumentMatchers.any(), ArgumentMatchers.any())
            .map { it.filterNot { categoryItem -> repository.containsYear(categoryItem.name) } }
            .test()
            .assertValue(listOf(CategoryItem("test 2014", "Desc", "Thumb", false)))

@shankarpriyank
Copy link
Contributor

I might be totally wrong, but I think we can test the functionality using simpler unit tests like these

  @Test
    fun testCheckIrrelevantCategoryIsFilteredOut() {
        assertFalse(containsYear("Category:Media needing categories as of 16 June 2017"))
    }

@Test
    fun testCheckNotAllCategoriesWithDateAreFilteredOut() {
        assertTrue(containsYear("Category:Amavenita (ship, 2014)"))
    }

@mnalis
Copy link
Contributor

mnalis commented Aug 1, 2024

@sivaraam as mentioned in #5749 (comment) as other prerequisites have been merged now; perhaps this PR can now be rebased to latest master and updated to allow years (except blacklisted ones)?

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.

[Bug]: Category not found
5 participants