Skip to content
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

Automation/reorder widgets reworking #253

Merged
merged 6 commits into from
Feb 19, 2020
Merged
Changes from 3 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
132 changes: 73 additions & 59 deletions functional/cypress-tests/cypress/integration/reordering.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,48 @@ describe('Reordering', () => {
});
});

it('Logged in user can reorder widgets', () => {
const reorderedWidgetName = 'Reorder Widget';
const dropOnWidget = 'Example Widget';
const widgets = [];
it("Logged in user can reorder widgets, logged out user can't", () => {
const dashboardName = dashboardNameGen('ReorderWidgetsTest');
const firstWidgetsName = 'First Widget';
const secondWidgetsName = 'Second Widget';
const thirdWidgetsName = 'Third Widget';
let widgets = [];

cy.login();
cy.get(`h3:contains("${reorderedWidgetName}")`).drag(
`h3:contains("${dropOnWidget}")`,
cy.addDashboard(dashboardName);
cy.chooseDashboard(dashboardName);
cy.clickAddWidgetButton();
cy.fillNewWidgetGeneral('Checkbox', firstWidgetsName, false, false, 1, 1);
cy.confirmAddWidget();
cy.clickAddWidgetButton();
cy.fillNewWidgetGeneral('Checkbox', secondWidgetsName, false, false, 1, 1);
cy.confirmAddWidget();
cy.clickAddWidgetButton();
cy.fillNewWidgetGeneral('Checkbox', thirdWidgetsName, false, false, 1, 1);
cy.confirmAddWidget();

cy.get('[draggable="true"]')
.each(widget => {
cy.wrap(widget)
.find('h3')
.then(heading => {
widgets.push(heading.text());
});
})
.then(() => {
expect(widgets, 'Verifying the initial state').to.deep.equal([
firstWidgetsName,
secondWidgetsName,
thirdWidgetsName
]);
widgets = [];
});

cy.get(`h3:contains("${thirdWidgetsName}")`).drag(
`h3:contains("${firstWidgetsName}")`,
'left'
);

cy.get('[draggable="true"]')
.each(widget => {
cy.wrap(widget)
Expand All @@ -68,23 +100,42 @@ describe('Reordering', () => {
});
})
.then(() => {
for (let i = 0; i < widgets.length; i++) {
if (
widgets[i] == reorderedWidgetName &&
widgets[i + 1] == dropOnWidget
) {
i = widgets.length;
} else if (
i == widgets.length - 1 &&
!(
widgets[i] == reorderedWidgetName &&
widgets[i + 1] == dropOnWidget
)
) {
throw new Error('Reordering of widgets is not working.');
}
}
expect(widgets, 'Verifying if reordering widgets works').to.deep.equal([
thirdWidgetsName,
firstWidgetsName,
secondWidgetsName
]);
widgets = [];
});

cy.logout();

cy.get(`h3:contains("${firstWidgetsName}")`).drag(
`h3:contains("${thirdWidgetsName}")`,
'left'
);

cy.get('[draggable="true"]')
.each(widget => {
cy.wrap(widget)
.find('h3')
.then(heading => {
widgets.push(heading.text());
});
})
.then(() => {
expect(
widgets,
'Verifying if user is unable to reorder widgets when logged out'
).to.not.deep.equal([
firstWidgetsName,
thirdWidgetsName,
secondWidgetsName
]);
});

cy.login();
cy.removeDashboard(dashboardName);
});

it("Logged out user can't reorder dashboards", () => {
Expand Down Expand Up @@ -129,41 +180,4 @@ describe('Reordering', () => {
}
});
});

it("Logged out user can't reorder widgets", () => {
const reorderedWidgetName = 'Reorder Widget';
const dropOnWidget = 'Example Widget';
const widgets = [];

cy.get(`h3:contains("${reorderedWidgetName}")`).drag(
`h3:contains("${dropOnWidget}")`,
'left'
);
cy.get('[draggable="true"]')
.each(widget => {
cy.wrap(widget)
.find('h3')
.then(heading => {
widgets.push(heading.text());
});
})
.then(() => {
for (let i = 0; i < widgets.length; i++) {
if (
widgets[i] == dropOnWidget &&
widgets[i + 1] == reorderedWidgetName
) {
i = widgets.length;
} else if (
i == widgets.length - 1 &&
!(
widgets[i] == dropOnWidget &&
widgets[i + 1] == reorderedWidgetName
)
) {
throw new Error('Logged out user can reorder widgets.');
}
}
});
});
});