-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lucas ONeil <[email protected]>
- Loading branch information
Showing
6 changed files
with
179 additions
and
103 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
services/tenant-ui/frontend/src/components/common/ConfigItem.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<template> | ||
<p> | ||
<strong v-if="props.title"> | ||
{{ title }}{{ $t('common.configDelim') }} | ||
</strong> | ||
<strong v-else> | ||
<slot name="title"></slot>{{ $t('common.configDelim') }} | ||
</strong> | ||
|
||
<span v-if="contentToString">{{ props.content }}</span> | ||
<slot v-else name="content"></slot> | ||
</p> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed } from 'vue'; | ||
// Can pass in the fields as props, or use slots if more customization needed | ||
const props = withDefaults( | ||
defineProps<{ | ||
title?: string; | ||
content?: string | number | boolean; | ||
}>(), | ||
{ | ||
title: '', | ||
content: '', | ||
} | ||
); | ||
const contentToString = computed(() => | ||
typeof props.content === 'boolean' ? props.content.toString() : props.content | ||
); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
services/tenant-ui/frontend/test/components/common/ConfigItem.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { mount, shallowMount } from '@vue/test-utils'; | ||
import PrimeVue from 'primevue/config'; | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
import ConfigItem from '@/components/common/ConfigItem.vue'; | ||
|
||
const mountConfigItem = () => | ||
mount(ConfigItem, { | ||
props: { | ||
title: 'the_header', | ||
content: 'the_content', | ||
}, | ||
global: { | ||
plugins: [PrimeVue], | ||
}, | ||
}); | ||
|
||
const mountConfigItemSlot = () => | ||
mount(ConfigItem, { | ||
slots: { | ||
title: 'the_header', | ||
content: '<div>test</div>', | ||
}, | ||
global: { | ||
plugins: [PrimeVue], | ||
}, | ||
}); | ||
|
||
describe('ConfigItem', () => { | ||
test('mount renders with props', async () => { | ||
const wrapper = mountConfigItem(); | ||
|
||
const strongTitle = wrapper.find('strong'); | ||
const spanContent = wrapper.find('span'); | ||
expect(strongTitle.html()).toContain('the_header'); | ||
expect(strongTitle.html()).toContain('configDelim'); | ||
expect(spanContent.html()).toContain('the_content'); | ||
}); | ||
|
||
test('mount renders with slots', async () => { | ||
const wrapper = mountConfigItemSlot(); | ||
|
||
const strongTitle = wrapper.find('strong'); | ||
const spanContent = wrapper.find('div'); | ||
expect(strongTitle.html()).toContain('the_header'); | ||
expect(strongTitle.html()).toContain('configDelim'); | ||
expect(spanContent.html()).toContain('test'); | ||
}); | ||
}); |