docusaurus-plugin-generate-schema-docs 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -6
- package/__tests__/ExampleDataLayer.test.js +78 -155
- package/__tests__/__fixtures__/static/schemas/add-to-cart-event.json +4 -15
- package/__tests__/__fixtures__/static/schemas/choice-event.json +72 -0
- package/__tests__/__fixtures__/static/schemas/components/dataLayer.json +52 -54
- package/__tests__/__fixtures__/static/schemas/components/product.json +124 -210
- package/__tests__/__fixtures__/static/schemas/nested/child-event.json +10 -0
- package/__tests__/__fixtures__/static/schemas/nested/grandchild-a.json +9 -0
- package/__tests__/__fixtures__/static/schemas/nested/grandchild-b.json +9 -0
- package/__tests__/__fixtures__/static/schemas/nested/parent-event.json +7 -0
- package/__tests__/__fixtures__/static/schemas/root-any-of-event.json +34 -0
- package/__tests__/__fixtures__/static/schemas/root-choice-event.json +36 -0
- package/__tests__/__fixtures__/validateSchemas/circular-schema.json +6 -6
- package/__tests__/__fixtures__/validateSchemas/components/referenced.json +9 -7
- package/__tests__/__fixtures__/validateSchemas/invalid-example-schema.json +7 -7
- package/__tests__/__fixtures__/validateSchemas/main-schema-with-missing-ref.json +7 -7
- package/__tests__/__fixtures__/validateSchemas/main-schema-with-ref.json +7 -7
- package/__tests__/__fixtures__/validateSchemas/no-example-schema.json +11 -11
- package/__tests__/__fixtures__/validateSchemas/schema-A.json +5 -5
- package/__tests__/__fixtures__/validateSchemas/schema-B.json +5 -5
- package/__tests__/__fixtures__/validateSchemas/valid-schema.json +7 -7
- package/__tests__/__fixtures_versioned__/static/schemas/1.1.1/add-to-cart-event.json +44 -0
- package/__tests__/__fixtures_versioned__/static/schemas/1.1.1/components/dataLayer.json +56 -0
- package/__tests__/__fixtures_versioned__/static/schemas/1.1.1/components/product.json +125 -0
- package/__tests__/__fixtures_versioned__/static/schemas/next/add-to-cart-event.json +44 -0
- package/__tests__/__fixtures_versioned__/static/schemas/next/components/dataLayer.json +56 -0
- package/__tests__/__fixtures_versioned__/static/schemas/next/components/product.json +125 -0
- package/__tests__/__fixtures_versioned__/versions.json +1 -0
- package/__tests__/__snapshots__/ExampleDataLayer.test.js.snap +117 -0
- package/__tests__/__snapshots__/generateEventDocs.nested.test.js.snap +92 -0
- package/__tests__/__snapshots__/generateEventDocs.test.js.snap +113 -15
- package/__tests__/__snapshots__/generateEventDocs.versioned.test.js.snap +53 -0
- package/__tests__/components/FoldableRows.test.js +330 -0
- package/__tests__/components/PropertiesTable.test.js +31 -14
- package/__tests__/components/PropertyRow.test.js +471 -51
- package/__tests__/components/SchemaJsonViewer.test.js +23 -19
- package/__tests__/components/SchemaRows.test.js +96 -66
- package/__tests__/components/SchemaViewer.test.js +34 -17
- package/__tests__/components/TableHeader.test.js +12 -12
- package/__tests__/generateEventDocs.nested.test.js +80 -0
- package/__tests__/generateEventDocs.test.js +77 -71
- package/__tests__/generateEventDocs.versioned.test.js +69 -0
- package/__tests__/helpers/buildExampleFromSchema.test.js +160 -160
- package/__tests__/helpers/file-system.test.js +44 -0
- package/__tests__/helpers/getConstraints.test.js +48 -48
- package/__tests__/helpers/loadSchema.test.js +11 -5
- package/__tests__/helpers/path-helpers.test.js +34 -0
- package/__tests__/helpers/processSchema.test.js +42 -22
- package/__tests__/helpers/schema-processing.test.js +82 -0
- package/__tests__/helpers/schemaToExamples.test.js +56 -0
- package/__tests__/helpers/schemaToTableData.filtering.test.js +65 -0
- package/__tests__/helpers/schemaToTableData.hierarchicalLines.test.js +539 -0
- package/__tests__/helpers/schemaToTableData.test.js +222 -0
- package/__tests__/helpers/update-schema-ids.test.js +107 -0
- package/__tests__/update-schema-ids.test.js +39 -0
- package/__tests__/validateSchemas.test.js +125 -88
- package/components/ExampleDataLayer.js +59 -28
- package/components/FoldableRows.js +164 -0
- package/components/PropertiesTable.js +10 -7
- package/components/PropertyRow.js +169 -60
- package/components/SchemaJsonViewer.js +6 -6
- package/components/SchemaRows.css +236 -14
- package/components/SchemaRows.js +24 -41
- package/components/SchemaViewer.js +19 -13
- package/components/TableHeader.js +12 -12
- package/generateEventDocs.js +141 -61
- package/helpers/buildExampleFromSchema.js +58 -72
- package/helpers/choice-index-template.js +22 -0
- package/helpers/file-system.js +32 -0
- package/helpers/getConstraints.js +43 -44
- package/helpers/loadSchema.js +2 -2
- package/helpers/path-helpers.js +22 -0
- package/helpers/processSchema.js +19 -19
- package/helpers/{mdx-template.js → schema-doc-template.js} +12 -12
- package/helpers/schema-processing.js +75 -0
- package/helpers/schemaToExamples.js +99 -0
- package/helpers/schemaToTableData.js +311 -0
- package/helpers/update-schema-ids.js +47 -0
- package/index.js +143 -54
- package/package.json +1 -1
- package/validateSchemas.js +54 -71
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
|
2
2
|
|
|
3
|
-
exports[`generateEventDocs should generate documentation correctly
|
|
3
|
+
exports[`generateEventDocs (non-versioned) should generate documentation correctly 1`] = `
|
|
4
4
|
"---
|
|
5
5
|
title: Add to Cart Event
|
|
6
6
|
description: "An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications."
|
|
7
7
|
sidebar_label: Add to Cart Event
|
|
8
|
-
custom_edit_url: https://github.com/test-org/test-project/edit/main/
|
|
8
|
+
custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures__/static/schemas/add-to-cart-event.json
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
import SchemaViewer from '@theme/SchemaViewer';
|
|
@@ -26,28 +26,126 @@ An add_to_cart event fires when a user adds one or more items to their shopping
|
|
|
26
26
|
"
|
|
27
27
|
`;
|
|
28
28
|
|
|
29
|
-
exports[`generateEventDocs should generate documentation
|
|
29
|
+
exports[`generateEventDocs (non-versioned) should generate documentation correctly 2`] = `
|
|
30
30
|
"---
|
|
31
|
-
title:
|
|
32
|
-
description: "An
|
|
33
|
-
sidebar_label:
|
|
34
|
-
custom_edit_url: https://github.com/test-org/test-project/edit/main/
|
|
31
|
+
title: Choice Event
|
|
32
|
+
description: "An example event that uses oneOf and anyOf."
|
|
33
|
+
sidebar_label: Choice Event
|
|
34
|
+
custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures__/static/schemas/choice-event.json
|
|
35
35
|
---
|
|
36
36
|
|
|
37
37
|
import SchemaViewer from '@theme/SchemaViewer';
|
|
38
38
|
import SchemaJsonViewer from '@theme/SchemaJsonViewer';
|
|
39
|
-
import TopPartial from '@site/docs/partials/add-to-cart-event.mdx';
|
|
40
|
-
import BottomPartial from '@site/docs/partials/add-to-cart-event_bottom.mdx';
|
|
41
39
|
|
|
42
|
-
# Add to Cart Event
|
|
43
40
|
|
|
44
|
-
An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.
|
|
45
41
|
|
|
46
|
-
|
|
42
|
+
# Choice Event
|
|
43
|
+
|
|
44
|
+
An example event that uses oneOf and anyOf.
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
<SchemaViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/1.2.0/choice-event.json","title":"Choice Event","description":"An example event that uses oneOf and anyOf.","type":"object","required":["event","user_id","payment_method"],"properties":{"event":{"type":"string","const":"one_of_event"},"user_id":{"description":"The user's ID.","oneOf":[{"type":"string","title":"User ID as String","description":"The user's ID as a string.","examples":["user-123"]},{"type":"integer","title":"User ID as Integer","description":"The user's ID as an integer.","examples":[123]}]},"payment_method":{"description":"The user's payment method.","type":"object","anyOf":[{"title":"Credit Card","properties":{"payment_type":{"type":"string","enum":["credit_card","debit_card"],"examples":["credit_card"]},"card_number":{"type":"string","examples":["1234-5678-9012-3456"]},"expiry_date":{"type":"string","examples":["12/26"]}},"required":["card_number","expiry_date"]},{"title":"PayPal","type":"object","properties":{"payment_type":{"type":"string","const":"paypal"},"email":{"type":"string","format":"email","examples":["test@example.com"]}},"required":["email"]}]}}}} />
|
|
49
|
+
<SchemaJsonViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/1.2.0/choice-event.json","title":"Choice Event","description":"An example event that uses oneOf and anyOf.","type":"object","properties":{"event":{"type":"string","const":"one_of_event"},"user_id":{"description":"The user's ID.","oneOf":[{"type":"string","title":"User ID as String","description":"The user's ID as a string.","examples":["user-123"]},{"type":"integer","title":"User ID as Integer","description":"The user's ID as an integer.","examples":[123]}]},"payment_method":{"description":"The user's payment method.","type":"object","anyOf":[{"title":"Credit Card","properties":{"payment_type":{"type":"string","enum":["credit_card","debit_card"],"examples":["credit_card"]},"card_number":{"type":"string","examples":["1234-5678-9012-3456"]},"expiry_date":{"type":"string","examples":["12/26"]}},"required":["card_number","expiry_date"]},{"title":"PayPal","type":"object","properties":{"payment_type":{"type":"string","const":"paypal"},"email":{"type":"string","format":"email","examples":["test@example.com"]}},"required":["email"]}]}},"required":["event","user_id","payment_method"]}} />
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
"
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
exports[`generateEventDocs (non-versioned) should generate documentation correctly 3`] = `
|
|
56
|
+
"---
|
|
57
|
+
title: Root AnyOf Event
|
|
58
|
+
description: "An example event that has anyOf at the root level."
|
|
59
|
+
sidebar_label: Root AnyOf Event
|
|
60
|
+
custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures__/static/schemas/root-any-of-event.json
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
import SchemaViewer from '@theme/SchemaViewer';
|
|
64
|
+
import SchemaJsonViewer from '@theme/SchemaJsonViewer';
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# Root AnyOf Event
|
|
69
|
+
|
|
70
|
+
An example event that has anyOf at the root level.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
<SchemaViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/1.2.0/root-any-of-event.json","title":"Root AnyOf Event","description":"An example event that has anyOf at the root level.","type":"object","anyOf":[{"title":"Has Param C","properties":{"param_c":{"type":"string","examples":["example_c"],"description":"This is the description for Param C."}}},{"title":"Has Param D","properties":{"param_d":{"type":"boolean","examples":[true]}}}],"properties":{"event":{"type":"string","const":"any_of_event"}}}} />
|
|
75
|
+
<SchemaJsonViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/1.2.0/root-any-of-event.json","title":"Root AnyOf Event","description":"An example event that has anyOf at the root level.","type":"object","properties":{"event":{"type":"string","const":"any_of_event"}},"anyOf":[{"title":"Has Param C","properties":{"param_c":{"type":"string","examples":["example_c"],"description":"This is the description for Param C."}}},{"title":"Has Param D","properties":{"param_d":{"type":"boolean","examples":[true]}}}]}} />
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
"
|
|
79
|
+
`;
|
|
80
|
+
|
|
81
|
+
exports[`generateEventDocs (non-versioned) should generate documentation correctly 4`] = `
|
|
82
|
+
"---
|
|
83
|
+
title: Root Choice Event
|
|
84
|
+
description: "An example event that has oneOf at the root level."
|
|
85
|
+
---
|
|
86
|
+
import SchemaJsonViewer from '@theme/SchemaJsonViewer';
|
|
87
|
+
|
|
88
|
+
# Root Choice Event
|
|
89
|
+
|
|
90
|
+
An example event that has oneOf at the root level.
|
|
91
|
+
|
|
92
|
+
Please select one of the following options:
|
|
93
|
+
|
|
94
|
+
- [Option A](./option-a)
|
|
95
|
+
- [Option B](./option-b)
|
|
96
|
+
|
|
97
|
+
<SchemaJsonViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://example.com/root-choice-event.schema.json","title":"Root Choice Event","description":"An example event that has oneOf at the root level.","oneOf":[{"title":"Option A","type":"object","properties":{"event":{"type":"string","const":"option_a"},"param_a":{"type":"string","examples":["example_a"]}}},{"title":"Option B","type":"object","properties":{"event":{"type":"string","const":"option_b"},"param_b":{"type":"integer","examples":[123]}}}]}} />
|
|
98
|
+
"
|
|
99
|
+
`;
|
|
100
|
+
|
|
101
|
+
exports[`generateEventDocs (non-versioned) should generate documentation correctly 5`] = `
|
|
102
|
+
"---
|
|
103
|
+
title: Option A
|
|
104
|
+
description: "An example event that has oneOf at the root level."
|
|
105
|
+
sidebar_label: Option A
|
|
106
|
+
custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures__/docs/root-choice-event/01-option-a.json
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
import SchemaViewer from '@theme/SchemaViewer';
|
|
110
|
+
import SchemaJsonViewer from '@theme/SchemaJsonViewer';
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
# Option A
|
|
115
|
+
|
|
116
|
+
An example event that has oneOf at the root level.
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
<SchemaViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://example.com/root-choice-event.schema.json#option-a","title":"Option A","description":"An example event that has oneOf at the root level.","type":"object","properties":{"event":{"type":"string","const":"option_a"},"param_a":{"type":"string","examples":["example_a"]}}}} />
|
|
121
|
+
<SchemaJsonViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://example.com/root-choice-event.schema.json#option-a","title":"Option A","description":"An example event that has oneOf at the root level.","type":"object","properties":{"event":{"type":"string","const":"option_a"},"param_a":{"type":"string","examples":["example_a"]}}}} />
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
"
|
|
125
|
+
`;
|
|
126
|
+
|
|
127
|
+
exports[`generateEventDocs (non-versioned) should generate documentation correctly 6`] = `
|
|
128
|
+
"---
|
|
129
|
+
title: Option B
|
|
130
|
+
description: "An example event that has oneOf at the root level."
|
|
131
|
+
sidebar_label: Option B
|
|
132
|
+
custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures__/docs/root-choice-event/02-option-b.json
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
import SchemaViewer from '@theme/SchemaViewer';
|
|
136
|
+
import SchemaJsonViewer from '@theme/SchemaJsonViewer';
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
# Option B
|
|
141
|
+
|
|
142
|
+
An example event that has oneOf at the root level.
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
<SchemaViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://example.com/root-choice-event.schema.json#option-b","title":"Option B","description":"An example event that has oneOf at the root level.","type":"object","properties":{"event":{"type":"string","const":"option_b"},"param_b":{"type":"integer","examples":[123]}}}} />
|
|
147
|
+
<SchemaJsonViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://example.com/root-choice-event.schema.json#option-b","title":"Option B","description":"An example event that has oneOf at the root level.","type":"object","properties":{"event":{"type":"string","const":"option_b"},"param_b":{"type":"integer","examples":[123]}}}} />
|
|
47
148
|
|
|
48
|
-
<SchemaViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/add-to-cart-event.json","title":"Add to Cart Event","description":"An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.","type":"object","required":["event"],"$defs":{"strictObject":{"type":"object","propertyNames":{"maxLength":40,"pattern":"^[a-z0-9_]+$"},"additionalProperties":{"anyOf":[{"$ref":"#/allOf/0/$defs/strictObject"},{"type":"array","items":{"$ref":"#/allOf/0/$defs/strictObject"}},{"not":{"type":"object"}}]}}},"$ref":"#/allOf/0/$defs/strictObject","properties":{"event":{"type":"string","const":"add_to_cart","description":"The name of the event indicating a add_to_cart has occurred."},"ecommerce":{"type":"object","description":"Ecommerce related data for the purchase event.","required":["currency","items"],"x-gtm-clear":true,"properties":{"value":{"type":"number","description":"The monetary value of the event. Set value to the sum of (price * quantity) for all items in items.","examples":[30.03,99.99,45.5]},"currency":{"type":"string","description":"The currency of the items in ISO 4217 three-letter format. Required when value is set.","examples":["USD","EUR","GBP"]},"items":{"type":"array","description":"The products added to the cart.","minItems":1,"items":{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/components/product.json","title":"A Product","description":"A product object representing an item for use within a purchase event, based on Google Analytics 4 ecommerce event specifications.","type":"object","required":[],"properties":{"item_id":{"type":"string","description":"The ID of the item. Either item_id or item_name is required.","examples":["SKU_12345","PROD_98765"]},"item_name":{"type":"string","description":"The name of the item. Either item_id or item_name is required.","examples":["Stan and Friends Tee","Blue Running Shoes"]},"affiliation":{"type":"string","description":"A product affiliation to indicate a supplier or store. Note: affiliation is only available at the item level.","examples":["Google Merchandise Store","Nike Store"]},"coupon":{"type":"string","description":"The coupon name/code associated with the item. Coupon parameters at event and item levels are independent.","examples":["SUMMER_FUN","WELCOME20","SAVE10"]},"discount":{"type":"number","description":"The monetary value of the discount per unit applied to the item.","examples":[2.22,5,10.5]},"index":{"type":"number","description":"The index or position of the item in a list.","examples":[0,1,2]},"item_brand":{"type":"string","description":"The brand of the item.","examples":["Google","Nike","Adidas"]},"item_category":{"type":"string","description":"The category of the item. If used as part of a category hierarchy or taxonomy, this is the first category.","examples":["Apparel","Footwear","Electronics"]},"item_category2":{"type":"string","description":"The second category hierarchy or additional taxonomy of the item.","examples":["Adult","Women","Men"]},"item_category3":{"type":"string","description":"The third category hierarchy or additional taxonomy of the item.","examples":["Shirts","Shoes","Boots"]},"item_category4":{"type":"string","description":"The fourth category hierarchy or additional taxonomy of the item.","examples":["Crew","Running","Casual"]},"item_category5":{"type":"string","description":"The fifth category hierarchy or additional taxonomy of the item.","examples":["Short sleeve","Long distance","Lightweight"]},"item_list_id":{"type":"string","description":"The ID of the list in which the item was presented to the user. If set, item_list_id at the event level is ignored. If not set, item_list_id at the event level is used if available.","examples":["related_products","search_results","recommendations"]},"item_list_name":{"type":"string","description":"The name of the list in which the item was presented to the user. If set, item_list_name at the event level is ignored. If not set, item_list_name at the event level is used if available.","examples":["Related Products","Search Results","Recommended Items"]},"item_variant":{"type":"string","description":"The item variant or unique code or description for additional item details/options.","examples":["green","Blue Size 10","M-Black"]},"location_id":{"type":"string","description":"The physical location associated with the item, such as the location of a brick-and-mortar store. It is recommended to use the Google Place ID that corresponds to the associated item. A custom location ID can also be used. Note: location_id is only available at the item level.","examples":["ChIJIQBpAG2ahYAR_6128GcTUEo","store_123","location_sf"]},"price":{"type":"number","description":"The price of the item in the specified currency unit. If a discount is applied to the item, set price to the reduced per-unit price and provide the per-unit price discount in the discount parameter.","examples":[10.01,21.01,89.99]},"quantity":{"type":"number","description":"The item quantity. If not set, quantity is set to 1.","examples":[1,2,3]},"promotion_id":{"type":"string","description":"The ID of the promotion associated with the item.","examples":["P_12345","PROMO_001"]},"promotion_name":{"type":"string","description":"The name of the promotion associated with the item.","examples":["Summer Sale","Black Friday","Flash Deal"]},"creative_name":{"type":"string","description":"The name of the promotion creative.","examples":["summer_banner2","holiday_email_v1"]},"creative_slot":{"type":"string","description":"The name of the creative slot associated with the item.","examples":["featured_app_1","top_banner","sidebar"]},"google_business_vertical":{"type":"string","description":"The business vertical for the item (e.g., 'retail').","examples":["retail","ecommerce"]}}}}}},"user_data":{"type":"object","description":"User related data.","x-gtm-clear":true}}}} />
|
|
49
|
-
<SchemaJsonViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/add-to-cart-event.json","title":"Add to Cart Event","description":"An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.","type":"object","allOf":[{"$ref":"./components/dataLayer.json"}],"properties":{"event":{"type":"string","const":"add_to_cart","description":"The name of the event indicating a add_to_cart has occurred."},"ecommerce":{"type":"object","description":"Ecommerce related data for the purchase event.","properties":{"value":{"type":"number","description":"The monetary value of the event. Set value to the sum of (price * quantity) for all items in items.","examples":[30.03,99.99,45.5]},"currency":{"type":"string","description":"The currency of the items in ISO 4217 three-letter format. Required when value is set.","examples":["USD","EUR","GBP"]},"items":{"type":"array","description":"The products added to the cart.","minItems":1,"items":{"$ref":"./components/product.json"}}},"required":["currency","items"]}}}} />
|
|
50
149
|
|
|
51
|
-
<BottomPartial />
|
|
52
150
|
"
|
|
53
151
|
`;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
|
2
|
+
|
|
3
|
+
exports[`generateEventDocs (versioned) should generate documentation for "current" version 1`] = `
|
|
4
|
+
"---
|
|
5
|
+
title: Add to Cart Event
|
|
6
|
+
description: "An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications."
|
|
7
|
+
sidebar_label: Add to Cart Event
|
|
8
|
+
custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures_versioned__/static/schemas/next/add-to-cart-event.json
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
import SchemaViewer from '@theme/SchemaViewer';
|
|
12
|
+
import SchemaJsonViewer from '@theme/SchemaJsonViewer';
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# Add to Cart Event
|
|
17
|
+
|
|
18
|
+
An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
<SchemaViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/add-to-cart-event.json","title":"Add to Cart Event","description":"An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.","type":"object","required":["event"],"$defs":{"strictObject":{"type":"object","propertyNames":{"maxLength":40,"pattern":"^[a-z0-9_]+$"},"additionalProperties":{"anyOf":[{"$ref":"#/allOf/0/$defs/strictObject"},{"type":"array","items":{"$ref":"#/allOf/0/$defs/strictObject"}},{"not":{"type":"object"}}]}}},"$ref":"#/allOf/0/$defs/strictObject","properties":{"event":{"type":"string","const":"add_to_cart","description":"The name of the event indicating a add_to_cart has occurred."},"ecommerce":{"type":"object","description":"Ecommerce related data for the purchase event.","required":["currency","items"],"x-gtm-clear":true,"properties":{"value":{"type":"number","description":"The monetary value of the event. Set value to the sum of (price * quantity) for all items in items.","examples":[30.03,99.99,45.5]},"currency":{"type":"string","description":"The currency of the items in ISO 4217 three-letter format. Required when value is set.","examples":["USD","EUR","GBP"]},"items":{"type":"array","description":"The products added to the cart.","minItems":1,"items":{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/components/product.json","title":"A Product","description":"A product object representing an item for use within a purchase event, based on Google Analytics 4 ecommerce event specifications.","type":"object","required":[],"properties":{"item_id":{"type":"string","description":"The ID of the item. Either item_id or item_name is required.","examples":["SKU_12345","PROD_98765"]},"item_name":{"type":"string","description":"The name of the item. Either item_id or item_name is required.","examples":["Stan and Friends Tee","Blue Running Shoes"]},"affiliation":{"type":"string","description":"A product affiliation to indicate a supplier or store. Note: affiliation is only available at the item level.","examples":["Google Merchandise Store","Nike Store"]},"coupon":{"type":"string","description":"The coupon name/code associated with the item. Coupon parameters at event and item levels are independent.","examples":["SUMMER_FUN","WELCOME20","SAVE10"]},"discount":{"type":"number","description":"The monetary value of the discount per unit applied to the item.","examples":[2.22,5,10.5]},"index":{"type":"number","description":"The index or position of the item in a list.","examples":[0,1,2]},"item_brand":{"type":"string","description":"The brand of the item.","examples":["Google","Nike","Adidas"]},"item_category":{"type":"string","description":"The category of the item. If used as part of a category hierarchy or taxonomy, this is the first category.","examples":["Apparel","Footwear","Electronics"]},"item_category2":{"type":"string","description":"The second category hierarchy or additional taxonomy of the item.","examples":["Adult","Women","Men"]},"item_category3":{"type":"string","description":"The third category hierarchy or additional taxonomy of the item.","examples":["Shirts","Shoes","Boots"]},"item_category4":{"type":"string","description":"The fourth category hierarchy or additional taxonomy of the item.","examples":["Crew","Running","Casual"]},"item_category5":{"type":"string","description":"The fifth category hierarchy or additional taxonomy of the item.","examples":["Short sleeve","Long distance","Lightweight"]},"item_list_id":{"type":"string","description":"The ID of the list in which the item was presented to the user. If set, item_list_id at the event level is ignored. If not set, item_list_id at the event level is used if available.","examples":["related_products","search_results","recommendations"]},"item_list_name":{"type":"string","description":"The name of the list in which the item was presented to the user. If set, item_list_name at the event level is ignored. If not set, item_list_name at the event level is used if available.","examples":["Related Products","Search Results","Recommended Items"]},"item_variant":{"type":"string","description":"The item variant or unique code or description for additional item details/options.","examples":["green","Blue Size 10","M-Black"]},"location_id":{"type":"string","description":"The physical location associated with the item, such as the location of a brick-and-mortar store. It is recommended to use the Google Place ID that corresponds to the associated item. A custom location ID can also be used. Note: location_id is only available at the item level.","examples":["ChIJIQBpAG2ahYAR_6128GcTUEo","store_123","location_sf"]},"price":{"type":"number","description":"The price of the item in the specified currency unit. If a discount is applied to the item, set price to the reduced per-unit price and provide the per-unit price discount in the discount parameter.","examples":[10.01,21.01,89.99]},"quantity":{"type":"number","description":"The item quantity. If not set, quantity is set to 1.","examples":[1,2,3]},"promotion_id":{"type":"string","description":"The ID of the promotion associated with the item.","examples":["P_12345","PROMO_001"]},"promotion_name":{"type":"string","description":"The name of the promotion associated with the item.","examples":["Summer Sale","Black Friday","Flash Deal"]},"creative_name":{"type":"string","description":"The name of the promotion creative.","examples":["summer_banner2","holiday_email_v1"]},"creative_slot":{"type":"string","description":"The name of the creative slot associated with the item.","examples":["featured_app_1","top_banner","sidebar"]},"google_business_vertical":{"type":"string","description":"The business vertical for the item (e.g., 'retail').","examples":["retail","ecommerce"]}}}}}},"user_data":{"type":"object","description":"User related data.","x-gtm-clear":true}}}} />
|
|
23
|
+
<SchemaJsonViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/next/add-to-cart-event.json","title":"Add to Cart Event","description":"An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.","type":"object","allOf":[{"$ref":"./components/dataLayer.json"}],"properties":{"event":{"type":"string","const":"add_to_cart","description":"The name of the event indicating a add_to_cart has occurred."},"ecommerce":{"type":"object","description":"Ecommerce related data for the purchase event.","properties":{"value":{"type":"number","description":"The monetary value of the event. Set value to the sum of (price * quantity) for all items in items.","examples":[30.03,99.99,45.5]},"currency":{"type":"string","description":"The currency of the items in ISO 4217 three-letter format. Required when value is set.","examples":["USD","EUR","GBP"]},"items":{"type":"array","description":"The products added to the cart.","minItems":1,"items":{"$ref":"./components/product.json"}}},"required":["currency","items"]}}}} />
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
"
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
exports[`generateEventDocs (versioned) should generate documentation for a specific version 1`] = `
|
|
30
|
+
"---
|
|
31
|
+
title: Add to Cart Event
|
|
32
|
+
description: "An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications."
|
|
33
|
+
sidebar_label: Add to Cart Event
|
|
34
|
+
custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures_versioned__/static/schemas/1.1.1/add-to-cart-event.json
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
import SchemaViewer from '@theme/SchemaViewer';
|
|
38
|
+
import SchemaJsonViewer from '@theme/SchemaJsonViewer';
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# Add to Cart Event
|
|
43
|
+
|
|
44
|
+
An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
<SchemaViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/add-to-cart-event.json","title":"Add to Cart Event","description":"An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.","type":"object","required":["event"],"$defs":{"strictObject":{"type":"object","propertyNames":{"maxLength":40,"pattern":"^[a-z0-9_]+$"},"additionalProperties":{"anyOf":[{"$ref":"#/allOf/0/$defs/strictObject"},{"type":"array","items":{"$ref":"#/allOf/0/$defs/strictObject"}},{"not":{"type":"object"}}]}}},"$ref":"#/allOf/0/$defs/strictObject","properties":{"event":{"type":"string","const":"add_to_cart","description":"The name of the event indicating a add_to_cart has occurred."},"ecommerce":{"type":"object","description":"Ecommerce related data for the purchase event.","required":["currency","items"],"x-gtm-clear":true,"properties":{"value":{"type":"number","description":"The monetary value of the event. Set value to the sum of (price * quantity) for all items in items.","examples":[30.03,99.99,45.5]},"currency":{"type":"string","description":"The currency of the items in ISO 4217 three-letter format. Required when value is set.","examples":["USD","EUR","GBP"]},"items":{"type":"array","description":"The products added to the cart.","minItems":1,"items":{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/components/product.json","title":"A Product","description":"A product object representing an item for use within a purchase event, based on Google Analytics 4 ecommerce event specifications.","type":"object","required":[],"properties":{"item_id":{"type":"string","description":"The ID of the item. Either item_id or item_name is required.","examples":["SKU_12345","PROD_98765"]},"item_name":{"type":"string","description":"The name of the item. Either item_id or item_name is required.","examples":["Stan and Friends Tee","Blue Running Shoes"]},"affiliation":{"type":"string","description":"A product affiliation to indicate a supplier or store. Note: affiliation is only available at the item level.","examples":["Google Merchandise Store","Nike Store"]},"coupon":{"type":"string","description":"The coupon name/code associated with the item. Coupon parameters at event and item levels are independent.","examples":["SUMMER_FUN","WELCOME20","SAVE10"]},"discount":{"type":"number","description":"The monetary value of the discount per unit applied to the item.","examples":[2.22,5,10.5]},"index":{"type":"number","description":"The index or position of the item in a list.","examples":[0,1,2]},"item_brand":{"type":"string","description":"The brand of the item.","examples":["Google","Nike","Adidas"]},"item_category":{"type":"string","description":"The category of the item. If used as part of a category hierarchy or taxonomy, this is the first category.","examples":["Apparel","Footwear","Electronics"]},"item_category2":{"type":"string","description":"The second category hierarchy or additional taxonomy of the item.","examples":["Adult","Women","Men"]},"item_category3":{"type":"string","description":"The third category hierarchy or additional taxonomy of the item.","examples":["Shirts","Shoes","Boots"]},"item_category4":{"type":"string","description":"The fourth category hierarchy or additional taxonomy of the item.","examples":["Crew","Running","Casual"]},"item_category5":{"type":"string","description":"The fifth category hierarchy or additional taxonomy of the item.","examples":["Short sleeve","Long distance","Lightweight"]},"item_list_id":{"type":"string","description":"The ID of the list in which the item was presented to the user. If set, item_list_id at the event level is ignored. If not set, item_list_id at the event level is used if available.","examples":["related_products","search_results","recommendations"]},"item_list_name":{"type":"string","description":"The name of the list in which the item was presented to the user. If set, item_list_name at the event level is ignored. If not set, item_list_name at the event level is used if available.","examples":["Related Products","Search Results","Recommended Items"]},"item_variant":{"type":"string","description":"The item variant or unique code or description for additional item details/options.","examples":["green","Blue Size 10","M-Black"]},"location_id":{"type":"string","description":"The physical location associated with the item, such as the location of a brick-and-mortar store. It is recommended to use the Google Place ID that corresponds to the associated item. A custom location ID can also be used. Note: location_id is only available at the item level.","examples":["ChIJIQBpAG2ahYAR_6128GcTUEo","store_123","location_sf"]},"price":{"type":"number","description":"The price of the item in the specified currency unit. If a discount is applied to the item, set price to the reduced per-unit price and provide the per-unit price discount in the discount parameter.","examples":[10.01,21.01,89.99]},"quantity":{"type":"number","description":"The item quantity. If not set, quantity is set to 1.","examples":[1,2,3]},"promotion_id":{"type":"string","description":"The ID of the promotion associated with the item.","examples":["P_12345","PROMO_001"]},"promotion_name":{"type":"string","description":"The name of the promotion associated with the item.","examples":["Summer Sale","Black Friday","Flash Deal"]},"creative_name":{"type":"string","description":"The name of the promotion creative.","examples":["summer_banner2","holiday_email_v1"]},"creative_slot":{"type":"string","description":"The name of the creative slot associated with the item.","examples":["featured_app_1","top_banner","sidebar"]},"google_business_vertical":{"type":"string","description":"The business vertical for the item (e.g., 'retail').","examples":["retail","ecommerce"]}}}}}},"user_data":{"type":"object","description":"User related data.","x-gtm-clear":true}}}} />
|
|
49
|
+
<SchemaJsonViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/1.1.1/add-to-cart-event.json","title":"Add to Cart Event","description":"An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.","type":"object","allOf":[{"$ref":"./components/dataLayer.json"}],"properties":{"event":{"type":"string","const":"add_to_cart","description":"The name of the event indicating a add_to_cart has occurred."},"ecommerce":{"type":"object","description":"Ecommerce related data for the purchase event.","properties":{"value":{"type":"number","description":"The monetary value of the event. Set value to the sum of (price * quantity) for all items in items.","examples":[30.03,99.99,45.5]},"currency":{"type":"string","description":"The currency of the items in ISO 4217 three-letter format. Required when value is set.","examples":["USD","EUR","GBP"]},"items":{"type":"array","description":"The products added to the cart.","minItems":1,"items":{"$ref":"./components/product.json"}}},"required":["currency","items"]}}}} />
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
"
|
|
53
|
+
`;
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
4
|
+
import FoldableRows from '../../components/FoldableRows';
|
|
5
|
+
|
|
6
|
+
jest.mock('../../components/SchemaRows', () => {
|
|
7
|
+
const MockSchemaRows = (props) => (
|
|
8
|
+
// The mock needs to return a valid element to be a child of a tbody
|
|
9
|
+
// We'll use a data-testid to check for its presence.
|
|
10
|
+
<tr data-testid="schema-rows">
|
|
11
|
+
<td>{JSON.stringify(props.tableData)}</td>
|
|
12
|
+
</tr>
|
|
13
|
+
);
|
|
14
|
+
MockSchemaRows.displayName = 'MockSchemaRows';
|
|
15
|
+
return MockSchemaRows;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
jest.mock('@theme/Heading', () => {
|
|
19
|
+
const MockHeading = ({ as: Component, children, ...props }) => (
|
|
20
|
+
<Component {...props}>{children}</Component>
|
|
21
|
+
);
|
|
22
|
+
MockHeading.displayName = 'MockHeading';
|
|
23
|
+
return MockHeading;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('FoldableRows', () => {
|
|
27
|
+
const oneOfRow = {
|
|
28
|
+
type: 'choice',
|
|
29
|
+
choiceType: 'oneOf',
|
|
30
|
+
path: ['payment'],
|
|
31
|
+
level: 1,
|
|
32
|
+
description: 'Select one payment method:',
|
|
33
|
+
options: [
|
|
34
|
+
{
|
|
35
|
+
title: 'Credit Card',
|
|
36
|
+
description: 'Pay with card',
|
|
37
|
+
rows: [{ name: 'cardNumber' }],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
title: 'PayPal',
|
|
41
|
+
description: 'Pay with PayPal',
|
|
42
|
+
rows: [{ name: 'email' }],
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const anyOfRow = {
|
|
48
|
+
type: 'choice',
|
|
49
|
+
choiceType: 'anyOf',
|
|
50
|
+
path: ['contact'],
|
|
51
|
+
level: 1,
|
|
52
|
+
description: 'Select any contact method:',
|
|
53
|
+
options: [
|
|
54
|
+
{
|
|
55
|
+
title: 'Email',
|
|
56
|
+
description: 'Contact via email',
|
|
57
|
+
rows: [{ name: 'email_address' }],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
title: 'Phone',
|
|
61
|
+
description: 'Contact via phone',
|
|
62
|
+
rows: [{ name: 'phone_number' }],
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
it('renders oneOf as a radio-style accordion', () => {
|
|
68
|
+
render(
|
|
69
|
+
<table>
|
|
70
|
+
<tbody>
|
|
71
|
+
<FoldableRows row={oneOfRow} />
|
|
72
|
+
</tbody>
|
|
73
|
+
</table>,
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const creditCardToggle = screen.getByText('Credit Card');
|
|
77
|
+
const paypalToggle = screen.getByText('PayPal');
|
|
78
|
+
|
|
79
|
+
// Initially, first option is open
|
|
80
|
+
expect(
|
|
81
|
+
screen.getByText(JSON.stringify([{ name: 'cardNumber' }])),
|
|
82
|
+
).toBeInTheDocument();
|
|
83
|
+
expect(
|
|
84
|
+
screen.queryByText(JSON.stringify([{ name: 'email' }])),
|
|
85
|
+
).not.toBeInTheDocument();
|
|
86
|
+
|
|
87
|
+
// Click the second option
|
|
88
|
+
fireEvent.click(paypalToggle);
|
|
89
|
+
|
|
90
|
+
// Now, second option should be open and first should be closed
|
|
91
|
+
expect(
|
|
92
|
+
screen.queryByText(JSON.stringify([{ name: 'cardNumber' }])),
|
|
93
|
+
).not.toBeInTheDocument();
|
|
94
|
+
expect(
|
|
95
|
+
screen.getByText(JSON.stringify([{ name: 'email' }])),
|
|
96
|
+
).toBeInTheDocument();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('renders anyOf as a checkbox-style accordion', () => {
|
|
100
|
+
render(
|
|
101
|
+
<table>
|
|
102
|
+
<tbody>
|
|
103
|
+
<FoldableRows row={anyOfRow} />
|
|
104
|
+
</tbody>
|
|
105
|
+
</table>,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const emailToggle = screen.getByText('Email');
|
|
109
|
+
const phoneToggle = screen.getByText('Phone');
|
|
110
|
+
|
|
111
|
+
// Initially, nothing is open
|
|
112
|
+
expect(screen.queryByTestId('schema-rows')).not.toBeInTheDocument();
|
|
113
|
+
|
|
114
|
+
// Click the first option
|
|
115
|
+
fireEvent.click(emailToggle);
|
|
116
|
+
expect(
|
|
117
|
+
screen.getByText(JSON.stringify([{ name: 'email_address' }])),
|
|
118
|
+
).toBeInTheDocument();
|
|
119
|
+
expect(
|
|
120
|
+
screen.queryByText(JSON.stringify([{ name: 'phone_number' }])),
|
|
121
|
+
).not.toBeInTheDocument();
|
|
122
|
+
|
|
123
|
+
// Click the second option
|
|
124
|
+
fireEvent.click(phoneToggle);
|
|
125
|
+
expect(
|
|
126
|
+
screen.getByText(JSON.stringify([{ name: 'email_address' }])),
|
|
127
|
+
).toBeInTheDocument();
|
|
128
|
+
expect(
|
|
129
|
+
screen.getByText(JSON.stringify([{ name: 'phone_number' }])),
|
|
130
|
+
).toBeInTheDocument();
|
|
131
|
+
|
|
132
|
+
// Click the first option again to close it
|
|
133
|
+
fireEvent.click(emailToggle);
|
|
134
|
+
expect(
|
|
135
|
+
screen.queryByText(JSON.stringify([{ name: 'email_address' }])),
|
|
136
|
+
).not.toBeInTheDocument();
|
|
137
|
+
expect(
|
|
138
|
+
screen.getByText(JSON.stringify([{ name: 'phone_number' }])),
|
|
139
|
+
).toBeInTheDocument();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
describe('hierarchical lines feature', () => {
|
|
143
|
+
it('applies padding-left based on level using rem units', () => {
|
|
144
|
+
const rowWithLevel = {
|
|
145
|
+
type: 'choice',
|
|
146
|
+
choiceType: 'oneOf',
|
|
147
|
+
path: ['nested', 'payment'],
|
|
148
|
+
level: 2,
|
|
149
|
+
description: 'Nested choice',
|
|
150
|
+
continuingLevels: [],
|
|
151
|
+
options: [
|
|
152
|
+
{
|
|
153
|
+
title: 'Option A',
|
|
154
|
+
description: 'First option',
|
|
155
|
+
rows: [{ name: 'fieldA' }],
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const { container } = render(
|
|
161
|
+
<table>
|
|
162
|
+
<tbody>
|
|
163
|
+
<FoldableRows row={rowWithLevel} />
|
|
164
|
+
</tbody>
|
|
165
|
+
</table>,
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
const cells = container.querySelectorAll('td[colspan="5"]');
|
|
169
|
+
// level 2: 2 * 1.25 + 0.5 = 3rem
|
|
170
|
+
cells.forEach((cell) => {
|
|
171
|
+
expect(cell.style.paddingLeft).toBe('3rem');
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('applies background-image for continuing ancestor lines', () => {
|
|
176
|
+
const rowWithContinuingLevels = {
|
|
177
|
+
type: 'choice',
|
|
178
|
+
choiceType: 'anyOf',
|
|
179
|
+
path: ['deeply', 'nested', 'choice'],
|
|
180
|
+
level: 2,
|
|
181
|
+
description: 'Choice with continuing lines',
|
|
182
|
+
continuingLevels: [0], // Ancestor at level 0 has more siblings
|
|
183
|
+
options: [
|
|
184
|
+
{
|
|
185
|
+
title: 'Option A',
|
|
186
|
+
rows: [{ name: 'fieldA' }],
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const { container } = render(
|
|
192
|
+
<table>
|
|
193
|
+
<tbody>
|
|
194
|
+
<FoldableRows row={rowWithContinuingLevels} />
|
|
195
|
+
</tbody>
|
|
196
|
+
</table>,
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
const cells = container.querySelectorAll('td[colspan="5"]');
|
|
200
|
+
cells.forEach((cell) => {
|
|
201
|
+
expect(cell.style.backgroundImage).toContain('linear-gradient');
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('applies background-image for immediate parent level connection', () => {
|
|
206
|
+
const rowWithParentLevel = {
|
|
207
|
+
type: 'choice',
|
|
208
|
+
choiceType: 'oneOf',
|
|
209
|
+
path: ['parent', 'choice'],
|
|
210
|
+
level: 1,
|
|
211
|
+
description: 'Choice at level 1',
|
|
212
|
+
continuingLevels: [],
|
|
213
|
+
options: [
|
|
214
|
+
{
|
|
215
|
+
title: 'Option A',
|
|
216
|
+
rows: [{ name: 'fieldA' }],
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const { container } = render(
|
|
222
|
+
<table>
|
|
223
|
+
<tbody>
|
|
224
|
+
<FoldableRows row={rowWithParentLevel} />
|
|
225
|
+
</tbody>
|
|
226
|
+
</table>,
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
const cells = container.querySelectorAll('td[colspan="5"]');
|
|
230
|
+
// Should have a line at parent level (level 0) position
|
|
231
|
+
cells.forEach((cell) => {
|
|
232
|
+
expect(cell.style.backgroundImage).toContain('linear-gradient');
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('has no background-image for root level choices with no continuing levels', () => {
|
|
237
|
+
const rootLevelRow = {
|
|
238
|
+
type: 'choice',
|
|
239
|
+
choiceType: 'oneOf',
|
|
240
|
+
path: ['user_id'],
|
|
241
|
+
level: 0,
|
|
242
|
+
description: 'Root level choice',
|
|
243
|
+
continuingLevels: [],
|
|
244
|
+
options: [
|
|
245
|
+
{
|
|
246
|
+
title: 'Option A',
|
|
247
|
+
rows: [{ name: 'fieldA' }],
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const { container } = render(
|
|
253
|
+
<table>
|
|
254
|
+
<tbody>
|
|
255
|
+
<FoldableRows row={rootLevelRow} />
|
|
256
|
+
</tbody>
|
|
257
|
+
</table>,
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
const cells = container.querySelectorAll('td[colspan="5"]');
|
|
261
|
+
cells.forEach((cell) => {
|
|
262
|
+
expect(cell.style.backgroundImage).toBe('');
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it('combines multiple continuing levels in background-image', () => {
|
|
267
|
+
const rowWithMultipleLevels = {
|
|
268
|
+
type: 'choice',
|
|
269
|
+
choiceType: 'anyOf',
|
|
270
|
+
path: ['a', 'b', 'c', 'choice'],
|
|
271
|
+
level: 3,
|
|
272
|
+
description: 'Deeply nested choice',
|
|
273
|
+
continuingLevels: [0, 1], // Multiple ancestors have siblings
|
|
274
|
+
options: [
|
|
275
|
+
{
|
|
276
|
+
title: 'Option A',
|
|
277
|
+
rows: [{ name: 'fieldA' }],
|
|
278
|
+
},
|
|
279
|
+
],
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
const { container } = render(
|
|
283
|
+
<table>
|
|
284
|
+
<tbody>
|
|
285
|
+
<FoldableRows row={rowWithMultipleLevels} />
|
|
286
|
+
</tbody>
|
|
287
|
+
</table>,
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
const cells = container.querySelectorAll('td[colspan="5"]');
|
|
291
|
+
cells.forEach((cell) => {
|
|
292
|
+
const bgImage = cell.style.backgroundImage;
|
|
293
|
+
// Should have multiple gradients (one for each continuing level + parent)
|
|
294
|
+
const gradientCount = (bgImage.match(/linear-gradient/g) || []).length;
|
|
295
|
+
expect(gradientCount).toBeGreaterThanOrEqual(2);
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('applies correct indentation for level 0', () => {
|
|
300
|
+
const levelZeroRow = {
|
|
301
|
+
type: 'choice',
|
|
302
|
+
choiceType: 'oneOf',
|
|
303
|
+
path: ['user_id'],
|
|
304
|
+
level: 0,
|
|
305
|
+
description: 'Level 0 choice',
|
|
306
|
+
continuingLevels: [],
|
|
307
|
+
options: [
|
|
308
|
+
{
|
|
309
|
+
title: 'Option A',
|
|
310
|
+
rows: [{ name: 'fieldA' }],
|
|
311
|
+
},
|
|
312
|
+
],
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
const { container } = render(
|
|
316
|
+
<table>
|
|
317
|
+
<tbody>
|
|
318
|
+
<FoldableRows row={levelZeroRow} />
|
|
319
|
+
</tbody>
|
|
320
|
+
</table>,
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
const cells = container.querySelectorAll('td[colspan="5"]');
|
|
324
|
+
// level 0: 0 * 1.25 + 0.5 = 0.5rem
|
|
325
|
+
cells.forEach((cell) => {
|
|
326
|
+
expect(cell.style.paddingLeft).toBe('0.5rem');
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
});
|
|
@@ -3,22 +3,39 @@ import React from 'react';
|
|
|
3
3
|
import { render } from '@testing-library/react';
|
|
4
4
|
import PropertiesTable from '../../components/PropertiesTable';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
jest.mock('../../components/TableHeader', () => {
|
|
7
|
+
const MockTableHeader = () => (
|
|
8
|
+
<thead>
|
|
9
|
+
<tr>
|
|
10
|
+
<th>Mocked TableHeader</th>
|
|
11
|
+
</tr>
|
|
12
|
+
</thead>
|
|
13
|
+
);
|
|
14
|
+
MockTableHeader.displayName = 'MockTableHeader';
|
|
15
|
+
return MockTableHeader;
|
|
16
|
+
});
|
|
17
|
+
jest.mock('../../components/SchemaRows', () => {
|
|
18
|
+
const MockSchemaRows = () => (
|
|
19
|
+
<tr>
|
|
20
|
+
<td>Mocked SchemaRows</td>
|
|
21
|
+
</tr>
|
|
22
|
+
);
|
|
23
|
+
MockSchemaRows.displayName = 'MockSchemaRows';
|
|
24
|
+
return MockSchemaRows;
|
|
25
|
+
});
|
|
9
26
|
|
|
10
27
|
describe('PropertiesTable', () => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
28
|
+
it('renders the table with header and schema rows', () => {
|
|
29
|
+
const schema = {
|
|
30
|
+
properties: {
|
|
31
|
+
name: { type: 'string' },
|
|
32
|
+
},
|
|
33
|
+
required: ['name'],
|
|
34
|
+
};
|
|
18
35
|
|
|
19
|
-
|
|
36
|
+
const { getByText } = render(<PropertiesTable schema={schema} />);
|
|
20
37
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
38
|
+
expect(getByText('Mocked TableHeader')).toBeInTheDocument();
|
|
39
|
+
expect(getByText('Mocked SchemaRows')).toBeInTheDocument();
|
|
40
|
+
});
|
|
24
41
|
});
|