|
22 | 22 | from django.conf import settings |
23 | 23 | from django.forms import Form |
24 | 24 | from django.utils.html import escape |
| 25 | +from django.utils.text import slugify |
25 | 26 |
|
26 | 27 | from tastypie.test import ResourceTestCaseMixin |
27 | 28 |
|
@@ -1548,6 +1549,42 @@ def test_document_ballot(self): |
1548 | 1549 | self.assertContains(r, pos2.comment) |
1549 | 1550 | self.assertContains(r, '(was %s)' % pos.pos) |
1550 | 1551 |
|
| 1552 | + def test_document_ballot_popup_unique_anchors_per_doc(self): |
| 1553 | + """Ballot popup anchors should be different for each document""" |
| 1554 | + ad = Person.objects.get(user__username="ad") |
| 1555 | + docs = IndividualDraftFactory.create_batch(2) |
| 1556 | + ballots = [create_ballot_if_not_open(None, doc, ad, 'approve') for doc in docs] |
| 1557 | + for doc, ballot in zip(docs, ballots): |
| 1558 | + BallotPositionDocEvent.objects.create( |
| 1559 | + doc=doc, |
| 1560 | + rev=doc.rev, |
| 1561 | + ballot=ballot, |
| 1562 | + type="changed_ballot_position", |
| 1563 | + pos_id="yes", |
| 1564 | + comment="Looks fine to me", |
| 1565 | + comment_time=datetime.datetime.now(), |
| 1566 | + balloter=Person.objects.get(user__username="ad"), |
| 1567 | + by=Person.objects.get(name="(System)")) |
| 1568 | + |
| 1569 | + anchors = set() |
| 1570 | + author_slug = slugify(ad.plain_name()) |
| 1571 | + for doc, ballot in zip(docs, ballots): |
| 1572 | + r = self.client.get(urlreverse( |
| 1573 | + "ietf.doc.views_doc.ballot_popup", |
| 1574 | + kwargs=dict(name=doc.name, ballot_id=ballot.pk) |
| 1575 | + )) |
| 1576 | + self.assertEqual(r.status_code, 200) |
| 1577 | + q = PyQuery(r.content) |
| 1578 | + href = q(f'div.balloter-name a[href$="{author_slug}"]').attr('href') |
| 1579 | + ids = [ |
| 1580 | + target.attr('id') |
| 1581 | + for target in q(f'h4.anchor-target[id$="{author_slug}"]').items() |
| 1582 | + ] |
| 1583 | + self.assertEqual(len(ids), 1, 'Should be exactly one link for the balloter') |
| 1584 | + self.assertEqual(href, f'#{ids[0]}', 'Anchor href should match ID') |
| 1585 | + anchors.add(href) |
| 1586 | + self.assertEqual(len(anchors), len(docs), 'Each doc should have a distinct anchor for the balloter') |
| 1587 | + |
1551 | 1588 | def test_document_ballot_needed_positions(self): |
1552 | 1589 | # draft |
1553 | 1590 | doc = IndividualDraftFactory(intended_std_level_id='ps') |
|
0 commit comments