Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit a1f86f5

Browse files
authored
Merge pull request #601 from wordpress-mobile/task/add-editor-settings-tests
Add site editor settings tests for block theme support
2 parents f7aa1f9 + e5ca3f6 commit a1f86f5

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

WordPressKitTests/BlockEditorSettingsServiceRemoteTests.swift

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ extension BlockEditorSettingsServiceRemoteTests {
3636
XCTAssertFalse(result!.checksum.isEmpty)
3737
XCTAssertGreaterThan(result!.themeSupport!.colors!.count, 0)
3838
XCTAssertGreaterThan(result!.themeSupport!.gradients!.count, 0)
39+
XCTAssertTrue(result!.themeSupport!.blockTemplates)
3940
case .failure:
4041
XCTFail("This payload should parse successfully")
4142
}
@@ -84,7 +85,10 @@ extension BlockEditorSettingsServiceRemoteTests {
8485
var theme = mockedResponse[0]
8586
var themeSupport = theme[RemoteEditorTheme.CodingKeys.themeSupport.stringValue] as! [String: Any]
8687
themeSupport[RemoteEditorThemeSupport.CodingKeys.colors.stringValue] = "false"
88+
89+
themeSupport[RemoteEditorThemeSupport.CodingKeys.blockTemplates.stringValue] = "false"
8790
theme[RemoteEditorTheme.CodingKeys.themeSupport.stringValue] = themeSupport
91+
8892
mockedResponse[0] = theme
8993

9094
service.fetchTheme(forSiteID: siteID) { (response) in
@@ -94,6 +98,32 @@ extension BlockEditorSettingsServiceRemoteTests {
9498
XCTAssertFalse(result!.checksum.isEmpty)
9599
XCTAssertNil(result!.themeSupport!.colors)
96100
XCTAssertGreaterThan(result!.themeSupport!.gradients!.count, 0)
101+
XCTAssertFalse(result!.themeSupport!.blockTemplates)
102+
case .failure:
103+
XCTFail("This payload should parse successfully")
104+
}
105+
waitExpectation.fulfill()
106+
}
107+
mockRemoteApi.successBlockPassedIn!(mockedResponse as AnyObject, HTTPURLResponse())
108+
109+
waitForExpectations(timeout: 0.1)
110+
validateEditorThemeRequest()
111+
}
112+
113+
func testFetchThemeNoThemeSupport() {
114+
let waitExpectation = expectation(description: "Theme should be successfully fetched")
115+
var mockedResponse = mockedData(withFilename: twentytwentyoneResponseFilename) as! [[String: Any]]
116+
var theme = mockedResponse[0]
117+
var themeSupport = theme[RemoteEditorTheme.CodingKeys.themeSupport.stringValue] as! [String: Any]
118+
119+
themeSupport.removeValue(forKey: RemoteEditorThemeSupport.CodingKeys.blockTemplates.stringValue)
120+
theme[RemoteEditorTheme.CodingKeys.themeSupport.stringValue] = themeSupport
121+
mockedResponse[0] = theme
122+
123+
service.fetchTheme(forSiteID: siteID) { (response) in
124+
switch response {
125+
case .success(let result):
126+
XCTAssertFalse(result!.themeSupport!.blockTemplates)
97127
case .failure:
98128
XCTFail("This payload should parse successfully")
99129
}
@@ -139,6 +169,7 @@ extension BlockEditorSettingsServiceRemoteTests {
139169
case .success(let result):
140170
self.validateFetchBlockEditorSettingsResults(result)
141171
XCTAssertNil(result!.rawStyles)
172+
XCTAssertFalse(result!.isFSETheme)
142173
case .failure:
143174
XCTFail("This payload should parse successfully")
144175
}
@@ -160,6 +191,7 @@ extension BlockEditorSettingsServiceRemoteTests {
160191
self.validateFetchBlockEditorSettingsResults(result)
161192

162193
XCTAssertNotNil(result!.rawStyles)
194+
XCTAssertTrue(result!.isFSETheme)
163195
let gssRawJson = result!.rawStyles!.data(using: .utf8)!
164196
let vaildJson = try? JSONSerialization.jsonObject(with: gssRawJson, options: [])
165197
XCTAssertNotNil(vaildJson)
@@ -174,6 +206,27 @@ extension BlockEditorSettingsServiceRemoteTests {
174206
validateFetchBlockEditorSettingsRequest()
175207
}
176208

209+
func testFetchBlockEditorSettingsNoFSETheme() {
210+
let waitExpectation = expectation(description: "Block Settings should be successfully fetched")
211+
var mockedResponse = mockedData(withFilename: blockSettingsThemeJSONResponseFilename) as! [String: Any]
212+
mockedResponse.removeValue(forKey: RemoteBlockEditorSettings.CodingKeys.isFSETheme.stringValue)
213+
214+
service.fetchBlockEditorSettings(forSiteID: siteID) { (response) in
215+
switch response {
216+
case .success(let result):
217+
self.validateFetchBlockEditorSettingsResults(result)
218+
XCTAssertFalse(result!.isFSETheme)
219+
case .failure:
220+
XCTFail("This payload should parse successfully")
221+
}
222+
waitExpectation.fulfill()
223+
}
224+
mockRemoteApi.successBlockPassedIn!(mockedResponse as AnyObject, HTTPURLResponse())
225+
226+
waitForExpectations(timeout: 0.1)
227+
validateFetchBlockEditorSettingsRequest()
228+
}
229+
177230
func testFetchBlockEditorSettingsThemeJSON_ConsistentChecksum() {
178231
let json = Bundle(for: BlockEditorSettingsServiceRemoteTests.self).url(forResource: blockSettingsThemeJSONResponseFilename, withExtension: "json")!
179232
let data = try! Data(contentsOf: json)

WordPressKitTests/Mock Data/BlockEditorSettings/get_wp_v2_themes_twentytwentyone-no-colors.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@
178178
"post-thumbnails": true,
179179
"responsive-embeds": true,
180180
"title-tag": true,
181-
"wp-block-styles": true
181+
"wp-block-styles": true,
182+
"block-templates": false
182183
},
183184
"_links": {
184185
"self": [

WordPressKitTests/Mock Data/BlockEditorSettings/get_wp_v2_themes_twentytwentyone.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@
229229
"post-thumbnails": true,
230230
"responsive-embeds": true,
231231
"title-tag": true,
232-
"wp-block-styles": true
232+
"wp-block-styles": true,
233+
"block-templates": true
233234
},
234235
"_links": {
235236
"self": [

WordPressKitTests/Mock Data/BlockEditorSettings/wp-block-editor-v1-settings-success-NotThemeJSON.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"__unstableIsBlockBasedTheme": false,
23
"__unstableEnableFullSiteEditingBlocks": true,
34
"alignWide": true,
45
"allowedBlockTypes": true,

WordPressKitTests/Mock Data/BlockEditorSettings/wp-block-editor-v1-settings-success-ThemeJSON.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"__unstableIsBlockBasedTheme": true,
23
"__unstableEnableFullSiteEditingBlocks": true,
34
"alignWide": false,
45
"allowedBlockTypes": true,

0 commit comments

Comments
 (0)