Skip to content

Commit

Permalink
Adding method to deregister a (child) section
Browse files Browse the repository at this point in the history
  • Loading branch information
ycombinator committed Jun 29, 2016
1 parent 323a3a9 commit a9013a5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/ui/public/management/__tests__/section.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 12 additions & 0 deletions src/ui/public/management/section.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit a9013a5

Please sign in to comment.