Skip to content

[Feature Request] Grouping Similar Elements #80

@roniemartinez

Description

@roniemartinez

When a very different element is added to a group of very similar elements, the result tends to become the fallback instead of "grouping" similar elements. For example below, the simplest selector is [aaa], [ddd]. Regardless of the arrangements of the children, the selector should still be the same.

  it('should group similar elements (2-2)', () => {
    root.innerHTML = `
      <div aaa="bbb"></div>
      <div aaa="ccc"></div>
      <p ddd="eee"></p>
      <p ddd="fff"></p>
    `
    const result = getCssSelector(Array.from(root.children))
    assert.ok(testSelector(Array.from(root.children), '[aaa], [ddd]'))  // passes
    assert.equal(result, '[aaa], [ddd]')  // fails
  })

  it('should group similar elements (3-1)', () => {
    root.innerHTML = `
      <div aaa="bbb"></div>
      <div aaa="ccc"></div>
      <div aaa="ddd"></div>
      <p eee="fff"></p>
    `
    const result = getCssSelector(Array.from(root.children))
    assert.ok(testSelector(Array.from(root.children), '[aaa], [eee]'))  // passes
    assert.equal(result, '[aaa], [eee]')  // fails
  })

Output:

    ✖ should subgroup similar elements (2-2)
      Chrome Headless 92.0.4515.159 (Mac OS 10.15.7)
    AssertionError: expected '[aaa=\'bbb\'], [aaa=\'ccc\'], [ddd=\'eee\'], [ddd=\'fff\']' to equal '[aaa], [ddd]'

    ✖ should subgroup similar elements (3-1)
      Chrome Headless 92.0.4515.159 (Mac OS 10.15.7)
    AssertionError: expected '[aaa=\'bbb\'], [aaa=\'ccc\'], [aaa=\'ddd\'], p' to equal '[aaa], [eee]'

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions