Skip to content

Commit ad8fede

Browse files
committed
refactor/qg-290: выделена логика формирования дескриптора элемента для Jsoup и Selenide
1 parent 0233f98 commit ad8fede

File tree

4 files changed

+39
-24
lines changed

4 files changed

+39
-24
lines changed

app/src/testFixtures/kotlin/pro/qyoga/tests/assertions/ElementMatchers.kt

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.springframework.web.util.UriTemplate
1010
import pro.qyoga.tests.platform.html.Component
1111
import pro.qyoga.tests.platform.html.HtmlPage
1212
import pro.qyoga.tests.platform.html.Input
13+
import pro.qyoga.tests.platform.html.elementDescr
1314

1415

1516
fun beComponent(component: Component) = Matcher<Element> { element ->
@@ -189,19 +190,14 @@ fun haveCheckboxChecked(
189190
}
190191

191192
val Element.descr: String
192-
get() {
193-
val selector = if (this.id().isNotEmpty()) {
194-
"id=\"${this.id()}\""
195-
} else if (this.classNames().isNotEmpty()) {
196-
"class=\"${this.classNames().first()}\" ..."
197-
} else {
198-
""
199-
}
200-
return "<${this.tag().name} $selector>" +
201-
this.text().take(32) +
202-
("...".takeIf { this.text().length > 32 } ?: "") +
203-
"</${this.tag().name}>"
204-
}
193+
get() =
194+
elementDescr(
195+
this.tag().name,
196+
this.id(),
197+
this.classNames().firstOrNull(),
198+
this.attr("name"),
199+
this.text()
200+
)
205201

206202
infix fun Element.shouldHaveComponent(component: Component): Element {
207203
this should haveComponent(component)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package pro.qyoga.tests.platform.html
2+
3+
4+
fun elementDescr(
5+
tag: String,
6+
idValue: String?,
7+
elClassValue: String?,
8+
nameValue: String?,
9+
text: String?
10+
): String {
11+
val id = idValue?.takeIf { it.isNotBlank() }
12+
?.let { "id=\"$it\"" } ?: ""
13+
val elClass = elClassValue?.takeIf { it.isNotBlank() }
14+
?.let { "class=\"${it.split(" ").first()} ...\"" } ?: ""
15+
val name = nameValue?.takeIf { it.isNotBlank() }
16+
?.let { "name=\"$it\"" } ?: ""
17+
18+
return "<$tag $id $elClass $name>" +
19+
(text?.take(16)?.let { "$it ..." } ?: "") +
20+
"</$tag>"
21+
}

e2e-tests/src/test/kotlin/pro/qyoga/tests/assertions/SelenideElement.kt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package pro.qyoga.tests.assertions
33
import com.codeborne.selenide.SelenideElement
44
import io.kotest.matchers.Matcher
55
import io.kotest.matchers.MatcherResult
6+
import pro.qyoga.tests.platform.html.elementDescr
67
import io.kotest.matchers.should as koshould
78
import io.kotest.matchers.shouldNot as koshouldNot
89

@@ -32,14 +33,11 @@ fun SelenideElement.shouldNotBeEmptyInput() {
3233
}
3334

3435
fun SelenideElement.descr(): String {
35-
val id = this.getAttribute("id")
36-
?.takeIf { it.isNotBlank() }
37-
?.let { "id=\"$it\"" } ?: ""
38-
val elClass = this.getAttribute("class")
39-
?.takeIf { it.isNotBlank() }
40-
?.let { "class=\"${it.split(" ").first()} ...\"" } ?: ""
41-
val name = this.getAttribute("name")
42-
?.takeIf { it.isNotBlank() }
43-
?.let { "name=\"$it\"" } ?: ""
44-
return "<${this.tagName} $id $elClass $name/>"
36+
return elementDescr(
37+
this.tagName,
38+
getAttribute("id"),
39+
getAttribute("class"),
40+
getAttribute("name"),
41+
this.text
42+
)
4543
}

e2e-tests/src/test/kotlin/pro/qyoga/tests/scenarios/CreateClientScenarioTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ class CreateClientScenarioTest : QYogaE2EBaseTest() {
4949
CreateClientForm.shouldBeEmpty()
5050
}
5151

52-
}
52+
}

0 commit comments

Comments
 (0)