Skip to content

Commit

Permalink
Fix: Update tests to meet new standards (fixes #306) (#307)
Browse files Browse the repository at this point in the history
* added narrative tests

* Prelim changes

* neatened up v1 use functions

* removed visit /

* Removed comment

* Updated test

* moved out html
  • Loading branch information
lemmyadams authored Jun 18, 2024
1 parent 05d7f5f commit 8095f29
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions tests/e2e/narrative.cy.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
describe('Narrative', function () {
function loopThroughNarrative(narrativeItems) {
const itemsCount = Object.keys(narrativeItems).length
const itemsCount = Object.keys(narrativeItems).length;
for (let i = 0; i < itemsCount-1; i++) {
cy.get('.narrative__controls-right').eq(1).click()
cy.get('.narrative__content-item.is-active').should('contain', narrativeItems[i+1].title)
cy.get('.narrative__progress').eq(i+1).should('have.class', 'is-selected')
}
cy.get('.narrative__controls-right.is-disabled').should('exist')
cy.get('.narrative__controls-right').eq(1).click();
cy.get('.narrative__content-item.is-active').should('contain', narrativeItems[i+1].title);
cy.get('.narrative__progress').eq(i+1).should('have.class', 'is-selected');
};
cy.get('.narrative__controls-right.is-disabled').should('exist');
for (let i = itemsCount-2; i >= 0; i--) {
cy.get('.narrative__controls-left').eq(1).click()
cy.get('.narrative__content-item.is-active').should('contain', narrativeItems[i].title)
cy.get('.narrative__progress').eq(i).should('have.class', 'is-selected')
}
cy.get('.narrative__controls-left.is-disabled').should('exist')
}
cy.get('.narrative__controls-left').eq(1).click();
cy.get('.narrative__content-item.is-active').should('contain', narrativeItems[i].title);
cy.get('.narrative__progress').eq(i).should('have.class', 'is-selected');
};
cy.get('.narrative__controls-left.is-disabled').should('exist');
};

beforeEach(function () {
cy.getData()
cy.getData();
});

it('should display the narrative component', function () {
const narrativeComponents = this.data.components.filter((component) => component._component === 'narrative')
narrativeComponents.forEach((narrativeComponent) => {
const narrativeComponents = this.data.components.filter(component => component._component === 'narrative');
const stripHtml = cy.helpers.stripHtml;
narrativeComponents.forEach(narrativeComponent => {
cy.visit(`/#/preview/${narrativeComponent._id}`);
const bodyWithoutHtml = narrativeComponent.body.replace(/<[^>]*>/g, '')

cy.testContainsOrNotExists('.narrative__title', narrativeComponent.displayTitle)
cy.testContainsOrNotExists('.narrative__body', bodyWithoutHtml)
cy.testContainsOrNotExists('.narrative__instruction', narrativeComponent.instruction)
cy.testContainsOrNotExists('.narrative__body', stripHtml(narrativeComponent.body));
cy.testContainsOrNotExists('.narrative__title', stripHtml(narrativeComponent.displayTitle));
cy.testContainsOrNotExists('.narrative__instruction', stripHtml(narrativeComponent.instruction));

cy.testContainsOrNotExists('.narrative__content-item.is-active', narrativeComponent._items[0].title)
cy.get('.narrative__progress').eq(0).should('have.class', 'is-selected')
cy.get('.narrative__controls-left.is-disabled').should('exist')
cy.testContainsOrNotExists('.narrative__content-item.is-active', narrativeComponent._items[0].title);
cy.get('.narrative__progress').eq(0).should('have.class', 'is-selected');
cy.get('.narrative__controls-left.is-disabled').should('exist');

loopThroughNarrative(narrativeComponent._items)
})
loopThroughNarrative(narrativeComponent._items);
});
});
});

0 comments on commit 8095f29

Please sign in to comment.