Candidate Set
all li tags on the page or any element that has the role="listitem" that do not have an ancestor that is a ul, ol or dl element.
Test
Is the li a descendant of and unordered, ordered or definition list? (ul, ol or dl)
If it is not the it should be queued up to be categorized as a failing element.
We are flagging these a little bit differently that just to flag each li tag. What we want to do is flag a common ancestor p, div or span of li tags that are not descendants of a valid list element.
What we would like to do with this test is highlight and act on a set of related li tags by flagging and highlighting their container tag.
Traverse up the DOM from the current list item until a p, div, or span ancestor is found
Select all list item descendants of the ancestor that do not have valid list container ancestors and remove them from the list of candidates to be evaluated. These items will be fixed when this common ancestor is addressed.
If no valid ancestor (p, div, span) is found then use the parent of the current element to run a query selector that checks for any list item descendants of the parent.
Move up the DOM from this parent to the previous ancestor until you find an element that has more than one list item descendant
Once you find a parent with more than one list item descendent continue up the DOM until you find a common ancestor that will allow a span to be inserted as valid html
Otherwise flag the list item
Alchemy Test: Ensure list items are found in a list container
Unordered list (UL) with some LI list items (should not be flagged)
Ordered list (OL) with some role="listitem" children (should not be flagged)
Exit 1
Exit 2
Div with some role="listitem" children (should be flagged)
Juice
Milk
Tea
Span with some LI descendants with intermediate children (should be flagged)
Span with some LI descendants with intermediate children where the LIs are not grouped (should be flagged)