@@ -122,4 +122,44 @@ class PlaceholderTest {
122122 Assert .assertEquals(initialHtml, editText.toHtml())
123123 }
124124 }
125+
126+ @Test
127+ @Throws(Exception ::class )
128+ fun updatePlaceholderWhenItShouldBe () {
129+ runBlocking {
130+ val initialHtml = " <placeholder uuid=\" uuid123\" type=\" image_with_caption\" src=\" image.jpg;image2.jpg\" caption=\" Caption - 1, 2\" /><p>Line</p>"
131+ editText.fromHtml(initialHtml)
132+
133+ placeholderManager.removeOrUpdate(" uuid123" , shouldUpdateItem = {
134+ true
135+ }) { currentAttributes ->
136+ val result = mutableMapOf<String , String >()
137+ result[" src" ] = currentAttributes[" src" ]?.split(" ;" )?.firstOrNull() ? : " "
138+ result[" caption" ] = " Updated caption"
139+ result
140+ }
141+
142+ Assert .assertEquals(" <placeholder src=\" image.jpg\" caption=\" Updated caption\" uuid=\" uuid123\" type=\" image_with_caption\" /><p>Line</p>" , editText.toHtml())
143+ }
144+ }
145+
146+ @Test
147+ @Throws(Exception ::class )
148+ fun removePlaceholderWhenItShouldNotBeUpdated () {
149+ runBlocking {
150+ val initialHtml = " <placeholder uuid=\" uuid123\" type=\" image_with_caption\" src=\" image.jpg;image2.jpg\" caption=\" Caption - 1, 2\" /><p>Line</p>"
151+ editText.fromHtml(initialHtml)
152+
153+ placeholderManager.removeOrUpdate(" uuid123" , shouldUpdateItem = {
154+ false
155+ }) { currentAttributes ->
156+ val result = mutableMapOf<String , String >()
157+ result[" src" ] = currentAttributes[" src" ]?.split(" ;" )?.firstOrNull() ? : " "
158+ result[" caption" ] = " Updated caption"
159+ result
160+ }
161+
162+ Assert .assertEquals(" <p>Line</p>" , editText.toHtml())
163+ }
164+ }
125165}
0 commit comments