Again I have a question regarding Cypress. I have many blocks of publication previews on the page, each block contains a header and several statuses of publication itself and its users, and I need to check the statuses of the certain blocks with the test. I can't use 'eq()' because data is dynamic and for some reasons the tests also don't run in the same order, therefore I often get the wrong publication by counting eq(). So I was trying to use 'within', but it fails.
My test:
cy.get('[data-test="list-item"]').within(() => {
cy.get('[data-test="title-link"]')
.contains('Empty text')
.find('[data-test="status"]')
.contains('Draft');
});
I understand that my mistake is in 'contains()' because it tries to search in there, but as I mentioned above there's no other way for me to filter the elements other than by the titles. I need to check that block with title A has status 'Draft', block with title B has status 'Published' etc.
The code I'm trying to test (UPD: HTML, as react has too much unnecessary info):
<div class="list-item bg-white cursor-pointer" data-test="list-item">
<div class="content-grid grid grid-rows-1 sm:grid-cols-2">
<div>
<a data-test="title-link" class="leading-lg font-medium text-lg text-black" href="/edit/details/5ecf5deb49ec7431bca16759">Empty text</a>
</div>
<div class="text-right mt-4 sm:mt-0">
<div class="leading-caption font-medium" data-test="status">Draft</div>
<div class="mt-4" data-test="phase">
</div>
</div>
</div>
</div>