Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdchr committed May 5, 2023
1 parent 8efd32f commit 84e8706
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
16 changes: 10 additions & 6 deletions WordPress/WordPress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -9240,6 +9241,7 @@
FE6BB1452932289B001E5F7A /* ContentMigrationCoordinatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentMigrationCoordinatorTests.swift; sourceTree = "<group>"; };
FE7FAABA299A36570032A6F2 /* WPComJetpackRemoteInstallViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WPComJetpackRemoteInstallViewModelTests.swift; sourceTree = "<group>"; };
FE7FAABC299A98B90032A6F2 /* EventTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTracker.swift; sourceTree = "<group>"; };
FE9438B12A050251006C40EC /* BlockEditorSettings_GutenbergEditorSettingsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockEditorSettings_GutenbergEditorSettingsTests.swift; sourceTree = "<group>"; };
FE97BC13274FCE7A00CF08F9 /* WordPress 137.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "WordPress 137.xcdatamodel"; sourceTree = "<group>"; };
FE9CC71926D7A2A40026AEF3 /* CommentDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentDetailViewController.swift; sourceTree = "<group>"; };
FEA088002696E7F600193358 /* ListTableHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListTableHeaderView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -10351,7 +10353,7 @@
path = Classes;
sourceTree = "<group>";
};
29B97314FDCFA39411CA2CEA = {
29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
isa = PBXGroup;
children = (
3F20FDF3276BF21000DA3CAD /* Packages */,
Expand Down Expand Up @@ -18035,6 +18037,7 @@
FF0B2566237A023C004E255F /* GutenbergVideoUploadProcessorTests.swift */,
4629E4222440C8160002E15C /* GutenbergCoverUploadProcessorTests.swift */,
AEE082892681C23C00DCF54B /* GutenbergRefactoredGalleryUploadProcessorTests.swift */,
FE9438B12A050251006C40EC /* BlockEditorSettings_GutenbergEditorSettingsTests.swift */,
);
name = Gutenberg;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */;
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 */ = {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 84e8706

Please sign in to comment.