mosaic-headless 1.28.0 → 1.29.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.
@@ -53,6 +53,8 @@ def main():
53
53
  help="a loop-pagination-numbers whose children are page links")
54
54
  ap.add_argument("--paged-item", default="ct-arch-title",
55
55
  help="the repeated attrID whose text should change per page")
56
+ ap.add_argument("--instances", default="cs-card",
57
+ help="a component's root attrID; instances are prefixed")
56
58
  a = ap.parse_args()
57
59
 
58
60
  rows, fails = [], []
@@ -165,6 +167,40 @@ def main():
165
167
  check("FORM/required_blocks", bool(invalid),
166
168
  "empty form reports invalid: %s" % invalid[:4])
167
169
 
170
+ # ---- component instances
171
+ #
172
+ # An instance's ids are PREFIXED with the instance's own attrID
173
+ # (`cs-0-cs-card`), so the definition's attrID is a suffix, not an id.
174
+ # The claim worth checking is not that three cards rendered - it is that
175
+ # they are the SAME definition: one generated class token across all of
176
+ # them, while the text differs. Copy-pasted sections would each carry
177
+ # their own token.
178
+ inst = p.evaluate("""(suffix) => {
179
+ const els = [...document.querySelectorAll('[id$="-' + suffix + '"]')];
180
+ return els.map(e => ({
181
+ id: e.id,
182
+ // No regex here. `\b` inside a non-raw Python string is a BACKSPACE,
183
+ // so the pattern shipped with a 0x08 in it, matched nothing, and the
184
+ // "they all share one class" check passed on a set of three nulls.
185
+ token: String(e.className).split(/\s+/)
186
+ .filter(c => c.startsWith('_'))[0] || null,
187
+ text: e.textContent.trim().slice(0, 24)}));
188
+ }""", a.instances)
189
+ if len(inst) < 2:
190
+ skip("COMPONENT/instances", "fewer than two on this page")
191
+ else:
192
+ tokens = {i["token"] for i in inst}
193
+ texts = {i["text"] for i in inst}
194
+ check("COMPONENT/instances", len(inst) >= 2,
195
+ "%d instances: %s" % (len(inst), [i["id"] for i in inst]))
196
+ check("COMPONENT/one_definition",
197
+ len(tokens) == 1 and None not in tokens,
198
+ "all share the generated class %s - one definition, not %d copies"
199
+ % (sorted(str(t) for t in tokens), len(inst)))
200
+ check("COMPONENT/content_differs", len(texts) == len(inst),
201
+ "%d instances, %d distinct bodies - the overrides are per-instance"
202
+ % (len(inst), len(texts)))
203
+
168
204
  # ---- components whose children come from a loop
169
205
  #
170
206
  # One authored template, repeated per row. The assertion is COUNT: a