diff --git a/WordPress/Classes/ViewRelated/Post/PostListFilter.swift b/WordPress/Classes/ViewRelated/Post/PostListFilter.swift index fe1b6d7fbee7..cd45f344adc1 100644 --- a/WordPress/Classes/ViewRelated/Post/PostListFilter.swift +++ b/WordPress/Classes/ViewRelated/Post/PostListFilter.swift @@ -85,7 +85,7 @@ import Foundation let statuses: [BasePost.Status] = [.publish, .publishPrivate] let predicate: NSPredicate - if FeatureFlag.syncPublishing.enabled { + if !FeatureFlag.syncPublishing.enabled { let query = // existing published/private posts "(statusAfterSync = status AND status IN (%@))" @@ -128,7 +128,7 @@ import Foundation let statusesForLocalDrafts: [BasePost.Status] = [.draft, .pending, .publish, .publishPrivate, .scheduled] let predicate: NSPredicate - if FeatureFlag.syncPublishing.enabled { + if !FeatureFlag.syncPublishing.enabled { let query = // Existing draft/pending posts "(statusAfterSync = status AND status IN (%@))" @@ -170,7 +170,7 @@ import Foundation let statuses: [BasePost.Status] = [.scheduled] let predicate: NSPredicate - if FeatureFlag.syncPublishing.enabled { + if !FeatureFlag.syncPublishing.enabled { let query = // existing scheduled posts "(statusAfterSync = status AND status IN (%@))" @@ -213,7 +213,7 @@ import Foundation let statuses: [BasePost.Status] = [.draft, .pending, .publish, .publishPrivate, .scheduled] let predicate: NSPredicate - if FeatureFlag.syncPublishing.enabled { + if !FeatureFlag.syncPublishing.enabled { let query = // Existing non-trashed posts "(statusAfterSync = status AND status IN (%@))" diff --git a/WordPress/WordPressTest/PostListFilterTests.swift b/WordPress/WordPressTest/PostListFilterTests.swift index 456c99fde58a..9acbec8d5ef6 100644 --- a/WordPress/WordPressTest/PostListFilterTests.swift +++ b/WordPress/WordPressTest/PostListFilterTests.swift @@ -50,159 +50,4 @@ class PostListFilterTests: CoreDataTestCase { XCTAssertEqual(descriptors[0].key, filter.sortField.keyPath) } } - - func testDraftFilterIncludesLocalDraftsAndExistingDraftAndPendingPosts() { - // Arrange - let predicate = PostListFilter.draftFilter().predicateForFetchRequest - let matchingPosts = [ - createPost(.draft), - createPost(.publish), - createPost(.scheduled), - createPost(.publishPrivate), - createPost(.pending), - createPost(.draft, hasRemote: true), - createPost(.pending, hasRemote: true), - createPost(.draft, hasRemote: true, statusAfterSync: .draft), - createPost(.pending, hasRemote: true, statusAfterSync: .pending), - ] - let nonMatchingPosts = [ - createPost(.trash), - createPost(.deleted), - - createPost(.publish, hasRemote: true), - createPost(.publishPrivate, hasRemote: true), - createPost(.scheduled, hasRemote: true), - createPost(.trash, hasRemote: true), - ] - - // Assert - expect(matchingPosts).to(allPass { predicate.evaluate(with: $0) == true }) - expect(nonMatchingPosts).to(allPass { predicate.evaluate(with: $0) == false }) - } - - func testDraftFilterIncludesExistingDraftsAndPendingPostsTransitionedToOtherStatuses() { - // Arrange - let predicate = PostListFilter.draftFilter().predicateForFetchRequest - let matchingPosts = [ - createPost(.publish, hasRemote: true, statusAfterSync: .draft), - createPost(.publishPrivate, hasRemote: true, statusAfterSync: .draft), - createPost(.scheduled, hasRemote: true, statusAfterSync: .draft), - createPost(.pending, hasRemote: true, statusAfterSync: .draft), - createPost(.trash, hasRemote: true, statusAfterSync: .draft), - - createPost(.publish, hasRemote: true, statusAfterSync: .pending), - createPost(.publishPrivate, hasRemote: true, statusAfterSync: .pending), - createPost(.scheduled, hasRemote: true, statusAfterSync: .pending), - createPost(.pending, hasRemote: true, statusAfterSync: .pending), - createPost(.trash, hasRemote: true, statusAfterSync: .pending), - ] - - // Assert - expect(matchingPosts).to(allPass { predicate.evaluate(with: $0) == true }) - } - - func testPublishedFilterIncludesExistingPrivateAndRemotePublishedPosts() { - // Arrange - let predicate = PostListFilter.publishedFilter().predicateForFetchRequest - let matchingPosts = [ - createPost(.publish, hasRemote: true), - createPost(.publishPrivate, hasRemote: true), - createPost(.publish, hasRemote: true, statusAfterSync: .publish), - createPost(.publishPrivate, hasRemote: true, statusAfterSync: .publishPrivate), - ] - let nonMatchingPosts = [ - createPost(.draft), - createPost(.publish), - createPost(.publishPrivate), - createPost(.scheduled), - createPost(.trash), - createPost(.deleted), - - createPost(.draft, hasRemote: true), - createPost(.scheduled, hasRemote: true), - createPost(.trash, hasRemote: true), - ] - - // Assert - expect(matchingPosts).to(allPass { predicate.evaluate(with: $0) == true }) - expect(nonMatchingPosts).to(allPass { predicate.evaluate(with: $0) == false }) - } - - func testPublishedFilterIncludesExistingPublishedAndPrivatePostsTransitionedToOtherStatuses() { - // Arrange - let predicate = PostListFilter.publishedFilter().predicateForFetchRequest - let matchingPosts = [ - createPost(.draft, hasRemote: true, statusAfterSync: .publish), - createPost(.publishPrivate, hasRemote: true, statusAfterSync: .publish), - createPost(.scheduled, hasRemote: true, statusAfterSync: .publish), - createPost(.pending, hasRemote: true, statusAfterSync: .publish), - createPost(.trash, hasRemote: true, statusAfterSync: .publish), - - createPost(.draft, hasRemote: true, statusAfterSync: .publishPrivate), - createPost(.publishPrivate, hasRemote: true, statusAfterSync: .publishPrivate), - createPost(.scheduled, hasRemote: true, statusAfterSync: .publishPrivate), - createPost(.pending, hasRemote: true, statusAfterSync: .publishPrivate), - createPost(.trash, hasRemote: true, statusAfterSync: .publishPrivate), - ] - - // Assert - expect(matchingPosts).to(allPass { predicate.evaluate(with: $0) == true }) - } - - func testScheduledFilterIncludesExistingScheduledPostsOnly() { - // Arrange - let predicate = PostListFilter.scheduledFilter().predicateForFetchRequest - let matchingPosts = [ - createPost(.scheduled, hasRemote: true), - createPost(.scheduled, hasRemote: true, statusAfterSync: .scheduled), - ] - let nonMatchingPosts = [ - createPost(.draft), - createPost(.scheduled), - createPost(.publish), - createPost(.publishPrivate), - createPost(.trash), - createPost(.deleted), - - createPost(.trash, hasRemote: true), - createPost(.draft, hasRemote: true), - createPost(.publish, hasRemote: true), - createPost(.publishPrivate, hasRemote: true), - ] - - // Assert - expect(matchingPosts).to(allPass { predicate.evaluate(with: $0) == true }) - expect(nonMatchingPosts).to(allPass { predicate.evaluate(with: $0) == false }) - } - - func testScheduledFilterIncludesExistingScheduledPostsTransitionedToOtherStatuses() { - // Arrange - let predicate = PostListFilter.scheduledFilter().predicateForFetchRequest - let matchingPosts = [ - createPost(.draft, hasRemote: true, statusAfterSync: .scheduled), - createPost(.publish, hasRemote: true, statusAfterSync: .scheduled), - createPost(.publishPrivate, hasRemote: true, statusAfterSync: .scheduled), - createPost(.pending, hasRemote: true, statusAfterSync: .scheduled), - createPost(.trash, hasRemote: true, statusAfterSync: .scheduled), - ] - - // Assert - expect(matchingPosts).to(allPass { predicate.evaluate(with: $0) == true }) - } -} - -private extension PostListFilterTests { - func createPost(_ status: BasePost.Status, - hasRemote: Bool = false, - statusAfterSync: BasePost.Status? = nil) -> Post { - let post = Post(context: mainContext) - post.status = status - post.statusAfterSync = statusAfterSync - - if hasRemote { - post.postID = NSNumber(value: Int.random(in: 1...Int.max)) - } - - return post - } }