Skip to content

Commit

Permalink
Add title props to CardBoxBig, Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Aug 27, 2024
1 parent 2ab7a69 commit 6759290
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 22 deletions.
8 changes: 7 additions & 1 deletion src/components/Content/CardBoxBig.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<script setup>
defineProps({
title: String
})
</script>

<template>
<div class="uk-flex uk-flex-center uk-flex-middle">
<div class="uk-width-1-1@s uk-width-3-5@l uk-width-1-3@xl">
<UFCardBox>
<UFCardBox :title="title">
<slot />
</UFCardBox>
</div>
Expand Down
44 changes: 23 additions & 21 deletions src/tests/components/Content/CardBox.test.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
import { expect, test } from 'vitest'
import { describe, expect, test } from 'vitest'
import { mount } from '@vue/test-utils'
import CardBox from '../../../components/Content/CardBox.vue'

test('Basic test', () => {
// Arrange
const wrapper = mount(CardBox, {
props: {
title: 'Hello world'
},
slots: {
default: 'This is the slot content'
}
})
describe('CardBoxBig.vue', () => {
test('Basic test', () => {
// Arrange
const wrapper = mount(CardBox, {
props: {
title: 'Hello world'
},
slots: {
default: 'This is the slot content'
}
})

// Assert
expect(wrapper.get('[data-test="title"]').text()).toMatch('Hello world')
expect(wrapper.get('[data-test="slot"]').text()).toMatch('This is the slot content')
})
// Assert
expect(wrapper.get('[data-test="title"]').text()).toMatch('Hello world')
expect(wrapper.get('[data-test="slot"]').text()).toMatch('This is the slot content')
})

test('Test with no prop and slot', () => {
// Arrange
const wrapper = mount(CardBox)
test('Test with no prop and slot', () => {
// Arrange
const wrapper = mount(CardBox)

// Assert
expect(wrapper.find('[data-test="title"]').exists()).toBe(false)
expect(wrapper.get('[data-test="slot"]').text()).toMatch('')
// Assert
expect(wrapper.find('[data-test="title"]').exists()).toBe(false)
expect(wrapper.get('[data-test="slot"]').text()).toMatch('')
})
})
33 changes: 33 additions & 0 deletions src/tests/components/Content/CardBoxBig.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, expect, test } from 'vitest'
import { mount, config } from '@vue/test-utils'
import CardBox from '../../../components/Content/CardBox.vue'
import CardBoxBig from '../../../components/Content/CardBoxBig.vue'

config.global.stubs['UFCardBox'] = CardBox

describe('CardBoxBig.vue', () => {
test('Basic test', () => {
// Arrange
const wrapper = mount(CardBoxBig, {
props: {
title: 'Hello world'
},
slots: {
default: 'This is the slot content'
}
})

// Assert
expect(wrapper.get('[data-test="title"]').text()).toMatch('Hello world')
expect(wrapper.get('[data-test="slot"]').text()).toMatch('This is the slot content')
})

test('Test with no prop and slot', () => {
// Arrange
const wrapper = mount(CardBoxBig)

// Assert
expect(wrapper.find('[data-test="title"]').exists()).toBe(false)
expect(wrapper.get('[data-test="slot"]').text()).toMatch('')
})
})

0 comments on commit 6759290

Please sign in to comment.