44 *
55 * @author Raimund Schlüßler <raimund.schluessler@mailbox.org>
66 *
7- * @license GNU AGPL version 3 or any later version
7+ * @license AGPL-3.0-or- later
88 *
99 * This program is free software: you can redistribute it and/or modify
1010 * it under the terms of the GNU Affero General Public License as
2222 */
2323
2424import { mount } from '@vue/test-utils'
25+ import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest'
2526
2627import Vue from 'vue'
2728import NcAppSidebarTabs from '../../../../src/components/NcAppSidebar/NcAppSidebarTabs.vue'
2829import NcAppSidebarTab from '../../../../src/components/NcAppSidebarTab/NcAppSidebarTab.vue'
2930import NcActionButton from '../../../../src/components/NcActionButton/NcActionButton.vue'
3031
31- let onWarning
32- let consoleDebug
33-
34- let wrapper
35-
3632const initialConsole = { ...console }
3733
3834describe ( 'NcAppSidebarTabs.vue' , ( ) => {
3935 'use strict'
40- beforeEach ( ( ) => {
41- onWarning = jest . fn ( )
42- consoleDebug = jest . fn ( )
43- Vue . config . warnHandler = onWarning
44- global . console = { ...console , debug : consoleDebug }
36+
37+ beforeEach ( ( ctx ) => {
38+ ctx . onWarning = vi . fn ( )
39+ ctx . consoleDebug = vi . fn ( )
40+ Vue . config . warnHandler = ctx . onWarning
41+ global . console = { ...console , debug : ctx . consoleDebug }
4542 } )
43+
4644 afterEach ( ( ) => {
4745 Vue . config . warnHandler = ( ) => null
4846 global . console = initialConsole
4947 } )
48+
5049 describe ( 'when using the component without tabs' , ( ) => {
5150 describe ( 'with only one div' , ( ) => {
52- beforeEach ( ( ) => {
53- wrapper = mount ( NcAppSidebarTabs , {
51+ beforeEach ( ( ctx ) => {
52+ ctx . wrapper = mount ( NcAppSidebarTabs , {
5453 propsData : {
5554 title : 'Sidebar title.' ,
5655 } ,
@@ -59,17 +58,22 @@ describe('NcAppSidebarTabs.vue', () => {
5958 } ,
6059 } )
6160 } )
62- it ( 'Issues no warning nor logs to console.' , ( ) => {
61+
62+ it ( 'does not display the nav element' , ( { wrapper} ) => {
63+ expect ( wrapper . find ( 'nav' ) . exists ( ) ) . toBe ( false )
64+ } )
65+ it ( 'Issues no warning nor logs to console.' , ( { consoleDebug, onWarning } ) => {
6366 expect ( onWarning ) . toHaveBeenCalledTimes ( 0 )
6467 expect ( consoleDebug ) . toHaveBeenCalledTimes ( 0 )
6568 } )
66- it ( 'does not display the nav element' , ( ) => {
69+ it ( 'does not display the nav element' , ( { wrapper } ) => {
6770 expect ( wrapper . find ( 'nav' ) . exists ( ) ) . toBe ( false )
6871 } )
6972 } )
73+
7074 describe ( 'with div and secondary action' , ( ) => {
71- beforeEach ( ( ) => {
72- wrapper = mount ( NcAppSidebarTabs , {
75+ beforeEach ( ( ctx ) => {
76+ ctx . wrapper = mount ( NcAppSidebarTabs , {
7377 propsData : {
7478 title : 'Sidebar title.' ,
7579 } ,
@@ -83,19 +87,16 @@ describe('NcAppSidebarTabs.vue', () => {
8387 } ,
8488 } )
8589 } )
86- it ( 'Issues no warning.' , ( ) => {
90+ it ( 'Issues no warning.' , ( { onWarning } ) => {
8791 expect ( onWarning ) . toHaveBeenCalledTimes ( 0 )
8892 } )
8993 } )
90-
91- it ( 'does not display the nav element' , ( ) => {
92- expect ( wrapper . find ( 'nav' ) . exists ( ) ) . toBe ( false )
93- } )
9494 } )
95+
9596 describe ( 'when only children of type AppSidebarTab is used' , ( ) => {
9697 describe ( 'when 3 children of type AppSidebarTab are used' , ( ) => {
97- beforeEach ( ( ) => {
98- wrapper = mount ( NcAppSidebarTabs , {
98+ beforeEach ( ( ctx ) => {
99+ ctx . wrapper = mount ( NcAppSidebarTabs , {
99100 slots : {
100101 default : [
101102 '<nc-app-sidebar-tab id="first" icon="icon-details" name="Tab1">Tab1</nc-app-sidebar-tab>' ,
@@ -109,67 +110,69 @@ describe('NcAppSidebarTabs.vue', () => {
109110 } ,
110111 } )
111112 } )
112- it ( 'Issues no warning.' , ( ) => {
113+
114+ it ( 'Issues no warning.' , ( { onWarning } ) => {
113115 expect ( onWarning ) . toHaveBeenCalledTimes ( 0 )
114116 } )
115- it ( 'display the nav element' , ( ) => {
117+ it ( 'display the nav element' , ( { wrapper } ) => {
116118 expect ( wrapper . find ( 'nav' ) . exists ( ) ) . toBe ( true )
117119 } )
118- it ( 'display all the 3 elements in li' , ( ) => {
120+ it ( 'display all the 3 elements in li' , ( { wrapper } ) => {
119121 const liList = wrapper . findAll ( 'nav>ul>li' )
120122 expect ( liList . length ) . toEqual ( 3 )
121123 } )
122- it ( 'emit "update:active" event with the selected tab id when clicking on a tab' , ( ) => {
124+ it ( 'emit "update:active" event with the selected tab id when clicking on a tab' , ( { wrapper } ) => {
123125 const lastLink = wrapper . find ( 'nav>ul>li:last-of-type>a' )
124126 lastLink . trigger ( 'click' )
125127 expect ( wrapper . emitted ( 'update:active' ) [ 0 ] ) . toEqual ( [ 'last' ] )
126128 } )
127- it ( 'emit "update:active" event with the first tab id when keydown pageup is pressed' , ( ) => {
129+ it ( 'emit "update:active" event with the first tab id when keydown pageup is pressed' , ( { wrapper } ) => {
128130 const lastLink = wrapper . find ( 'nav>ul>li:last-of-type>a' )
129- lastLink . trigger ( 'keydown.pageup' )
131+ lastLink . trigger ( 'keydown' , { keyCode : 33 } )
130132 expect ( wrapper . emitted ( 'update:active' ) [ 0 ] ) . toEqual ( [ 'first' ] )
131133 } )
132- it ( 'emit "update:active" event with the last tab id when keydown pagedown is pressed' , ( ) => {
134+ it ( 'emit "update:active" event with the last tab id when keydown pagedown is pressed' , ( { wrapper } ) => {
133135 const lastLink = wrapper . find ( 'nav>ul>li:last-of-type>a' )
134- lastLink . trigger ( 'keydown.pagedown' )
136+ lastLink . trigger ( 'keydown' , { keyCode : 34 } )
135137 expect ( wrapper . emitted ( 'update:active' ) [ 0 ] ) . toEqual ( [ 'last' ] )
136138 } )
137139 describe ( 'when we select the first element' , ( ) => {
138- beforeEach ( ( ) => {
139- wrapper . setData ( { activeTab : 'first' } )
140+ beforeEach ( ( ctx ) => {
141+ ctx . wrapper . setData ( { activeTab : 'first' } )
140142 } )
141- it ( 'does not emit "update:active" event when keydown left is pressed' , ( ) => {
143+ it ( 'does not emit "update:active" event when keydown left is pressed' , ( { wrapper } ) => {
142144 expect ( wrapper . emitted ( 'update:active' ) ) . toBeFalsy ( )
143145 const firstLink = wrapper . find ( 'nav>ul>li>a' )
144146 firstLink . trigger ( 'keydown.left' )
145147 expect ( wrapper . emitted ( 'update:active' ) ) . toBeFalsy ( )
146148 } )
147- it ( 'emit "update:active" event with the next tab id when keydown right is pressed' , ( ) => {
149+ it ( 'emit "update:active" event with the next tab id when keydown right is pressed' , ( { wrapper } ) => {
148150 const firstLink = wrapper . find ( 'nav>ul>li>a' )
149151 firstLink . trigger ( 'keydown.right' )
150152 expect ( wrapper . emitted ( 'update:active' ) [ 0 ] ) . toEqual ( [ 'second' ] )
151153 } )
152154 } )
153155 describe ( 'when we select the last element' , ( ) => {
154- beforeEach ( ( ) => {
155- wrapper . setData ( { activeTab : 'last' } )
156+ beforeEach ( ( ctx ) => {
157+ ctx . wrapper . setData ( { activeTab : 'last' } )
156158 } )
157- it ( 'emit "update:active" event with the previous tab id when keydown left is pressed' , ( ) => {
159+ it ( 'emit "update:active" event with the previous tab id when keydown left is pressed' , ( { wrapper } ) => {
158160 const lastLink = wrapper . find ( 'nav>ul>li:last-of-type>a' )
159161 lastLink . trigger ( 'keydown.left' )
160162 expect ( wrapper . emitted ( 'update:active' ) [ 0 ] ) . toEqual ( [ 'second' ] )
161163 } )
162- it ( 'does not emit "update:active" event when keydown right is pressed' , ( ) => {
164+ it ( 'does not emit "update:active" event when keydown right is pressed' , ( { wrapper } ) => {
163165 expect ( wrapper . emitted ( 'update:active' ) ) . toBeFalsy ( )
164166 const lastLink = wrapper . find ( 'nav>ul>li:last-of-type>a' )
165167 lastLink . trigger ( 'keydown.right' )
166168 expect ( wrapper . emitted ( 'update:active' ) ) . toBeFalsy ( )
167169 } )
168170 } )
169171 } )
172+
170173 describe ( 'when they is only 1 child of type AppSidebarTab are used' , ( ) => {
171- beforeEach ( ( ) => {
172- wrapper = mount ( NcAppSidebarTabs , {
174+ beforeEach ( ( ctx ) => {
175+ ctx . wrapper = mount ( NcAppSidebarTabs , {
173176 slots : {
174177 default : [
175178 '<nc-app-sidebar-tab id="1" icon="icon-details" name="Tab1">Tab1</nc-app-sidebar-tab>' ,
@@ -181,16 +184,16 @@ describe('NcAppSidebarTabs.vue', () => {
181184 } ,
182185 } )
183186 } )
184- it ( 'Issues no warning.' , ( ) => {
187+ it ( 'Issues no warning.' , ( { onWarning } ) => {
185188 expect ( onWarning ) . toHaveBeenCalledTimes ( 0 )
186189 } )
187- it ( 'does not display the nav element' , ( ) => {
190+ it ( 'does not display the nav element' , ( { wrapper } ) => {
188191 expect ( wrapper . find ( 'nav' ) . exists ( ) ) . toBe ( false )
189192 } )
190193 } )
191194 } )
192195 describe ( 'when tabs and other elements are mixed' , ( ) => {
193- it ( 'Issues a warning and logs to console .' , ( ) => {
196+ it ( 'Issues a warning and logs to console .' , ( { consoleDebug , onWarning } ) => {
194197 mount ( NcAppSidebarTabs , {
195198 slots : {
196199 default : [
0 commit comments