Skip to content

Commit c3ba8e4

Browse files
committed
refactor(BInputGroupAppend): move attrs
refactor(BInputGroupPrepend): move attrs feat(BInputGroupText): add optional text prop refactor(BProgress): move attrs out of template test: progress.spec.ts test: input-group-addon.spec.ts test: input-group-append.spec.ts test: input-group-text.spec.ts test: input-group-prepend.spec.ts
1 parent bb95ab3 commit c3ba8e4

File tree

9 files changed

+379
-22
lines changed

9 files changed

+379
-22
lines changed

packages/bootstrap-vue-3/src/components/BInputGroup/BInputGroupAppend.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<template>
2-
<b-input-group-addon :id="id" :is-text="isTextBoolean" :tag="tag" append>
2+
<b-input-group-addon v-bind="computedAttrs">
33
<slot />
44
</b-input-group-addon>
55
</template>
66

77
<script setup lang="ts">
88
// import type {BInputGroupAppendProps} from '../../types/components'
99
import BInputGroupAddon from './BInputGroupAddon.vue'
10-
import {toRef} from 'vue'
11-
import {useBooleanish} from '../../composables'
10+
import {computed} from 'vue'
1211
import type {Booleanish} from '../../types'
1312
1413
interface BInputGroupAppendProps {
@@ -22,5 +21,10 @@ const props = withDefaults(defineProps<BInputGroupAppendProps>(), {
2221
isText: false,
2322
})
2423
25-
const isTextBoolean = useBooleanish(toRef(props, 'isText'))
24+
const computedAttrs = computed(() => ({
25+
id: props.id,
26+
isText: props.isText,
27+
tag: props.tag,
28+
append: true,
29+
}))
2630
</script>

packages/bootstrap-vue-3/src/components/BInputGroup/BInputGroupPrepend.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<template>
2-
<b-input-group-addon :id="id" :is-text="isTextBoolean" :tag="tag" :append="false">
2+
<b-input-group-addon v-bind="computedAttrs">
33
<slot />
44
</b-input-group-addon>
55
</template>
66

77
<script setup lang="ts">
88
// import type {BInputGroupPrependProps} from '../../types/components'
99
import BInputGroupAddon from './BInputGroupAddon.vue'
10-
import {toRef} from 'vue'
11-
import {useBooleanish} from '../../composables'
10+
import {computed} from 'vue'
1211
import type {Booleanish} from '../../types'
1312
1413
interface BInputGroupPrependProps {
@@ -22,5 +21,10 @@ const props = withDefaults(defineProps<BInputGroupPrependProps>(), {
2221
isText: false,
2322
})
2423
25-
const isTextBoolean = useBooleanish(toRef(props, 'isText'))
24+
const computedAttrs = computed(() => ({
25+
id: props.id,
26+
isText: props.isText,
27+
tag: props.tag,
28+
append: false,
29+
}))
2630
</script>

packages/bootstrap-vue-3/src/components/BInputGroup/BInputGroupText.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<template>
22
<component :is="tag" class="input-group-text">
3-
<slot />
3+
<slot>
4+
{{ text }}
5+
</slot>
46
</component>
57
</template>
68

@@ -9,6 +11,7 @@
911
1012
interface BInputGroupTextProps {
1113
tag?: string
14+
text?: string
1215
}
1316
1417
withDefaults(defineProps<BInputGroupTextProps>(), {
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import {enableAutoUnmount, mount} from '@vue/test-utils'
2+
import BInputGroupAddon from './BInputGroupAddon.vue'
3+
import BInputGroupText from './BInputGroupText.vue'
4+
import {afterEach, describe, expect, it} from 'vitest'
5+
6+
describe('input-group-addon', () => {
7+
enableAutoUnmount(afterEach)
8+
9+
it('tag is div by default', () => {
10+
const wrapper = mount(BInputGroupAddon)
11+
expect(wrapper.element.tagName).toBe('DIV')
12+
})
13+
14+
it('tag is prop tag', () => {
15+
const wrapper = mount(BInputGroupAddon, {
16+
props: {tag: 'span'},
17+
})
18+
expect(wrapper.element.tagName).toBe('SPAN')
19+
})
20+
21+
it('has attr id when prop id', async () => {
22+
const wrapper = mount(BInputGroupAddon, {
23+
props: {id: 'foobar'},
24+
})
25+
expect(wrapper.attributes('id')).toBe('foobar')
26+
await wrapper.setProps({id: 'bar'})
27+
expect(wrapper.attributes('id')).toBe('bar')
28+
})
29+
30+
it('has static class d-flex', () => {
31+
const wrapper = mount(BInputGroupAddon)
32+
expect(wrapper.classes()).toContain('d-flex')
33+
})
34+
35+
it('has class input-group-append when prop append', () => {
36+
const wrapper = mount(BInputGroupAddon, {
37+
props: {append: true},
38+
})
39+
expect(wrapper.classes()).toContain('input-group-append')
40+
})
41+
42+
it('has class input-group-prepend when prop append is false', () => {
43+
const wrapper = mount(BInputGroupAddon, {
44+
props: {append: false},
45+
})
46+
expect(wrapper.classes()).toContain('input-group-prepend')
47+
})
48+
49+
it('has BInputGroupText when prop isText', () => {
50+
const wrapper = mount(BInputGroupAddon, {
51+
props: {isText: true},
52+
})
53+
const $inputgrouptext = wrapper.findComponent(BInputGroupText)
54+
expect($inputgrouptext.exists()).toBe(true)
55+
})
56+
57+
it('does not have BInputGroupText when prop not isText', () => {
58+
const wrapper = mount(BInputGroupAddon, {
59+
props: {isText: false},
60+
})
61+
const $inputgrouptext = wrapper.findComponent(BInputGroupText)
62+
expect($inputgrouptext.exists()).toBe(false)
63+
})
64+
65+
it('BInputGroupText renders default slot', () => {
66+
const wrapper = mount(BInputGroupAddon, {
67+
props: {isText: true},
68+
slots: {default: 'foobar'},
69+
})
70+
const $inputgrouptext = wrapper.getComponent(BInputGroupText)
71+
expect($inputgrouptext.text()).toBe('foobar')
72+
})
73+
74+
it('renders default slot', () => {
75+
const wrapper = mount(BInputGroupAddon, {
76+
slots: {default: 'foobar'},
77+
})
78+
expect(wrapper.text()).toBe('foobar')
79+
})
80+
})
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import {enableAutoUnmount, mount} from '@vue/test-utils'
2+
import BInputGroupAppend from './BInputGroupAppend.vue'
3+
import BInputGroupAddon from './BInputGroupAddon.vue'
4+
import {afterEach, describe, expect, it} from 'vitest'
5+
6+
describe('input-group-append', () => {
7+
enableAutoUnmount(afterEach)
8+
9+
it('child is BInputGroupAddon', () => {
10+
const wrapper = mount(BInputGroupAppend)
11+
const $inputgroupaddon = wrapper.findComponent(BInputGroupAddon)
12+
expect($inputgroupaddon.exists()).toBe(true)
13+
})
14+
15+
it('BInputGroupAddon is given prop id', async () => {
16+
const wrapper = mount(BInputGroupAppend, {
17+
props: {id: 'foobar'},
18+
})
19+
const $inputgroupaddon = wrapper.getComponent(BInputGroupAddon)
20+
expect($inputgroupaddon.props('id')).toBe('foobar')
21+
await wrapper.setProps({id: 'foo'})
22+
expect($inputgroupaddon.props('id')).toBe('foo')
23+
})
24+
25+
it('BInputGroupAddon is given prop isText', async () => {
26+
const wrapper = mount(BInputGroupAppend, {
27+
props: {isText: true},
28+
})
29+
const $inputgroupaddon = wrapper.getComponent(BInputGroupAddon)
30+
expect($inputgroupaddon.props('isText')).toBe(true)
31+
await wrapper.setProps({isText: false})
32+
expect($inputgroupaddon.props('isText')).toBe(false)
33+
})
34+
35+
it('BInputGroupAddon is given prop tag', async () => {
36+
const wrapper = mount(BInputGroupAppend, {
37+
props: {tag: 'span'},
38+
})
39+
const $inputgroupaddon = wrapper.getComponent(BInputGroupAddon)
40+
expect($inputgroupaddon.props('tag')).toBe('span')
41+
await wrapper.setProps({tag: 'div'})
42+
expect($inputgroupaddon.props('tag')).toBe('div')
43+
})
44+
45+
it('BInputGroupAddon is given prop append to be true', () => {
46+
const wrapper = mount(BInputGroupAppend)
47+
const $inputgroupaddon = wrapper.getComponent(BInputGroupAddon)
48+
expect($inputgroupaddon.props('append')).toBe(true)
49+
})
50+
})
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {enableAutoUnmount, mount} from '@vue/test-utils'
2+
import BInputGroupText from './BInputGroupText.vue'
3+
import {afterEach, describe, expect, it} from 'vitest'
4+
5+
describe('input-group-text', () => {
6+
enableAutoUnmount(afterEach)
7+
8+
it('tag is div by default', () => {
9+
const wrapper = mount(BInputGroupText)
10+
expect(wrapper.element.tagName).toBe('DIV')
11+
})
12+
13+
it('tag is prop tag', () => {
14+
const wrapper = mount(BInputGroupText, {
15+
props: {tag: 'span'},
16+
})
17+
expect(wrapper.element.tagName).toBe('SPAN')
18+
})
19+
20+
it('has static class input-group-text', () => {
21+
const wrapper = mount(BInputGroupText)
22+
expect(wrapper.classes()).toContain('input-group-text')
23+
})
24+
25+
it('renders default slot', () => {
26+
const wrapper = mount(BInputGroupText, {
27+
slots: {default: 'foobar'},
28+
})
29+
expect(wrapper.text()).toBe('foobar')
30+
})
31+
32+
it('renders prop text', () => {
33+
const wrapper = mount(BInputGroupText, {
34+
props: {text: 'foobar'},
35+
})
36+
expect(wrapper.text()).toBe('foobar')
37+
})
38+
39+
it('renders default slot over prop text', () => {
40+
const wrapper = mount(BInputGroupText, {
41+
slots: {default: 'slots'},
42+
props: {text: 'props'},
43+
})
44+
expect(wrapper.text()).toBe('slots')
45+
})
46+
})
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import {enableAutoUnmount, mount} from '@vue/test-utils'
2+
import BInputGroupPrepend from './BInputGroupPrepend.vue'
3+
import BInputGroupAddon from './BInputGroupAddon.vue'
4+
import {afterEach, describe, expect, it} from 'vitest'
5+
6+
describe('input-group-prepend', () => {
7+
enableAutoUnmount(afterEach)
8+
9+
it('child is BInputGroupAddon', () => {
10+
const wrapper = mount(BInputGroupPrepend)
11+
const $inputgroupaddon = wrapper.findComponent(BInputGroupAddon)
12+
expect($inputgroupaddon.exists()).toBe(true)
13+
})
14+
15+
it('BInputGroupAddon is given prop id', async () => {
16+
const wrapper = mount(BInputGroupPrepend, {
17+
props: {id: 'foobar'},
18+
})
19+
const $inputgroupaddon = wrapper.getComponent(BInputGroupAddon)
20+
expect($inputgroupaddon.props('id')).toBe('foobar')
21+
await wrapper.setProps({id: 'foo'})
22+
expect($inputgroupaddon.props('id')).toBe('foo')
23+
})
24+
25+
it('BInputGroupAddon is given prop isText', async () => {
26+
const wrapper = mount(BInputGroupPrepend, {
27+
props: {isText: true},
28+
})
29+
const $inputgroupaddon = wrapper.getComponent(BInputGroupAddon)
30+
expect($inputgroupaddon.props('isText')).toBe(true)
31+
await wrapper.setProps({isText: false})
32+
expect($inputgroupaddon.props('isText')).toBe(false)
33+
})
34+
35+
it('BInputGroupAddon is given prop tag', async () => {
36+
const wrapper = mount(BInputGroupPrepend, {
37+
props: {tag: 'span'},
38+
})
39+
const $inputgroupaddon = wrapper.getComponent(BInputGroupAddon)
40+
expect($inputgroupaddon.props('tag')).toBe('span')
41+
await wrapper.setProps({tag: 'div'})
42+
expect($inputgroupaddon.props('tag')).toBe('div')
43+
})
44+
45+
it('BInputGroupAddon is given prop append to be false', () => {
46+
const wrapper = mount(BInputGroupPrepend)
47+
const $inputgroupaddon = wrapper.getComponent(BInputGroupAddon)
48+
expect($inputgroupaddon.props('append')).toBe(false)
49+
})
50+
})

packages/bootstrap-vue-3/src/components/BProgress/BProgress.vue

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
<template>
22
<div class="progress" :style="{height}">
33
<slot>
4-
<b-progress-bar
5-
v-bind="{
6-
animated: animatedBoolean,
7-
max,
8-
precision,
9-
showProgress: showProgressBoolean,
10-
showValue: showValueBoolean,
11-
striped: stripedBoolean,
12-
value,
13-
variant,
14-
}"
15-
/>
4+
<b-progress-bar v-bind="computedAttrs" />
165
</slot>
176
</div>
187
</template>
@@ -22,7 +11,7 @@
2211
import BProgressBar from './BProgressBar.vue'
2312
import type {Booleanish, ColorVariant} from '../../types'
2413
import {useBooleanish} from '../../composables'
25-
import {InjectionKey, provide, toRef} from 'vue'
14+
import {computed, InjectionKey, provide, toRef} from 'vue'
2615
2716
interface BProgressProps {
2817
variant?: ColorVariant
@@ -50,6 +39,17 @@ const showProgressBoolean = useBooleanish(toRef(props, 'showProgress'))
5039
const showValueBoolean = useBooleanish(toRef(props, 'showValue'))
5140
const stripedBoolean = useBooleanish(toRef(props, 'striped'))
5241
42+
const computedAttrs = computed(() => ({
43+
animated: animatedBoolean.value,
44+
max: props.max,
45+
precision: props.precision,
46+
showProgress: showProgressBoolean.value,
47+
showValue: showValueBoolean.value,
48+
striped: stripedBoolean.value,
49+
value: props.value,
50+
variant: props.variant,
51+
}))
52+
5353
// TODO check and see if doing animatedBoolean.value is reactive for provide
5454
// It may be possible that a toRef() is required for these types of systems.
5555
provide(injectionKey, {

0 commit comments

Comments
 (0)