|
1 | 1 | import {enableAutoUnmount, mount} from '@vue/test-utils' |
2 | 2 | import {afterEach, describe, expect, it} from 'vitest' |
| 3 | +import BSpinner from '../BSpinner.vue' |
3 | 4 | import BButton from './BButton.vue' |
4 | 5 | import BLink from '../BLink/BLink.vue' |
5 | 6 |
|
@@ -461,4 +462,139 @@ describe('button', () => { |
461 | 462 | }) |
462 | 463 | expect(wrapper.text()).toBe('foobar') |
463 | 464 | }) |
| 465 | + |
| 466 | + it('contains div child when prop loading', () => { |
| 467 | + const wrapper = mount(BButton, { |
| 468 | + props: {loading: true}, |
| 469 | + }) |
| 470 | + const $div = wrapper.find('div') |
| 471 | + expect($div.exists()).toBe(true) |
| 472 | + }) |
| 473 | + |
| 474 | + it('first div child has static class btn-loading', () => { |
| 475 | + const wrapper = mount(BButton, { |
| 476 | + props: {loading: true}, |
| 477 | + }) |
| 478 | + const $div = wrapper.get('div') |
| 479 | + expect($div.classes()).toContain('btn-loading') |
| 480 | + }) |
| 481 | + |
| 482 | + it('first div child has class mode-fill when prop loadingMode is fill', () => { |
| 483 | + const wrapper = mount(BButton, { |
| 484 | + props: {loading: true, loadingMode: 'fill'}, |
| 485 | + }) |
| 486 | + const $div = wrapper.get('div') |
| 487 | + expect($div.classes()).toContain('mode-fill') |
| 488 | + }) |
| 489 | + |
| 490 | + it('first div child has class mode-inline when prop loadingMode is inline', () => { |
| 491 | + const wrapper = mount(BButton, { |
| 492 | + props: {loading: true, loadingMode: 'inline'}, |
| 493 | + }) |
| 494 | + const $div = wrapper.get('div') |
| 495 | + expect($div.classes()).toContain('mode-inline') |
| 496 | + }) |
| 497 | + |
| 498 | + it('first div child has nested BSpinner by default', () => { |
| 499 | + const wrapper = mount(BButton, { |
| 500 | + props: {loading: true, loadingMode: 'inline'}, |
| 501 | + }) |
| 502 | + const $div = wrapper.get('div') |
| 503 | + const $bspinner = $div.findComponent(BSpinner) |
| 504 | + expect($bspinner.exists()).toBe(true) |
| 505 | + }) |
| 506 | + |
| 507 | + it('first div child nested BSpinner has static class btn-spinner', () => { |
| 508 | + const wrapper = mount(BButton, { |
| 509 | + props: {loading: true, loadingMode: 'inline'}, |
| 510 | + }) |
| 511 | + const $div = wrapper.get('div') |
| 512 | + const $bspinner = $div.getComponent(BSpinner) |
| 513 | + expect($bspinner.classes()).toContain('btn-spinner') |
| 514 | + }) |
| 515 | + |
| 516 | + it('first div child nested BSpinner has prop small true when size is not lg', async () => { |
| 517 | + const wrapper = mount(BButton, { |
| 518 | + props: {loading: true, loadingMode: 'inline'}, |
| 519 | + }) |
| 520 | + const $div = wrapper.get('div') |
| 521 | + const $bspinner = $div.getComponent(BSpinner) |
| 522 | + expect($bspinner.props('small')).toBe(true) |
| 523 | + await wrapper.setProps({size: 'lg'}) |
| 524 | + expect($bspinner.props('small')).toBe(false) |
| 525 | + }) |
| 526 | + |
| 527 | + it('first div child does not have bspinner when slot loading', async () => { |
| 528 | + const wrapper = mount(BButton, { |
| 529 | + props: {loading: true, loadingMode: 'inline'}, |
| 530 | + slots: {loading: 'loading...'}, |
| 531 | + }) |
| 532 | + const $div = wrapper.get('div') |
| 533 | + const $bspinner = $div.findComponent(BSpinner) |
| 534 | + expect($bspinner.exists()).toBe(false) |
| 535 | + }) |
| 536 | + |
| 537 | + it('first div child renders slot loading', async () => { |
| 538 | + const wrapper = mount(BButton, { |
| 539 | + props: {loading: true, loadingMode: 'inline'}, |
| 540 | + slots: {loading: 'loading...'}, |
| 541 | + }) |
| 542 | + const $div = wrapper.get('div') |
| 543 | + expect($div.text()).toBe('loading...') |
| 544 | + }) |
| 545 | + |
| 546 | + it('both child divs exist when prop loading', () => { |
| 547 | + const wrapper = mount(BButton, { |
| 548 | + props: {loading: true}, |
| 549 | + }) |
| 550 | + const [$first, $second] = wrapper.findAll('div') |
| 551 | + expect($first.exists()).toBe(true) |
| 552 | + expect($second.exists()).toBe(true) |
| 553 | + }) |
| 554 | + |
| 555 | + it('has a second child div when not prop loading', () => { |
| 556 | + const wrapper = mount(BButton) |
| 557 | + const $div = wrapper.find('div') |
| 558 | + expect($div.exists()).toBe(true) |
| 559 | + }) |
| 560 | + |
| 561 | + it('second child div has static class btn-content', () => { |
| 562 | + const wrapper = mount(BButton) |
| 563 | + const $div = wrapper.get('div') |
| 564 | + expect($div.classes()).toContain('btn-content') |
| 565 | + }) |
| 566 | + |
| 567 | + it('second child div does not have class btn-loading-fill when prop loading false', () => { |
| 568 | + const wrapper = mount(BButton) |
| 569 | + const $div = wrapper.get('div') |
| 570 | + expect($div.classes()).not.toContain('btn-loading-fill') |
| 571 | + }) |
| 572 | + |
| 573 | + it('second child div has class btn-loading-fill when prop loading and loadingMode is fill', async () => { |
| 574 | + const wrapper = mount(BButton, { |
| 575 | + props: {loading: true, loadingMode: 'fill'}, |
| 576 | + }) |
| 577 | + const [, $div] = wrapper.findAll('div') |
| 578 | + expect($div.classes()).toContain('btn-loading-fill') |
| 579 | + await wrapper.setProps({loadingMode: 'inline'}) |
| 580 | + expect($div.classes()).not.toContain('btn-loading-fill') |
| 581 | + }) |
| 582 | + |
| 583 | + it('second child div renders default slot', () => { |
| 584 | + const wrapper = mount(BButton, { |
| 585 | + slots: {default: 'foobar'}, |
| 586 | + }) |
| 587 | + const $div = wrapper.get('div') |
| 588 | + expect($div.text()).toBe('foobar') |
| 589 | + }) |
| 590 | + |
| 591 | + it('renders both slots when prop loading in correct order', () => { |
| 592 | + const wrapper = mount(BButton, { |
| 593 | + props: {loading: true}, |
| 594 | + slots: {default: 'foobar', loading: 'loading'}, |
| 595 | + }) |
| 596 | + const [$first, $second] = wrapper.findAll('div') |
| 597 | + expect($first.text()).toBe('loading') |
| 598 | + expect($second.text()).toBe('foobar') |
| 599 | + }) |
464 | 600 | }) |
0 commit comments