Skip to content

Add cypress tests on the timeline bubbles (#2574) #2667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 62 additions & 3 deletions src/test/cypress/cypress/integration/Timeline.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,23 @@ describe('Time line moves', function () {
cy.get("#opfab-timeline-link-move-left").click();
}


function checkHaveCircle(nb) {
cy.get("of-custom-timeline-chart").find("circle").should('have.length', nb);
cy.get("of-custom-timeline-chart").find("ellipse").should('have.length', nb);
}

function checkNthCircleContains(nb,value) {
cy.get('#opfab-timelineCircle-' + nb ).within(() => {
cy.get("text").contains(value);
})
}

function hoverNthCircle(nb) {
cy.get('#opfab-timelineCircle-' + nb).trigger('mouseenter');
}


function clickNthCircle(nb) {
cy.get('#opfab-timelineCircle-' + nb).click();
}

function checkTitle(title) {
Expand All @@ -54,7 +68,9 @@ describe('Time line moves', function () {
cy.get(".axis").find("text").first().should("have.text", label);
}


function checkDisplayedCardTitle(title) {
cy.get("#opfab-card-title").should("have.text", title);
}

before('Set up configuration and cards', function () {
cy.loadTestConf();
Expand Down Expand Up @@ -833,4 +849,47 @@ describe('Time line moves', function () {

});


it('Check timeline circles have valid popover', function () {

cy.loginOpFab("operator1_fr", "test");
const currentDate = new Date();

checkHaveCircle(0);

cy.sendCard('cypress/feed/customEvent.json', currentDate.getTime() + 2 * HOURS, currentDate.getTime() + 5 * HOURS);
checkHaveCircle(1);
checkNthCircleContains(0,"1");

hoverNthCircle(0);
cy.get(".popover-body").find('button').should("have.length", 1);
cy.get("#opfab-div-card-template").should("not.exist");

clickNthCircle(0);
cy.get("#opfab-div-card-template").should("exist");
checkDisplayedCardTitle("State to test template rendering features");

cy.sendCard('defaultProcess/chartLine.json');
cy.sendCard('cypress/feed/customAlarm.json', currentDate.getTime() + 1 * HOURS, currentDate.getTime() + 5 * HOURS);

// wait we receive the cards (when we have 3 cards in the feed)
cy.get('of-light-card').should('have.length',3);
checkHaveCircle(2);
checkNthCircleContains(0,"1");
checkNthCircleContains(1,"2");

// Clicking on a circle with several cards should not change the currently displayed card
clickNthCircle(1);
cy.get("#opfab-div-card-template").should("exist");
checkDisplayedCardTitle("State to test template rendering features");


hoverNthCircle(1);
cy.get(".popover-body").find('button').should("have.length", 2);
cy.get(".popover-body").find('button').eq(1).click();


checkDisplayedCardTitle("Electricity consumption forecast");
});

})
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@
></svg:rect>


<svg:g *ngFor="let circle of circles" type="button">
<svg:g *ngFor="let circle of circles;let index = index;" type="button">

<svg:g *ngIf="(circle.count>1)" (mouseenter)="feedCircleHovered(circle, p1)" container="body" #p1="ngbPopover" [ngbPopover]="tooltipTemplate" triggers="mouseenter:mouseleave" closeDelay="3000" popoverClass="opfab-popover">
<svg:g id="opfab-timelineCircle-{{index}}" (click)="onCircleClick(circle)" (mouseenter)="feedCircleHovered(circle, p1)" container="body" #p1="ngbPopover" [ngbPopover]="tooltipTemplate" triggers="mouseenter:mouseleave" closeDelay="3000" popoverClass="opfab-popover">
<svg:ellipse [attr.cx]="xScale(circle.date)"
[attr.cy]="yScale(circle.circleYPosition)" [attr.ry]="'10'" [attr.rx]="circle.width" [attr.fill]=circle.color [attr.stroke]="'stroke'"
/>
Expand All @@ -128,17 +128,6 @@
[attr.font-size]="15" dy=".3em">{{circle.count}} </text>
</svg:g>

<svg:g *ngIf="(circle.count==1)" (click)="showCard(circle.summary[0].cardId)" (mouseenter)="feedCircleHovered(circle, p2)" container="body" #p2="ngbPopover" [ngbPopover]="tooltipTemplate" triggers="mouseenter:mouseleave" closeDelay="3000" popoverClass="opfab-popover" >
<svg:circle [attr.cx]="xScale(circle.date)"
[attr.cy]="yScale(circle.circleYPosition)" [attr.r]="'10'" [attr.fill]=circle.color [attr.stroke]="'stroke'"
/>
<text [attr.x]="xScale(circle.date)"
[attr.y]="yScale(circle.circleYPosition)"
text-anchor="middle"
fill=white
font-weight="bold"
[attr.font-size]="15" dy=".3em">{{circle.count}} </text>
</svg:g>
</svg:g>
</svg:g>
<ng-template #tooltipTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,14 @@ export class CustomTimelineChartComponent extends BaseChartComponent implements
return '';
}

showCard(cardId): void {
onCircleClick(circle) {
if (circle.count==1) {
let cardId = circle.summary[0].cardId
this.showCard(cardId);
}
}

showCard(cardId): void {
this.router.navigate(['/' + this.currentPath, 'cards', cardId]);
this.scrollToSelectedCard();
}
Expand Down