MCPcopy
hub / github.com/PostHog/posthog / test_elements_to_string

Method test_elements_to_string

posthog/test/test_element_model.py:6–59  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4
5class TestElement(ClickhouseTestMixin, BaseTest):
6 def test_elements_to_string(self) -> None:
7 self.maxDiff = None
8 elements_string = elements_to_string(
9 elements=[
10 Element(
11 tag_name="a",
12 href="/a-url",
13 attr_class=["small"],
14 text="bla bla",
15 attributes={
16 "prop": "value",
17 "number": 33,
18 "data-attr": 'something " that; could mess up',
19 "style": "min-height: 100vh;",
20 },
21 nth_child=1,
22 nth_of_type=0,
23 ),
24 Element(tag_name="button", attr_class=["btn", "btn-primary"], nth_child=0, nth_of_type=0),
25 Element(tag_name="div", nth_child=0, nth_of_type=0),
26 Element(tag_name="div", nth_child=0, nth_of_type=0, attr_id="nested"),
27 ]
28 )
29
30 self.assertEqual(
31 elements_string,
32 ";".join(
33 [
34 r'a.small:data-attr="something \" that; could mess up"href="/a-url"nth-child="1"nth-of-type="0"number="33"prop="value"style="min-height: 100vh;"text="bla bla"',
35 'button.btn.btn-primary:nth-child="0"nth-of-type="0"',
36 'div:nth-child="0"nth-of-type="0"',
37 'div:attr_id="nested"nth-child="0"nth-of-type="0"',
38 ]
39 ),
40 )
41
42 elements = chain_to_elements(elements_string)
43 self.assertEqual(elements[0].tag_name, "a")
44 self.assertEqual(elements[0].href, "/a-url")
45 self.assertEqual(elements[0].attr_class, ["small"])
46 self.assertDictEqual(
47 elements[0].attributes,
48 {
49 "prop": "value",
50 "number": "33",
51 "data-attr": r"something \" that; could mess up",
52 "style": "min-height: 100vh;",
53 },
54 )
55 self.assertEqual(elements[0].nth_child, 1)
56 self.assertEqual(elements[0].nth_of_type, 0)
57
58 self.assertEqual(elements[1].attr_class, ["btn", "btn-primary"])
59 self.assertEqual(elements[3].attr_id, "nested")
60
61 def test_broken_class_names(self):
62 elements = chain_to_elements("a........small")

Callers

nothing calls this directly

Calls 4

elements_to_stringFunction · 0.90
ElementClass · 0.90
chain_to_elementsFunction · 0.90
joinMethod · 0.80

Tested by

no test coverage detected