diff --git a/src/collapse/tests/Collapse.spec.tsx b/src/collapse/tests/Collapse.spec.tsx
index e110b3f10..298bcf096 100644
--- a/src/collapse/tests/Collapse.spec.tsx
+++ b/src/collapse/tests/Collapse.spec.tsx
@@ -21,6 +21,50 @@ describe('n-collapse', () => {
expect(wrapper.find('.my-icon').exists()).toEqual(true)
})
+ it('should work with `accordion` prop', async () => {
+ const wrapper = mount(NCollapse, {
+ slots: {
+ default: () => [
+
+ {{ default: () => ci1
}}
+ ,
+
+ {{ default: () => ci2
}}
+ ,
+
+ {{ default: () => ci3
}}
+
+ ]
+ }
+ })
+
+ const headerMains = wrapper.findAll('.n-collapse-item__header-main')
+ await headerMains[0].trigger('click')
+ await headerMains[1].trigger('click')
+
+ expect(wrapper.findAll('.n-collapse-item__header')[0].classes()).toContain(
+ 'n-collapse-item__header--active'
+ )
+ expect(wrapper.findAll('.n-collapse-item__header')[1].classes()).toContain(
+ 'n-collapse-item__header--active'
+ )
+
+ await wrapper.setProps({
+ accordion: true
+ })
+
+ await headerMains[2].trigger('click')
+ expect(
+ wrapper.findAll('.n-collapse-item__header')[0].classes()
+ ).not.toContain('n-collapse-item__header--active')
+ expect(
+ wrapper.findAll('.n-collapse-item__header')[1].classes()
+ ).not.toContain('n-collapse-item__header--active')
+ expect(wrapper.findAll('.n-collapse-item__header')[2].classes()).toContain(
+ 'n-collapse-item__header--active'
+ )
+ })
+
it('should work with `arrow-placement` prop', async () => {
const wrapper = mount(NCollapse, {
slots: {
@@ -38,28 +82,40 @@ describe('n-collapse', () => {
})
it('should work with nested structure', async () => {
- mount(NCollapse, {
+ const wrapper = mount(NCollapse, {
slots: {
default: () =>
h(
NCollapseItem,
- { name: '1', title: 'test1' },
+ { name: '1' },
{
default: () =>
h(NCollapse, null, {
- default: () => h(NCollapseItem, { name: '2', title: 'test2' })
+ default: () => h(NCollapseItem, { name: '2' })
})
}
)
}
})
- // todo: test display-directive
- // I wanted to test this function, but I was bothered by the
+ await wrapper.find('.n-collapse-item__header-main').trigger('click')
+ expect(wrapper.find('.n-collapse-item__header').classes()).toContain(
+ 'n-collapse-item__header--active'
+ )
+ await wrapper
+ .find('.n-collapse-item__content-wrapper')
+ .find('.n-collapse-item__header-main')
+ .trigger('click')
+ expect(
+ wrapper
+ .find('.n-collapse-item__content-wrapper')
+ .find('.n-collapse-item__header')
+ .classes()
+ ).toContain('n-collapse-item__header--active')
})
it('should work with `display-directive` prop', async () => {
- mount(NCollapse, {
+ const wrapper = mount(NCollapse, {
props: {
displayDirective: 'show'
},
@@ -67,13 +123,27 @@ describe('n-collapse', () => {
default: () =>
h(
NCollapseItem,
- { name: '1', title: 'test' },
+ { name: '1' },
{ default: () => h('div', null, { default: () => 'test' }) }
)
}
- // todo: test display-directive
- // I wanted to test this function, but I was bothered by the
})
+
+ await wrapper.find('.n-collapse-item__header-main').trigger('click')
+ await wrapper.find('.n-collapse-item__header-main').trigger('click')
+ expect(
+ wrapper.find('.n-collapse-item__content-wrapper').attributes('style')
+ ).toBe('display: none;')
+
+ await wrapper.setProps({
+ displayDirective: 'if'
+ })
+
+ await wrapper.find('.n-collapse-item__header-main').trigger('click')
+ await wrapper.find('.n-collapse-item__header-main').trigger('click')
+ expect(wrapper.find('.n-collapse-item__content-wrapper').exists()).toBe(
+ false
+ )
})
it('should work with `on-item-header-click` prop', async () => {
@@ -149,4 +219,15 @@ describe('n-collapse', () => {
expect(wrapper.find('.ci1').isVisible()).toEqual(true)
expect(wrapper.find('.ci2').exists()).toEqual(false)
})
+
+ it('should work with collapseItem component `title` prop', async () => {
+ const wrapper = mount(NCollapse, {
+ slots: {
+ default: () =>
+ }
+ })
+
+ await wrapper.find('.n-collapse-item__header-main').trigger('click')
+ expect(wrapper.find('.n-collapse-item__header-main').text()).toBe('test')
+ })
})