-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0420880
commit b5c3fbf
Showing
7 changed files
with
194 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/ui/public/courier/saved_object/get_title_already_exists.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Returns true if the given saved object has a title that already exists, false otherwise. | ||
* @param savedObject {SavedObject} The object with the title to check. | ||
* @param esAdmin {Object} Used to query es | ||
* @returns {Promise<bool>} | ||
*/ | ||
export function getTitleAlreadyExists(savedObject, esAdmin) { | ||
const { index, title, type, id } = savedObject; | ||
if (!title) { | ||
throw new Error('Title must be supplied'); | ||
} | ||
|
||
const body = { | ||
query: { | ||
bool: { | ||
must: [{ match: { title } }], | ||
must_not: [{ match: { id } }] | ||
} | ||
} | ||
}; | ||
|
||
const size = 0; | ||
return esAdmin.search({ index, type, body, size }) | ||
.then((response) => { | ||
return response.hits.total > 0 ? true : false; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import expect from 'expect.js'; | ||
import { bdd } from '../../../support'; | ||
|
||
import PageObjects from '../../../support/page_objects'; | ||
|
||
bdd.describe('dashboard save', function describeIndexTests() { | ||
const dashboardName = 'Dashboard Save Test'; | ||
|
||
bdd.before(async function () { | ||
return PageObjects.dashboard.initTests(); | ||
}); | ||
|
||
bdd.it('warns on duplicate name', async function() { | ||
await PageObjects.dashboard.clickNewDashboard(); | ||
await PageObjects.dashboard.saveDashboard(dashboardName); | ||
|
||
let isConfirmOpen = await PageObjects.common.isConfirmModalOpen(); | ||
expect(isConfirmOpen).to.equal(false); | ||
|
||
await PageObjects.dashboard.gotoDashboardLandingPage(); | ||
await PageObjects.dashboard.clickNewDashboard(); | ||
await PageObjects.dashboard.enterDashboardTitleAndClickSave(dashboardName); | ||
|
||
isConfirmOpen = await PageObjects.common.isConfirmModalOpen(); | ||
expect(isConfirmOpen).to.equal(true); | ||
}); | ||
|
||
bdd.it('does not save on reject confirmation', async function() { | ||
await PageObjects.common.clickCancelOnModal(); | ||
|
||
const countOfDashboards = await PageObjects.dashboard.getDashboardCountWithName(dashboardName); | ||
expect(countOfDashboards).to.equal(1); | ||
|
||
}); | ||
|
||
bdd.it('Saves on confirm duplicate title warning', async function() { | ||
await PageObjects.dashboard.gotoDashboardLandingPage(); | ||
await PageObjects.dashboard.clickNewDashboard(); | ||
await PageObjects.dashboard.enterDashboardTitleAndClickSave(dashboardName); | ||
|
||
await PageObjects.common.clickConfirmOnModal(); | ||
|
||
const countOfDashboards = await PageObjects.dashboard.getDashboardCountWithName(dashboardName); | ||
expect(countOfDashboards).to.equal(2); | ||
}); | ||
|
||
bdd.it('Does not warn when saving a duplicate title that remains unchanged', 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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters