Display and test notification counter

This commit is contained in:
Robert Schäfer 2019-04-09 20:12:52 +02:00
parent edfbd2a6ed
commit 5b77c92c35
2 changed files with 62 additions and 36 deletions

View File

@ -8,18 +8,45 @@ const localVue = createLocalVue()
localVue.use(Styleguide)
localVue.filter('truncate', string => string)
config.stubs['dropdown'] = '<span><slot /></span>'
config.stubs['dropdown'] = '<span class="dropdown"><slot /></span>'
describe('NotificationMenu.vue', () => {
let wrapper
let Wrapper
let mocks
let data
beforeEach(() => {
mocks = {
$t: jest.fn()
}
data = () => {
return {
notifications: []
}
}
})
describe('shallowMount', () => {
const Wrapper = () => {
return shallowMount(NotificationMenu, {
data,
mocks,
localVue
})
}
it('counter displays 0', () => {
wrapper = Wrapper()
expect(wrapper.find('ds-button-stub').text()).toEqual('0')
})
it('no dropdown is rendered', () => {
wrapper = Wrapper()
expect(wrapper.contains('.dropdown')).toBe(false)
})
describe('given some notifications', () => {
beforeEach(() => {
data = () => {
return {
notifications: [
@ -56,21 +83,10 @@ describe('NotificationMenu.vue', () => {
}
})
describe('shallowMount', () => {
const Wrapper = () => {
return shallowMount(NotificationMenu, {
data,
mocks,
localVue
})
}
beforeEach(() => {
wrapper = Wrapper()
})
it('displays the total number of notifications', () => {
wrapper = Wrapper()
expect(wrapper.find('ds-button-stub').text()).toEqual('2')
})
})
})
})

View File

@ -1,5 +1,15 @@
<template>
<dropdown class="notifications-menu">
<ds-button
v-if="totalNotifications <= 0"
disabled
icon="bell"
>
{{ totalNotifications }}
</ds-button>
<dropdown
v-else
class="notifications-menu"
>
<template
slot="default"
slot-scope="{toggleMenu}"