Update test to findIndex instead of hard coding

Co-authored-by: Mike Aono <aonomike@gmail.com>
This commit is contained in:
mattwr18 2019-11-02 14:44:21 +01:00
parent b7e39ca3db
commit 09e4c20bb8

View File

@ -91,18 +91,24 @@ describe('AvatarMenu.vue', () => {
describe('role user', () => { describe('role user', () => {
it('displays a link to user profile', () => { it('displays a link to user profile', () => {
const profileLink = wrapper.findAll('.ds-menu-item span').at(0) const profileLink = wrapper
expect(profileLink.attributes().to).toEqual('/profile/u343/matt') .findAll('.ds-menu-item span')
.at(wrapper.vm.routes.findIndex(route => route.path === '/profile/u343/matt'))
expect(profileLink.exists()).toBe(true)
}) })
it('displays a link to the notifications page', () => { it('displays a link to the notifications page', () => {
const notificationsLink = wrapper.findAll('.ds-menu-item span').at(2) const notificationsLink = wrapper
expect(notificationsLink.attributes().to).toEqual('/notifications') .findAll('.ds-menu-item span')
.at(wrapper.vm.routes.findIndex(route => route.path === '/notifications'))
expect(notificationsLink.exists()).toBe(true)
}) })
it('displays a link to the settings page', () => { it('displays a link to the settings page', () => {
const settingsLink = wrapper.findAll('.ds-menu-item span').at(4) const settingsLink = wrapper
expect(settingsLink.attributes().to).toEqual('/settings') .findAll('.ds-menu-item span')
.at(wrapper.vm.routes.findIndex(route => route.path === '/settings'))
expect(settingsLink.exists()).toBe(true)
}) })
}) })
@ -120,8 +126,15 @@ describe('AvatarMenu.vue', () => {
}) })
it('displays a link to moderation page', () => { it('displays a link to moderation page', () => {
const moderationLink = wrapper.findAll('.ds-menu-item span').at(6) const moderationLink = wrapper
expect(moderationLink.attributes().to).toEqual('/moderation') .findAll('.ds-menu-item span')
.at(wrapper.vm.routes.findIndex(route => route.path === '/moderation'))
expect(moderationLink.exists()).toBe(true)
})
it('displays a total of 4 links', () => {
const allLinks = wrapper.findAll('.ds-menu-item')
expect(allLinks).toHaveLength(4)
}) })
}) })
@ -139,8 +152,15 @@ describe('AvatarMenu.vue', () => {
}) })
it('displays a link to admin page', () => { it('displays a link to admin page', () => {
const adminLink = wrapper.findAll('.ds-menu-item span').at(8) const adminLink = wrapper
expect(adminLink.attributes().to).toEqual('/admin') .findAll('.ds-menu-item span')
.at(wrapper.vm.routes.findIndex(route => route.path === '/admin'))
expect(adminLink.exists()).toBe(true)
})
it('displays a total of 5 links', () => {
const allLinks = wrapper.findAll('.ds-menu-item')
expect(allLinks).toHaveLength(5)
}) })
}) })
}) })