Skip to content

Commit

Permalink
make case insensitive and return matching title
Browse files Browse the repository at this point in the history
  • Loading branch information
stacey-gammon committed Feb 23, 2017
1 parent 4335e9e commit 8881739
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
12 changes: 7 additions & 5 deletions src/ui/public/courier/saved_object/get_title_already_exists.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import _ from 'lodash';
/**
* Returns true if the given saved object has a title that already exists, false otherwise.
* Returns true if the given saved object has a title that already exists, false otherwise. Search is case
* insensitive.
* @param savedObject {SavedObject} The object with the title to check.
* @param esAdmin {Object} Used to query es
* @returns {Promise<bool>}
* @returns {Promise<string|undefined>} Returns the title that matches. Because this search is not case
* sensitive, it may not exactly match the title of the object.
*/
export function getTitleAlreadyExists(savedObject, esAdmin) {
const { index, title, type, id } = savedObject;
Expand All @@ -25,9 +27,9 @@ export function getTitleAlreadyExists(savedObject, esAdmin) {
const size = 10;
return esAdmin.search({ index, type, body, size })
.then((response) => {
const titleMatch = _.find(response.hits.hits, function currentVersion(hit) {
return hit._source.title === title;
const match = _.find(response.hits.hits, function currentVersion(hit) {
return hit._source.title.toLowerCase() === title.toLowerCase();
});
return !!titleMatch;
return match ? match._source.title : undefined;
});
}
6 changes: 3 additions & 3 deletions src/ui/public/courier/saved_object/saved_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,10 @@ export default function SavedObjectFactory(esAdmin, kbnIndex, Promise, Private,
}

return getTitleAlreadyExists(this, esAdmin)
.then((isDuplicate) => {
if (!isDuplicate) return true;
.then((duplicateTitle) => {
if (!duplicateTitle) return true;
const confirmMessage =
`A ${type} with the title '${this.title}' already exists. Would you like to save a duplicate with the same name?`;
`A ${type} with the title '${duplicateTitle}' already exists. Would you like to save anyway?`;

return confirmModalPromise(confirmMessage, { confirmButtonText: `Save ${type}` })
.catch(() => Promise.reject(new Error(SAVE_DUPLICATE_REJECTED)));
Expand Down
10 changes: 6 additions & 4 deletions test/functional/apps/dashboard/_dashboard_save.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bdd.describe('dashboard save', function describeIndexTests() {
});

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 });
await PageObjects.dashboard.enterDashboardTitleAndClickSave(dashboardName, { saveAsNew: true });

const isConfirmOpen = await PageObjects.common.isConfirmModalOpen();
expect(isConfirmOpen).to.equal(true);
Expand All @@ -68,10 +68,12 @@ bdd.describe('dashboard save', function describeIndexTests() {
expect(isConfirmOpen).to.equal(false);
});

bdd.it('Does not warn when case is different', async function() {
await PageObjects.dashboard.saveDashboard(dashboardName.toUpperCase());
bdd.it('Warns when case is different', async function() {
await PageObjects.dashboard.enterDashboardTitleAndClickSave(dashboardName.toUpperCase());

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

await PageObjects.common.clickCancelOnModal();
});
});
14 changes: 6 additions & 8 deletions test/support/page_objects/dashboard_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ export default class DashboardPage {
PageObjects.common.debug('Go to dashboard landing page');
const onPage = await this.onDashboardLandingPage();
if (!onPage) {
return PageObjects.common.try(() =>
PageObjects.common.findByCssSelector('a[href="#/dashboard"]').click()
await PageObjects.common.try(async () =>
await PageObjects.common.findByCssSelector('a[href="#/dashboard"]').click()
);
// Once the searchFilter can be found, we know the page finished loading.
await PageObjects.common.try(async () => await PageObjects.common.findTestSubject('searchFilter'));
}
}

Expand Down Expand Up @@ -140,7 +142,7 @@ export default class DashboardPage {
async saveDashboard(dashName, saveOptions = {}) {
await this.enterDashboardTitleAndClickSave(dashName, saveOptions);

await PageObjects.header.isGlobalLoadingIndicatorHidden();
await PageObjects.header.waitUntilLoadingHasFinished();

// verify that green message at the top of the page.
// it's only there for about 5 seconds
Expand All @@ -161,7 +163,6 @@ export default class DashboardPage {
await PageObjects.common.findTestSubject('dashboardSaveButton').click();

await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.common.sleep(1000);

PageObjects.common.debug('entering new title');
await this.findTimeout.findById('dashboardTitle').type(dashboardTitle);
Expand All @@ -174,14 +175,10 @@ export default class DashboardPage {
await this.saveAsNewCheckbox(saveOptions.saveAsNew);
}

await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.common.sleep(1000);

await PageObjects.common.try(() => {
PageObjects.common.debug('clicking final Save button for named dashboard');
return this.findTimeout.findByCssSelector('.btn-primary').click();
});
await PageObjects.header.waitUntilLoadingHasFinished();
}

clickDashboardByLinkText(dashName) {
Expand All @@ -194,6 +191,7 @@ export default class DashboardPage {
PageObjects.common.debug(`searchForDashboardWithName: ${dashName}`);

await this.gotoDashboardLandingPage();

const searchBox = await PageObjects.common.findTestSubject('searchFilter');
await searchBox.click();

Expand Down

0 comments on commit 8881739

Please sign in to comment.