diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index e66d539178a2..ff40b0463a9f 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -5489,6 +5489,7 @@ FE7FAABB299A36570032A6F2 /* WPComJetpackRemoteInstallViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE7FAABA299A36570032A6F2 /* WPComJetpackRemoteInstallViewModelTests.swift */; }; FE7FAABE299A998E0032A6F2 /* EventTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE7FAABC299A98B90032A6F2 /* EventTracker.swift */; }; FE7FAABF299A998F0032A6F2 /* EventTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE7FAABC299A98B90032A6F2 /* EventTracker.swift */; }; + FE9438B22A050251006C40EC /* BlockEditorSettings_GutenbergEditorSettingsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE9438B12A050251006C40EC /* BlockEditorSettings_GutenbergEditorSettingsTests.swift */; }; FE9CC71A26D7A2A40026AEF3 /* CommentDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE9CC71926D7A2A40026AEF3 /* CommentDetailViewController.swift */; }; FE9CC71B26D7A2A40026AEF3 /* CommentDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE9CC71926D7A2A40026AEF3 /* CommentDetailViewController.swift */; }; FEA088012696E7F600193358 /* ListTableHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FEA088002696E7F600193358 /* ListTableHeaderView.swift */; }; @@ -9240,6 +9241,7 @@ FE6BB1452932289B001E5F7A /* ContentMigrationCoordinatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentMigrationCoordinatorTests.swift; sourceTree = ""; }; FE7FAABA299A36570032A6F2 /* WPComJetpackRemoteInstallViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WPComJetpackRemoteInstallViewModelTests.swift; sourceTree = ""; }; FE7FAABC299A98B90032A6F2 /* EventTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTracker.swift; sourceTree = ""; }; + FE9438B12A050251006C40EC /* BlockEditorSettings_GutenbergEditorSettingsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockEditorSettings_GutenbergEditorSettingsTests.swift; sourceTree = ""; }; FE97BC13274FCE7A00CF08F9 /* WordPress 137.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "WordPress 137.xcdatamodel"; sourceTree = ""; }; FE9CC71926D7A2A40026AEF3 /* CommentDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentDetailViewController.swift; sourceTree = ""; }; FEA088002696E7F600193358 /* ListTableHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListTableHeaderView.swift; sourceTree = ""; }; @@ -10351,7 +10353,7 @@ path = Classes; sourceTree = ""; }; - 29B97314FDCFA39411CA2CEA = { + 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = { isa = PBXGroup; children = ( 3F20FDF3276BF21000DA3CAD /* Packages */, @@ -18035,6 +18037,7 @@ FF0B2566237A023C004E255F /* GutenbergVideoUploadProcessorTests.swift */, 4629E4222440C8160002E15C /* GutenbergCoverUploadProcessorTests.swift */, AEE082892681C23C00DCF54B /* GutenbergRefactoredGalleryUploadProcessorTests.swift */, + FE9438B12A050251006C40EC /* BlockEditorSettings_GutenbergEditorSettingsTests.swift */, ); name = Gutenberg; sourceTree = ""; @@ -18634,14 +18637,14 @@ bg, sk, ); - mainGroup = 29B97314FDCFA39411CA2CEA; + mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */; packageReferences = ( 3FF1442E266F3C2400138163 /* XCRemoteSwiftPackageReference "ScreenObject" */, 3FC2C33B26C4CF0A00C6D98F /* XCRemoteSwiftPackageReference "XCUITestHelpers" */, 17A8858B2757B97F0071FCA3 /* XCRemoteSwiftPackageReference "AutomatticAbout-swift" */, 3F2B62DA284F4E0B0008CD59 /* XCRemoteSwiftPackageReference "Charts" */, 3F3B23C02858A1B300CACE60 /* XCRemoteSwiftPackageReference "test-collector-swift" */, - 3F411B6D28987E3F002513AE /* XCRemoteSwiftPackageReference "lottie-ios.git" */, + 3F411B6D28987E3F002513AE /* XCRemoteSwiftPackageReference "lottie-ios" */, 3F338B6F289BD3040014ADC5 /* XCRemoteSwiftPackageReference "Nimble" */, ); productRefGroup = 19C28FACFE9D520D11CA2CBB /* Products */; @@ -23125,6 +23128,7 @@ 572FB401223A806000933C76 /* NoticeStoreTests.swift in Sources */, F5CFB8F524216DFC00E58B69 /* CalendarHeaderViewTests.swift in Sources */, 748437EE1F1D4A7300E8DDAF /* RichContentFormatterTests.swift in Sources */, + FE9438B22A050251006C40EC /* BlockEditorSettings_GutenbergEditorSettingsTests.swift in Sources */, C81CCD6A243AEE1100A83E27 /* TenorAPIResponseTests.swift in Sources */, 8BE7C84123466927006EDE70 /* I18n.swift in Sources */, C396C80B280F2401006FE7AC /* SiteDesignTests.swift in Sources */, @@ -30355,7 +30359,7 @@ minimumVersion = 0.3.0; }; }; - 3F411B6D28987E3F002513AE /* XCRemoteSwiftPackageReference "lottie-ios.git" */ = { + 3F411B6D28987E3F002513AE /* XCRemoteSwiftPackageReference "lottie-ios" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/airbnb/lottie-ios.git"; requirement = { @@ -30436,12 +30440,12 @@ }; 3F411B6E28987E3F002513AE /* Lottie */ = { isa = XCSwiftPackageProductDependency; - package = 3F411B6D28987E3F002513AE /* XCRemoteSwiftPackageReference "lottie-ios.git" */; + package = 3F411B6D28987E3F002513AE /* XCRemoteSwiftPackageReference "lottie-ios" */; productName = Lottie; }; 3F44DD57289C379C006334CD /* Lottie */ = { isa = XCSwiftPackageProductDependency; - package = 3F411B6D28987E3F002513AE /* XCRemoteSwiftPackageReference "lottie-ios.git" */; + package = 3F411B6D28987E3F002513AE /* XCRemoteSwiftPackageReference "lottie-ios" */; productName = Lottie; }; 3FC2C33C26C4CF0A00C6D98F /* XCUITestHelpers */ = { diff --git a/WordPress/WordPressTest/BlockEditorSettings_GutenbergEditorSettingsTests.swift b/WordPress/WordPressTest/BlockEditorSettings_GutenbergEditorSettingsTests.swift new file mode 100644 index 000000000000..ffcaf918e3dd --- /dev/null +++ b/WordPress/WordPressTest/BlockEditorSettings_GutenbergEditorSettingsTests.swift @@ -0,0 +1,49 @@ +import Foundation +import XCTest + +@testable import WordPress + +class BlockEditorSettings_GutenbergEditorSettingsTests: CoreDataTestCase { + + func test_initWithRemoteEditorTheme_correctlyDetectsFSE() { + let fseTheme = makeRemoteEditorTheme() + let settings = BlockEditorSettings(editorTheme: fseTheme!, context: mainContext) + + XCTAssertNotNil(settings) + XCTAssertTrue(settings!.isFSETheme) + + let nonFSETheme = makeRemoteEditorTheme(isFSETheme: false) + let settings2 = BlockEditorSettings(editorTheme: nonFSETheme!, context: mainContext) + + XCTAssertNotNil(settings2) + XCTAssertFalse(settings2!.isFSETheme) + } + +} + +// MARK: - Helpers + +private extension BlockEditorSettings_GutenbergEditorSettingsTests { + func makeRemoteEditorTheme(isFSETheme: Bool = true) -> RemoteEditorTheme? { + guard var themeJson = mockedThemesResponse(filename: "get_wp_v2_themes_twentytwenty"), + var themeSupports = themeJson["theme_supports"] as? [String: AnyHashable] else { + return nil + } + themeSupports["block-templates"] = isFSETheme + themeJson["theme_supports"] = themeSupports + + guard let data = try? JSONSerialization.data(withJSONObject: themeJson) else { + return nil + } + return try? JSONDecoder().decode(RemoteEditorTheme.self, from: data) + } + + func mockedThemesResponse(filename: String) -> [String: AnyHashable]? { + guard let json = Bundle(for: BlockEditorSettingsServiceTests.self).url(forResource: filename, withExtension: "json"), + let data = try? Data(contentsOf: json), + let response = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [[String: AnyHashable]] else { + return nil + } + return response.first + } +}