-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79bcbe0
commit e2c466d
Showing
11 changed files
with
209 additions
and
35 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,77 @@ | ||
<script lang="ts"> | ||
import { computed, defineComponent, reactive, toRefs } from '@vue/composition-api' | ||
import { LaunchTileConfigIF } from '@/models/common' | ||
export default defineComponent({ | ||
name: 'LaunchTile', | ||
props: { | ||
tileConfig: { | ||
type: Object as () => LaunchTileConfigIF, | ||
required: true | ||
} | ||
}, | ||
setup (props) { | ||
const localVars = (reactive({ | ||
tileUrl: computed(() => { | ||
return props.tileConfig?.href ? new URL(props.tileConfig.href, import.meta.url) : null | ||
}), | ||
imgUrl: computed(() => new URL(`/src/assets/img/${props.tileConfig.image}`, import.meta.url)) | ||
})) | ||
return { | ||
...toRefs(localVars) | ||
} | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<v-card | ||
v-if="tileConfig.showTile" | ||
class="launch-card" | ||
> | ||
<v-row> | ||
<v-col cols="auto"> | ||
<img | ||
:src="imgUrl" | ||
alt="" | ||
class="launch-image" | ||
> | ||
</v-col> | ||
<v-col> | ||
<header> | ||
<h2>{{ tileConfig.title }}</h2> | ||
<p class="my-3"> | ||
{{ tileConfig.description }} | ||
</p> | ||
</header> | ||
<v-btn | ||
id="tile-btn" | ||
class="mt-1" | ||
color="primary" | ||
filled | ||
dark | ||
large | ||
:href="tileUrl" | ||
@click="!tileConfig.href ? tileConfig.action() : null" | ||
> | ||
<span> | ||
{{ tileConfig.actionLabel }} | ||
<v-icon>mdi-chevron-right</v-icon> | ||
</span> | ||
</v-btn> | ||
</v-col> | ||
</v-row> | ||
</v-card> | ||
</template> | ||
|
||
<style lang="scss" scoped> | ||
.launch-card { | ||
height: 225px; | ||
padding: 14px 26px; | ||
} | ||
.launch-image { | ||
width: 50px; | ||
height: auto; | ||
} | ||
</style> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ComputedRef } from '@vue/composition-api' | ||
|
||
/** Interface for the LaunchTileConfig object */ | ||
export interface LaunchTileConfigIF { | ||
showTile: ComputedRef<boolean> | ||
image: string | ||
title: string | ||
description: string | ||
href?: string | ||
action?: () => void | ||
actionLabel: string | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import LaunchTile from '@/components/LaunchTile.vue' | ||
import { LaunchTileConfigIF } from '@/models/common' | ||
import { mount } from '@vue/test-utils' | ||
import { nextTick } from '@vue/composition-api' | ||
|
||
// Mock data for the tileConfig prop | ||
const mockTileConfig: LaunchTileConfigIF = { | ||
showTile: true, | ||
image: 'icon-drs.svg', | ||
title: 'Document Record Service', | ||
description: 'Use our document record service to create a new record or search for existing ones.', | ||
href: 'http://example.com/', | ||
actionLabel: 'Open', | ||
action: vi.fn(() => 'action called') | ||
} | ||
|
||
describe('LaunchTile.vue', () => { | ||
let wrapper: any | ||
|
||
beforeEach(() => { | ||
wrapper = mount(LaunchTile, { | ||
propsData: { | ||
tileConfig: mockTileConfig | ||
} | ||
}) | ||
}) | ||
|
||
it('renders the component when showTile is true', () => { | ||
expect(wrapper.find('.launch-card').exists()).toBe(true) | ||
}) | ||
|
||
it('renders the image with the correct src', () => { | ||
const img = wrapper.find('img') | ||
expect(img.attributes('src')).toContain(mockTileConfig.image) | ||
}) | ||
|
||
it('renders the title and description', () => { | ||
expect(wrapper.find('h2').text()).toBe(mockTileConfig.title) | ||
expect(wrapper.find('p').text()).toBe(mockTileConfig.description) | ||
}) | ||
|
||
it('renders the button with the correct label and href', () => { | ||
const button = wrapper.find('#tile-btn') | ||
expect(button.text()).toContain(mockTileConfig.actionLabel) | ||
expect(button.attributes('href')).toBe(mockTileConfig.href) | ||
}) | ||
|
||
it('calls the action method when button is clicked and href is not provided', async () => { | ||
// Update the props | ||
await wrapper.setProps({ | ||
tileConfig: { ...mockTileConfig, href: null } | ||
}) | ||
|
||
// Find the button and trigger a click event | ||
const button = wrapper.find('#tile-btn') | ||
await button.trigger('click') | ||
await nextTick() | ||
|
||
// Assert that the action method was called | ||
expect(mockTileConfig.action).toHaveBeenCalled() | ||
expect(mockTileConfig.action).toHaveReturnedWith('action called') | ||
}) | ||
}) |