This repository has been archived by the owner on Oct 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation and tests for menu utils
- Loading branch information
Showing
2 changed files
with
101 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
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,52 @@ | ||
/* eslint-env node, mocha */ | ||
import { expect } from '../../../test-helpers/expect-unit'; | ||
import { MenuTree } from '../../../src/utils/menu'; | ||
|
||
const menu = new MenuTree([ | ||
{ | ||
name: 'Root1', | ||
path: '/root1', | ||
children: [ | ||
{ | ||
name: 'Root1 > 1', | ||
path: '/root1/1' | ||
}, | ||
{ | ||
name: 'Root1 > n', | ||
regexp: /\/root1\/\d+/ | ||
} | ||
] | ||
}, | ||
{ | ||
name: 'Root2', | ||
path: '/root2' | ||
} | ||
]); | ||
|
||
describe('MenuItem', () => { | ||
describe('getCurrentRoot', () => { | ||
it('returns root item when path is found', () => { | ||
expect(menu.getCurrentRoot('/root1/1'), 'to satisfy', { name: 'Root1' }); | ||
expect(menu.getCurrentRoot('/root1/234'), 'to satisfy', { name: 'Root1' }); | ||
}); | ||
|
||
it('returns null when path is not found', () => { | ||
expect(menu.getCurrentRoot('/root1/out-of-regexp'), 'to be null'); | ||
}); | ||
}); | ||
|
||
describe('getCurrent', () => { | ||
it('returns menu item when path is found', () => { | ||
expect(menu.getCurrent('/root1/1'), 'to satisfy', { name: 'Root1 > 1' }); | ||
expect(menu.getCurrent('/root1/234'), 'to satisfy', { name: 'Root1 > n' }); | ||
}); | ||
|
||
it('returns null when path is not found', () => { | ||
expect(menu.getCurrent('/root1/out-of-regexp'), 'to be null'); | ||
}); | ||
|
||
it('works on root items', () => { | ||
expect(menu.getCurrent('/root2'), 'to satisfy', { name: 'Root2' }); | ||
}); | ||
}); | ||
}); |