From a9013a5b88c9c59f8e6d7292b5ea8ebe5c1cf945 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 29 Jun 2016 12:00:06 -0700 Subject: [PATCH 1/2] Adding method to deregister a (child) section --- src/ui/public/management/__tests__/section.js | 28 +++++++++++++++++++ src/ui/public/management/section.js | 12 ++++++++ 2 files changed, 40 insertions(+) diff --git a/src/ui/public/management/__tests__/section.js b/src/ui/public/management/__tests__/section.js index 540fe8bbff207..a44d08171da4f 100644 --- a/src/ui/public/management/__tests__/section.js +++ b/src/ui/public/management/__tests__/section.js @@ -63,6 +63,34 @@ describe('ManagementSection', () => { }); }); + describe('deregister', () => { + let section; + + beforeEach(() => { + section = new ManagementSection('kibana'); + section.register('about'); + }); + + it ('deregisters an existing section', () => { + section.deregister('about'); + expect(section.items).to.have.length(0); + }); + + it ('can only deregister a section once', () => { + let threwException = false; + section.deregister('about'); + + try { + section.deregister('about'); + } catch (e) { + threwException = e.message.indexOf('is not registered') > -1; + } + + expect(threwException).to.be(true); + }); + + }); + describe('getSection', () => { let section; diff --git a/src/ui/public/management/section.js b/src/ui/public/management/section.js index ffc5406954574..c17b0d99ae1d1 100644 --- a/src/ui/public/management/section.js +++ b/src/ui/public/management/section.js @@ -49,6 +49,18 @@ export default class ManagementSection { return item; } + /** + * Deregisters a section + * + * @param {string} id + */ + deregister(id) { + if (!this.hasItem(id)) { + throw new Error(`'${id}' is not registered`); + } + this.items.remove(item => item.id === id); + } + /** * Determine if an id is already registered * From 01cf4c51582a677804d7f092c3d7a1f18596b7ce Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 29 Jun 2016 15:49:47 -0700 Subject: [PATCH 2/2] Allow deregistering a section more than once --- src/ui/public/management/__tests__/section.js | 13 +++---------- src/ui/public/management/section.js | 3 --- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/ui/public/management/__tests__/section.js b/src/ui/public/management/__tests__/section.js index a44d08171da4f..43ded4bc3e9a0 100644 --- a/src/ui/public/management/__tests__/section.js +++ b/src/ui/public/management/__tests__/section.js @@ -76,17 +76,10 @@ describe('ManagementSection', () => { expect(section.items).to.have.length(0); }); - it ('can only deregister a section once', () => { - let threwException = false; + it ('allows deregistering a section more than once', () => { section.deregister('about'); - - try { - section.deregister('about'); - } catch (e) { - threwException = e.message.indexOf('is not registered') > -1; - } - - expect(threwException).to.be(true); + section.deregister('about'); + expect(section.items).to.have.length(0); }); }); diff --git a/src/ui/public/management/section.js b/src/ui/public/management/section.js index c17b0d99ae1d1..7d7d67d9a35a2 100644 --- a/src/ui/public/management/section.js +++ b/src/ui/public/management/section.js @@ -55,9 +55,6 @@ export default class ManagementSection { * @param {string} id */ deregister(id) { - if (!this.hasItem(id)) { - throw new Error(`'${id}' is not registered`); - } this.items.remove(item => item.id === id); }