Skip to content

Commit

Permalink
warn when copyOnSave is checked. add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
stacey-gammon committed Feb 23, 2017
1 parent b0aa0b8 commit ee42002
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/ui/public/courier/saved_object/saved_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ export default function SavedObjectFactory(esAdmin, kbnIndex, Promise, Private,
*/
const warnIfDuplicateTitle = () => {
// Don't warn if the user isn't updating the title, otherwise that would become very annoying to have
// to confirm the save every time.
if (this.title === this.lastSavedTitle) {
// to confirm the save every time, except when copyOnSave is true, then we do want to check.
if (this.title === this.lastSavedTitle && !this.copyOnSave) {
return Promise.resolve();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
In previous versions of Kibana, changing the name of a {{savedObject.getDisplayName()}} would make a copy with the new name. Use the 'Save as a new {{savedObject.getDisplayName()}}' checkbox to do this now.
</div>
<label>
<input type="checkbox" ng-model="savedObject.copyOnSave" ng-checked="savedObject.copyOnSave">
<input type="checkbox" data-test-subj="saveAsNewCheckbox" ng-model="savedObject.copyOnSave" ng-checked="savedObject.copyOnSave">
Save as a new {{savedObject.getDisplayName()}}
</label>
</div>
14 changes: 11 additions & 3 deletions test/functional/apps/dashboard/_dashboard_save.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bdd.describe('dashboard save', function describeIndexTests() {
return PageObjects.dashboard.initTests();
});

bdd.it('warns on duplicate name', async function() {
bdd.it('warns on duplicate name for new dashboard', async function() {
await PageObjects.dashboard.clickNewDashboard();
await PageObjects.dashboard.saveDashboard(dashboardName);

Expand All @@ -30,7 +30,6 @@ bdd.describe('dashboard save', function describeIndexTests() {

const countOfDashboards = await PageObjects.dashboard.getDashboardCountWithName(dashboardName);
expect(countOfDashboards).to.equal(1);

});

bdd.it('Saves on confirm duplicate title warning', async function() {
Expand All @@ -44,12 +43,21 @@ bdd.describe('dashboard save', function describeIndexTests() {
expect(countOfDashboards).to.equal(2);
});

bdd.it('Does not warn when saving a duplicate title that remains unchanged', async function() {
bdd.it('Does not warn when saving a duplicate title that remains unchanged for an existing dashboard', async function() {
await PageObjects.dashboard.clickDashboardByLinkText(dashboardName);
await PageObjects.header.isGlobalLoadingIndicatorHidden();
await PageObjects.dashboard.saveDashboard(dashboardName);

const isConfirmOpen = await PageObjects.common.isConfirmModalOpen();
expect(isConfirmOpen).to.equal(false);
});

bdd.it('Warns when saving a duplicate title that remains unchanged when Save as New Dashboard is checked', async function() {
await PageObjects.dashboard.saveDashboard(dashboardName, { saveAsNew: true });

const isConfirmOpen = await PageObjects.common.isConfirmModalOpen();
expect(isConfirmOpen).to.equal(true);

await PageObjects.common.clickCancelOnModal();
});
});
6 changes: 3 additions & 3 deletions test/functional/apps/dashboard/_dashboard_time.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bdd.describe('dashboard time', function dashboardSaveWithTime() {
bdd.it('is saved', async function () {
await PageObjects.dashboard.clickNewDashboard();
await PageObjects.dashboard.addVisualizations([PageObjects.dashboard.getTestVisualizationNames()[0]]);
await PageObjects.dashboard.saveDashboard(dashboardName, false);
await PageObjects.dashboard.saveDashboard(dashboardName, { storeTimeWithDashboard: false });
});

bdd.it('Does not set the time picker on open', async function () {
Expand All @@ -35,7 +35,7 @@ bdd.describe('dashboard time', function dashboardSaveWithTime() {
bdd.describe('dashboard with stored timed', async function () {
bdd.it('is saved with quick time', async function () {
await PageObjects.header.setQuickTime('Today');
await PageObjects.dashboard.saveDashboard(dashboardName, true);
await PageObjects.dashboard.saveDashboard(dashboardName, { storeTimeWithDashboard: true });
});

bdd.it('sets quick time on open', async function () {
Expand All @@ -49,7 +49,7 @@ bdd.describe('dashboard time', function dashboardSaveWithTime() {

bdd.it('is saved with absolute time', async function () {
await PageObjects.header.setAbsoluteRange(fromTime, toTime);
await PageObjects.dashboard.saveDashboard(dashboardName, true);
await PageObjects.dashboard.saveDashboard(dashboardName, { storeTimeWithDashboard: true });
});

bdd.it('sets absolute time on open', async function () {
Expand Down
37 changes: 31 additions & 6 deletions test/support/page_objects/dashboard_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,13 @@ export default class DashboardPage {
});
}

async saveDashboard(dashName, storeTimeWithDash) {
await this.enterDashboardTitleAndClickSave(dashName, storeTimeWithDash);
/**
*
* @param dashName {String}
* @param saveOptions {{storeTimeWithDashboard: boolean, saveAsNew: boolean}}
*/
async saveDashboard(dashName, saveOptions = {}) {
await this.enterDashboardTitleAndClickSave(dashName, saveOptions);

await PageObjects.header.isGlobalLoadingIndicatorHidden();

Expand All @@ -147,7 +152,12 @@ export default class DashboardPage {
});
}

async enterDashboardTitleAndClickSave(dashboardTitle, storeTimeWithDash) {
/**
*
* @param dashboardTitle {String}
* @param saveOptions {{storeTimeWithDashboard: boolean, saveAsNew: boolean}}
*/
async enterDashboardTitleAndClickSave(dashboardTitle, saveOptions = {}) {
await PageObjects.common.findTestSubject('dashboardSaveButton').click();

await PageObjects.header.waitUntilLoadingHasFinished();
Expand All @@ -156,8 +166,12 @@ export default class DashboardPage {
PageObjects.common.debug('entering new title');
await this.findTimeout.findById('dashboardTitle').type(dashboardTitle);

if (storeTimeWithDash !== undefined) {
await this.storeTimeWithDashboard(storeTimeWithDash);
if (saveOptions.storeTimeWithDashboard !== undefined) {
await this.storeTimeWithDashboard(saveOptions.storeTimeWithDashboard);
}

if (saveOptions.saveAsNew !== undefined) {
await this.saveAsNewCheckbox(saveOptions.saveAsNew);
}

await PageObjects.header.waitUntilLoadingHasFinished();
Expand Down Expand Up @@ -304,8 +318,19 @@ export default class DashboardPage {
await PageObjects.header.setAbsoluteRange(fromTime, toTime);
}

async storeTimeWithDashboard(on) {
async saveAsNewCheckbox(on) {
PageObjects.common.debug('Storing time with dashboard: ' + on);
const saveAsNewCheckbox = await PageObjects.common.findTestSubject('saveAsNewCheckbox');
const checked = await saveAsNewCheckbox.getProperty('checked');
if (checked === true && on === false ||
checked === false && on === true) {
PageObjects.common.debug('Flipping save as new checkbox');
await saveAsNewCheckbox.click();
}
}

async storeTimeWithDashboard(on) {
PageObjects.common.debug('saveAsNewCheckbox: ' + on);
const storeTimeCheckbox = await PageObjects.common.findTestSubject('storeTimeWithDashboard');
const checked = await storeTimeCheckbox.getProperty('checked');
if (checked === true && on === false ||
Expand Down

0 comments on commit ee42002

Please sign in to comment.