Skip to content

Commit

Permalink
Merge pull request #1940 from wordpress-mobile/add/3163-GSS
Browse files Browse the repository at this point in the history
[Global Styles] Implements Global Styles API Call
  • Loading branch information
Antonis Lilis authored Jun 29, 2021
2 parents 2f9ee2a + b46c343 commit 2d9132d
Show file tree
Hide file tree
Showing 7 changed files with 1,229 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class MockedStack_EditorThemeStoreTest : MockedStack_Base() {
private lateinit var countDownLatch: CountDownLatch
private lateinit var site: SiteModel
private lateinit var payload: FetchEditorThemePayload
private lateinit var payloadWithGSS: FetchEditorThemePayload
private var editorTheme: EditorTheme? = null

override fun setUp() {
Expand All @@ -38,7 +39,9 @@ class MockedStack_EditorThemeStoreTest : MockedStack_Base() {

site = SiteModel()
site.setIsWPCom(true)
site.softwareVersion = "5.8"
payload = FetchEditorThemePayload(site)
payloadWithGSS = FetchEditorThemePayload(site, true)
countDownLatch = CountDownLatch(1)
}

Expand Down Expand Up @@ -134,6 +137,52 @@ class MockedStack_EditorThemeStoreTest : MockedStack_Base() {
assertEmpty(themeBundle)
}

@Test
fun testGlobalStylesSettingsOffSuccess() {
interceptor.respondWith("global-styles-off-success.json")
dispatcher.dispatch(EditorThemeActionBuilder.newFetchEditorThemeAction(payloadWithGSS))

// See onEditorThemeChanged for the latch's countdown to fire.
Assert.assertTrue(countDownLatch.await(TestUtils.DEFAULT_TIMEOUT_MS.toLong(), MILLISECONDS))

// Validate Callback
assertNotEmpty(editorTheme)

// Validate Cache
val cachedTheme = editorThemeStore.getEditorThemeForSite(site)
assertNotEmpty(cachedTheme)

// Validate Bundle
val themeBundle = editorTheme!!.themeSupport.toBundle()
assertNotEmpty(themeBundle)
}

@Test
fun testGlobalStylesSettingsFullSuccess() {
interceptor.respondWith("global-styles-full-success.json")
dispatcher.dispatch(EditorThemeActionBuilder.newFetchEditorThemeAction(payloadWithGSS))

// See onEditorThemeChanged for the latch's countdown to fire.
Assert.assertTrue(countDownLatch.await(TestUtils.DEFAULT_TIMEOUT_MS.toLong(), MILLISECONDS))

// Validate Callback
assertEmpty(editorTheme)
Assert.assertNotNull(editorTheme?.themeSupport?.rawStyles)

// Validate Cache
val cachedTheme = editorThemeStore.getEditorThemeForSite(site)
assertEmpty(cachedTheme)
Assert.assertNotNull(cachedTheme?.themeSupport?.rawStyles)

// Validate Bundle
val themeBundle = editorTheme!!.themeSupport.toBundle()
assertEmpty(themeBundle)
val styles = themeBundle.getString("rawStyles")
val features = themeBundle.getString("rawFeatures")
Assert.assertNotNull(styles)
Assert.assertNotNull(features)
}

private fun assertNotEmpty(theme: EditorTheme?) {
Assert.assertFalse(theme?.themeSupport?.colors.isNullOrEmpty())
Assert.assertFalse(theme?.themeSupport?.gradients.isNullOrEmpty())
Expand Down
Loading

0 comments on commit 2d9132d

Please sign in to comment.