|
1 | 1 | import {enableAutoUnmount, mount} from '@vue/test-utils'
|
2 | 2 | import {afterEach, beforeEach, describe, expect, it} from 'vitest'
|
3 | 3 | import BModal from './BModal.vue'
|
| 4 | +import BCloseButton from './BButton/BCloseButton.vue' |
| 5 | +import BButton from './BButton/BButton.vue' |
4 | 6 | // import BTransition from './BTransition/BTransition.vue'
|
5 | 7 |
|
6 | 8 | describe('modal', () => {
|
@@ -313,6 +315,109 @@ describe('modal', () => {
|
313 | 315 | expect($div3.exists()).toBe(true)
|
314 | 316 | })
|
315 | 317 |
|
| 318 | + it('nested div BCloseButton has class when prop headerCloseClass', () => { |
| 319 | + const wrapper = mount(BModal, { |
| 320 | + global: {stubs: {teleport: true}}, |
| 321 | + props: {headerCloseClass: 'foobar'}, |
| 322 | + }) |
| 323 | + const $div = wrapper.get('div') |
| 324 | + const $bclosebutton = $div.getComponent(BCloseButton) |
| 325 | + expect($bclosebutton.classes()).toContain('foobar') |
| 326 | + }) |
| 327 | + |
| 328 | + it('nested div BCloseButton has class when prop headerCloseWhite', () => { |
| 329 | + const wrapper = mount(BModal, { |
| 330 | + global: {stubs: {teleport: true}}, |
| 331 | + props: {headerCloseWhite: true}, |
| 332 | + }) |
| 333 | + const $div = wrapper.get('div') |
| 334 | + const $bclosebutton = $div.getComponent(BCloseButton) |
| 335 | + expect($bclosebutton.classes()).toContain('btn-close-white') |
| 336 | + }) |
| 337 | + |
| 338 | + it('nested div BCloseButton has no variant class when headerCloseVariant', () => { |
| 339 | + const wrapper = mount(BModal, { |
| 340 | + global: {stubs: {teleport: true}}, |
| 341 | + props: {headerCloseVariant: 'warning'}, |
| 342 | + }) |
| 343 | + const $div = wrapper.get('div') |
| 344 | + const $bclosebutton = $div.getComponent(BCloseButton) |
| 345 | + expect($bclosebutton.classes()).not.toContain('btn-warning') |
| 346 | + }) |
| 347 | + |
| 348 | + it('nested div BCloseButton has aria-label to be Close by default', () => { |
| 349 | + const wrapper = mount(BModal, { |
| 350 | + global: {stubs: {teleport: true}}, |
| 351 | + }) |
| 352 | + const $div = wrapper.get('div') |
| 353 | + const $bclosebutton = $div.getComponent(BCloseButton) |
| 354 | + expect($bclosebutton.attributes('aria-label')).toBe('Close') |
| 355 | + }) |
| 356 | + |
| 357 | + it('nested div BCloseButton has aria-label to be prop headerCloseLabel', () => { |
| 358 | + const wrapper = mount(BModal, { |
| 359 | + global: {stubs: {teleport: true}}, |
| 360 | + props: {headerCloseLabel: 'foobar'}, |
| 361 | + }) |
| 362 | + const $div = wrapper.get('div') |
| 363 | + const $bclosebutton = $div.getComponent(BCloseButton) |
| 364 | + expect($bclosebutton.attributes('aria-label')).toBe('foobar') |
| 365 | + }) |
| 366 | + |
| 367 | + it('nested div BButton has class when prop headerCloseClass', () => { |
| 368 | + const wrapper = mount(BModal, { |
| 369 | + global: {stubs: {teleport: true}}, |
| 370 | + props: {headerCloseClass: 'foobar'}, |
| 371 | + slots: {'header-close': 'foobar'}, |
| 372 | + }) |
| 373 | + const $div = wrapper.get('div') |
| 374 | + const $bbutton = $div.getComponent(BButton) |
| 375 | + expect($bbutton.classes()).toContain('foobar') |
| 376 | + }) |
| 377 | + |
| 378 | + it('nested div BButton has class when prop headerCloseWhite', () => { |
| 379 | + const wrapper = mount(BModal, { |
| 380 | + global: {stubs: {teleport: true}}, |
| 381 | + props: {headerCloseWhite: true}, |
| 382 | + slots: {'header-close': 'foobar'}, |
| 383 | + }) |
| 384 | + const $div = wrapper.get('div') |
| 385 | + const $bbutton = $div.getComponent(BButton) |
| 386 | + expect($bbutton.classes()).not.toContain('btn-close-white') |
| 387 | + }) |
| 388 | + |
| 389 | + it('nested div BButton has variant class when headerCloseVariant', () => { |
| 390 | + const wrapper = mount(BModal, { |
| 391 | + global: {stubs: {teleport: true}}, |
| 392 | + props: {headerCloseVariant: 'warning'}, |
| 393 | + slots: {'header-close': 'foobar'}, |
| 394 | + }) |
| 395 | + const $div = wrapper.get('div') |
| 396 | + const $bbutton = $div.getComponent(BButton) |
| 397 | + expect($bbutton.classes()).toContain('btn-warning') |
| 398 | + }) |
| 399 | + |
| 400 | + it('nested div BButton has aria-label to be Close by default', () => { |
| 401 | + const wrapper = mount(BModal, { |
| 402 | + global: {stubs: {teleport: true}}, |
| 403 | + slots: {'header-close': 'foobar'}, |
| 404 | + }) |
| 405 | + const $div = wrapper.get('div') |
| 406 | + const $bbutton = $div.getComponent(BButton) |
| 407 | + expect($bbutton.attributes('aria-label')).toBe('Close') |
| 408 | + }) |
| 409 | + |
| 410 | + it('nested div BButton has aria-label to be prop headerCloseLabel', () => { |
| 411 | + const wrapper = mount(BModal, { |
| 412 | + global: {stubs: {teleport: true}}, |
| 413 | + props: {headerCloseLabel: 'foobar'}, |
| 414 | + slots: {'header-close': 'foobar'}, |
| 415 | + }) |
| 416 | + const $div = wrapper.get('div') |
| 417 | + const $bbutton = $div.getComponent(BButton) |
| 418 | + expect($bbutton.attributes('aria-label')).toBe('foobar') |
| 419 | + }) |
| 420 | + |
316 | 421 | // Test isActive states
|
317 | 422 |
|
318 | 423 | // Test emit states
|
|
0 commit comments