Skip to content

Commit

Permalink
Merge pull request #5098 from wikimedia/yir-saved-slide
Browse files Browse the repository at this point in the history
[YiR] V2 - Saved Articles slide
  • Loading branch information
tonisevener authored Dec 5, 2024
2 parents f222aa1 + 8f83053 commit 71ce7a8
Show file tree
Hide file tree
Showing 32 changed files with 1,052 additions and 267 deletions.
12 changes: 12 additions & 0 deletions WMF Framework/MWKSavedPageList+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import WMFData

extension MWKSavedPageList: SavedArticleSlideDataDelegate {
public func getSavedArticleSlideData(from startDate: Date, to endDate: Date) async -> SavedArticleSlideData {
await MainActor.run {
let savedArticleCount = savedArticleCount(for: startDate, end: endDate)
let savedArticleTitles = randomSavedArticleTitles(for: startDate, end: endDate)
let slideData = SavedArticleSlideData(savedArticlesCount: savedArticleCount, articleTitles: savedArticleTitles)
return slideData
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public struct WMFFeatureConfigResponse: Codable {
let readCount: SlideSettings
let editCount: SlideSettings
let donateCount: SlideSettings
let saveCount: SlideSettings
let mostReadDay: SlideSettings
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum WMFYearInReviewPersonalizedSlideID: String, Comparable {
case readCount
case editCount
case donateCount
case saveCount
case mostReadDay

public static func < (lhs: WMFYearInReviewPersonalizedSlideID, rhs: WMFYearInReviewPersonalizedSlideID) -> Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ fileprivate class WMFMockYearInReviewDataController: WMFYearInReviewDataControll
let editCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let donateCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let mostReadDaySlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let personalizedSlides = WMFFeatureConfigResponse.IOS.YearInReview.PersonalizedSlides(readCount: readCountSlideSettings, editCount: editCountSlideSettings, donateCount: donateCountSlideSettings, mostReadDay: mostReadDaySlideSettings)
let savedCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let personalizedSlides = WMFFeatureConfigResponse.IOS.YearInReview.PersonalizedSlides(readCount: readCountSlideSettings, editCount: editCountSlideSettings, donateCount: donateCountSlideSettings, saveCount: savedCountSlideSettings, mostReadDay: mostReadDaySlideSettings)
let yearInReview = WMFFeatureConfigResponse.IOS.YearInReview(yearID: "2024.2", isEnabled: false, countryCodes: ["FR", "IT"], primaryAppLanguageCodes: ["fr", "it"], dataPopulationStartDateString: "2024-01-01T00:00:00Z", dataPopulationEndDateString: "2024-11-01T00:00:00Z", personalizedSlides: personalizedSlides, hideDonateCountryCodes: ["AE", "AF", "AX", "BY", "CD", "CI"])
let ios = WMFFeatureConfigResponse.IOS(version: 1, yir: [yearInReview])
let config = WMFFeatureConfigResponse(ios: [ios])
Expand Down Expand Up @@ -53,6 +54,14 @@ fileprivate class WMFMockYearInReviewDataController: WMFYearInReviewDataControll
donateCountSlide.data = nil
results.insert(donateCountSlide)

let savedCountSlide = try coreDataStore.create(entityType: CDYearInReviewSlide.self, in: moc)
savedCountSlide.year = 2024
savedCountSlide.id = WMFYearInReviewPersonalizedSlideID.saveCount.rawValue
savedCountSlide.evaluated = false
savedCountSlide.display = false
savedCountSlide.data = nil
results.insert(savedCountSlide)

let mostReadDaySlide = try coreDataStore.create(entityType: CDYearInReviewSlide.self, in: moc)
mostReadDaySlide.year = 2024
mostReadDaySlide.id = WMFYearInReviewPersonalizedSlideID.mostReadDay.rawValue
Expand Down Expand Up @@ -106,7 +115,7 @@ final class WMFYearInReviewDataControllerCreateOrRetrieveTests: XCTestCase {
}

dataController.shouldCreateOrRetrieve = false
let report = try await dataController.populateYearInReviewReportData(for: year, countryCode: countryCode, primaryAppLanguageProject: enProject, username: username)
let report = try await dataController.populateYearInReviewReportData(for: year, countryCode: countryCode, primaryAppLanguageProject: enProject, username: username, savedSlideDataDelegate: self)
XCTAssertNil(report, "Expected nil when shouldCreateOrRetrieveYearInReview returns false")

}
Expand All @@ -117,21 +126,23 @@ final class WMFYearInReviewDataControllerCreateOrRetrieveTests: XCTestCase {
throw TestsError.missingDataController
}

var report = try await dataController.populateYearInReviewReportData(for: year, countryCode: countryCode, primaryAppLanguageProject: enProject, username: username)
var report = try await dataController.populateYearInReviewReportData(for: year, countryCode: countryCode, primaryAppLanguageProject: enProject, username: username, savedSlideDataDelegate: self)
dataController.shouldCreateOrRetrieve = true

let existingSlide1 = WMFYearInReviewSlide(year: year, id: .readCount, evaluated: true, display: true)
let existingSlide2 = WMFYearInReviewSlide(year: year, id: .editCount, evaluated: true, display: true)
let existingSlide3 = WMFYearInReviewSlide(year: year, id: .donateCount, evaluated: true, display: true)
let existingSlide4 = WMFYearInReviewSlide(year: year, id: .mostReadDay, evaluated: true, display: true)
let existingSlide2 = WMFYearInReviewSlide(year: year, id: .saveCount, evaluated: true, display: true)
let existingSlide3 = WMFYearInReviewSlide(year: year, id: .mostReadDay, evaluated: true, display: true)
let existingSlide4 = WMFYearInReviewSlide(year: year, id: .editCount, evaluated: true, display: true)
let existingSlide5 = WMFYearInReviewSlide(year: year, id: .donateCount, evaluated: true, display: true)

let existingReport = WMFYearInReviewReport(year: year, slides: [existingSlide1, existingSlide2, existingSlide3, existingSlide4])
let existingReport = WMFYearInReviewReport(year: year, slides: [existingSlide1, existingSlide2, existingSlide3, existingSlide4, existingSlide5])

try await dataController.saveYearInReviewReport(existingReport)

report = try await dataController.populateYearInReviewReportData(for: year, countryCode: countryCode, primaryAppLanguageProject: enProject, username: username)
report = try await dataController.populateYearInReviewReportData(for: year, countryCode: countryCode, primaryAppLanguageProject: enProject, username: username, savedSlideDataDelegate: self)
XCTAssertNotNil(report, "Expected a report to be retrieved")
XCTAssertEqual(report?.year, year)
XCTAssertEqual(report?.slides.count, 4)
XCTAssertEqual(report?.slides.count, 5)
}

func testShouldCreateOrRetrieveYearInReviewWithNewReport() async throws {
Expand All @@ -140,13 +151,19 @@ final class WMFYearInReviewDataControllerCreateOrRetrieveTests: XCTestCase {
throw TestsError.missingDataController
}

var report = try await dataController.populateYearInReviewReportData(for: year, countryCode: countryCode, primaryAppLanguageProject: enProject, username: username)
var report = try await dataController.populateYearInReviewReportData(for: year, countryCode: countryCode, primaryAppLanguageProject: enProject, username: username, savedSlideDataDelegate: self)

try await dataController.deleteYearInReviewReport(year: year)

report = try await dataController.populateYearInReviewReportData(for: year, countryCode: countryCode, primaryAppLanguageProject: enProject, username: username)
report = try await dataController.populateYearInReviewReportData(for: year, countryCode: countryCode, primaryAppLanguageProject: enProject, username: username, savedSlideDataDelegate: self)
XCTAssertNotNil(report, "Expected a new report to be created")
XCTAssertEqual(report?.year, year)
XCTAssertEqual(report?.slides.count, 4)
XCTAssertEqual(report?.slides.count, 5)
}
}

extension WMFYearInReviewDataControllerCreateOrRetrieveTests: SavedArticleSlideDataDelegate {
func getSavedArticleSlideData(from startDate: Date, to endEnd: Date) async -> WMFData.SavedArticleSlideData {
return SavedArticleSlideData(savedArticlesCount: 30, articleTitles: ["Cat", "Dog", "Bird"])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ final class WMFYearInReviewDataControllerTests: XCTestCase {
let editCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let donateCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let mostReadDaySlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let personalizedSlides = WMFFeatureConfigResponse.IOS.YearInReview.PersonalizedSlides(readCount: readCountSlideSettings, editCount: editCountSlideSettings, donateCount: donateCountSlideSettings, mostReadDay: mostReadDaySlideSettings)
let savedCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)

let personalizedSlides = WMFFeatureConfigResponse.IOS.YearInReview.PersonalizedSlides(readCount: readCountSlideSettings, editCount: editCountSlideSettings, donateCount: donateCountSlideSettings, saveCount: savedCountSlideSettings, mostReadDay: mostReadDaySlideSettings)
let yearInReview = WMFFeatureConfigResponse.IOS.YearInReview(yearID: "2024.2", isEnabled: false, countryCodes: ["FR", "IT"], primaryAppLanguageCodes: ["fr", "it"], dataPopulationStartDateString: "2024-01-01T00:00:00Z", dataPopulationEndDateString: "2024-11-01T00:00:00Z", personalizedSlides: personalizedSlides, hideDonateCountryCodes: ["AE", "AF", "AX", "BY", "CD", "CI"])
let ios = WMFFeatureConfigResponse.IOS(version: 1, yir: [yearInReview])
let config = WMFFeatureConfigResponse(ios: [ios])
Expand Down Expand Up @@ -219,7 +221,9 @@ final class WMFYearInReviewDataControllerTests: XCTestCase {
let editCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let donateCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let mostReadDaySlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let personalizedSlides = WMFFeatureConfigResponse.IOS.YearInReview.PersonalizedSlides(readCount: readCountSlideSettings, editCount: editCountSlideSettings, donateCount: donateCountSlideSettings, mostReadDay: mostReadDaySlideSettings)
let savedCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)

let personalizedSlides = WMFFeatureConfigResponse.IOS.YearInReview.PersonalizedSlides(readCount: readCountSlideSettings, editCount: editCountSlideSettings, donateCount: donateCountSlideSettings, saveCount: savedCountSlideSettings, mostReadDay: mostReadDaySlideSettings)
let yearInReview = WMFFeatureConfigResponse.IOS.YearInReview(yearID: "2024.2", isEnabled: true, countryCodes: ["FR", "IT"], primaryAppLanguageCodes: ["fr", "it"], dataPopulationStartDateString: "2024-01-01T00:00:00Z", dataPopulationEndDateString: "2024-11-01T00:00:00Z", personalizedSlides: personalizedSlides, hideDonateCountryCodes: ["AE", "AF", "AX", "BY", "CD", "CI"])
let ios = WMFFeatureConfigResponse.IOS(version: 1, yir: [yearInReview])
let config = WMFFeatureConfigResponse(ios: [ios])
Expand Down Expand Up @@ -257,7 +261,9 @@ final class WMFYearInReviewDataControllerTests: XCTestCase {
let editCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let donateCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let mostReadDaySlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let personalizedSlides = WMFFeatureConfigResponse.IOS.YearInReview.PersonalizedSlides(readCount: readCountSlideSettings, editCount: editCountSlideSettings, donateCount: donateCountSlideSettings, mostReadDay: mostReadDaySlideSettings)
let savedCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)

let personalizedSlides = WMFFeatureConfigResponse.IOS.YearInReview.PersonalizedSlides(readCount: readCountSlideSettings, editCount: editCountSlideSettings, donateCount: donateCountSlideSettings, saveCount: savedCountSlideSettings, mostReadDay: mostReadDaySlideSettings)
let yearInReview = WMFFeatureConfigResponse.IOS.YearInReview(yearID: "2024.2", isEnabled: true, countryCodes: ["FR", "IT"], primaryAppLanguageCodes: ["fr", "it"], dataPopulationStartDateString: "2024-01-01T00:00:00Z", dataPopulationEndDateString: "2024-11-01T00:00:00Z", personalizedSlides: personalizedSlides, hideDonateCountryCodes: ["AE", "AF", "AX", "BY", "CD", "CI"])
let ios = WMFFeatureConfigResponse.IOS(version: 1, yir: [yearInReview])
let config = WMFFeatureConfigResponse(ios: [ios])
Expand Down Expand Up @@ -295,7 +301,9 @@ final class WMFYearInReviewDataControllerTests: XCTestCase {
let editCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: false)
let donateCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let mostReadDaySlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let personalizedSlides = WMFFeatureConfigResponse.IOS.YearInReview.PersonalizedSlides(readCount: readCountSlideSettings, editCount: editCountSlideSettings, donateCount: donateCountSlideSettings, mostReadDay: mostReadDaySlideSettings)
let savedCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)

let personalizedSlides = WMFFeatureConfigResponse.IOS.YearInReview.PersonalizedSlides(readCount: readCountSlideSettings, editCount: editCountSlideSettings, donateCount: donateCountSlideSettings, saveCount: savedCountSlideSettings, mostReadDay: mostReadDaySlideSettings)
let yearInReview = WMFFeatureConfigResponse.IOS.YearInReview(yearID: "2024.2", isEnabled: true, countryCodes: ["FR", "IT"], primaryAppLanguageCodes: ["fr", "it"], dataPopulationStartDateString: "2024-01-01T00:00:00Z", dataPopulationEndDateString: "2024-11-01T00:00:00Z", personalizedSlides: personalizedSlides, hideDonateCountryCodes: ["AE", "AF", "AX", "BY", "CD", "CI"])
let ios = WMFFeatureConfigResponse.IOS(version: 1, yir: [yearInReview])
let config = WMFFeatureConfigResponse(ios: [ios])
Expand Down Expand Up @@ -329,7 +337,9 @@ final class WMFYearInReviewDataControllerTests: XCTestCase {
let editCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: false)
let donateCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let mostReadDaySlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let personalizedSlides = WMFFeatureConfigResponse.IOS.YearInReview.PersonalizedSlides(readCount: readCountSlideSettings, editCount: editCountSlideSettings, donateCount: donateCountSlideSettings, mostReadDay: mostReadDaySlideSettings)
let savedCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)

let personalizedSlides = WMFFeatureConfigResponse.IOS.YearInReview.PersonalizedSlides(readCount: readCountSlideSettings, editCount: editCountSlideSettings, donateCount: donateCountSlideSettings, saveCount: savedCountSlideSettings, mostReadDay: mostReadDaySlideSettings)
let yearInReview = WMFFeatureConfigResponse.IOS.YearInReview(yearID: "2024.2", isEnabled: true, countryCodes: ["FR", "IT"], primaryAppLanguageCodes: ["fr", "it"], dataPopulationStartDateString: "2024-01-01T00:00:00Z", dataPopulationEndDateString: "2024-11-01T00:00:00Z", personalizedSlides: personalizedSlides, hideDonateCountryCodes: ["AE", "AF", "AX", "BY", "CD", "CI"])
let ios = WMFFeatureConfigResponse.IOS(version: 1, yir: [yearInReview])
let config = WMFFeatureConfigResponse(ios: [ios])
Expand Down
4 changes: 4 additions & 0 deletions Wikipedia.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@
67A6F14023BFF62300736539 /* ImageCacheController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A6F13F23BFF62200736539 /* ImageCacheController.swift */; };
67A770C8251BFE0400F94EF9 /* CocoaLumberjackSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 67A770C7251BFE0400F94EF9 /* CocoaLumberjackSwift */; };
67A7CA7528665CEF008D4BF6 /* HTTPStatusCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A7CA7428665CEF008D4BF6 /* HTTPStatusCode.swift */; };
67A82D202D0239550068B363 /* MWKSavedPageList+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A82D1F2D02394E0068B363 /* MWKSavedPageList+Extensions.swift */; };
67AD17FF2C49D3BB0027C630 /* WMFBarButtonItemPopoverMessageViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 67AD17FE2C49D3BB0027C630 /* WMFBarButtonItemPopoverMessageViewController.storyboard */; };
67AD18002C49D3BB0027C630 /* WMFBarButtonItemPopoverMessageViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 67AD17FE2C49D3BB0027C630 /* WMFBarButtonItemPopoverMessageViewController.storyboard */; };
67AD18012C49D3BB0027C630 /* WMFBarButtonItemPopoverMessageViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 67AD17FE2C49D3BB0027C630 /* WMFBarButtonItemPopoverMessageViewController.storyboard */; };
Expand Down Expand Up @@ -3454,6 +3455,7 @@
67A6F13D23BFEF4200736539 /* ArticleCacheController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleCacheController.swift; sourceTree = "<group>"; };
67A6F13F23BFF62200736539 /* ImageCacheController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCacheController.swift; sourceTree = "<group>"; };
67A7CA7428665CEF008D4BF6 /* HTTPStatusCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPStatusCode.swift; sourceTree = "<group>"; };
67A82D1F2D02394E0068B363 /* MWKSavedPageList+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MWKSavedPageList+Extensions.swift"; sourceTree = "<group>"; };
67A986EC2CC96488003A99B5 /* az */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = az; path = az.lproj/InfoPlist.strings; sourceTree = "<group>"; };
67A986ED2CC96488003A99B5 /* az */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = az; path = az.lproj/Localizable.strings; sourceTree = "<group>"; };
67A986EE2CC96488003A99B5 /* az */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = az; path = az.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5801,6 +5803,7 @@
672344CF2C98FBFA0021BB4F /* MWKDataStore+WMFPageViewImport.swift */,
B0E807B41C0CF0180065EBC0 /* MWKSavedPageList.h */,
B0E807B51C0CF0180065EBC0 /* MWKSavedPageList.m */,
67A82D1F2D02394E0068B363 /* MWKSavedPageList+Extensions.swift */,
D8C41DDA23FC09EE00353DCE /* NSManagedObjectContext+History.swift */,
D8BD63BE1EA7E28700BBC082 /* SummaryExtensions.swift */,
83A933442514C491006EB48A /* WMFCrossProcessCoreDataSynchronizer.h */,
Expand Down Expand Up @@ -11022,6 +11025,7 @@
D8FA18D11E1BD891009675C3 /* WMFMath.m in Sources */,
678F512B23A7EE6600CE5357 /* ArticleFetcher.swift in Sources */,
0042808925E6E395004945B3 /* MTLModel.m in Sources */,
67A82D202D0239550068B363 /* MWKSavedPageList+Extensions.swift in Sources */,
6785FCC92A66D8DB0078FAF2 /* WMFCleanLevel.swift in Sources */,
0042807B25E6E395004945B3 /* MTLModel+NSCoding.m in Sources */,
D8FA18B41E1BD891009675C3 /* NSCalendar+WMFCommonCalendars.m in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions Wikipedia/Code/MWKSavedPageList.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)removeEntryWithURL:(NSURL *)url;

- (NSInteger)savedArticleCountFor:(NSDate *)startDate endDate:(NSDate *)endDate;

- (NSArray<NSString *> *)randomSavedArticleTitlesFor:(NSDate *)startDate endDate:(NSDate *)endDate;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 71ce7a8

Please sign in to comment.