Repository navigation
feat(home): add HomeCtaComponent for final CTA section #3843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
eebf2a4
feat(home): add HomeCtaComponent for final CTA section
PierreBrisorgueil 688430e
feat(home): add imgMode prop to features cards for SVG illustrations
PierreBrisorgueil 0386cac
fix(home): address CTA button link handling and JSDoc conventions
PierreBrisorgueil c045406
test(home): add unit tests for HomeCtaComponent
PierreBrisorgueil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,115 @@ | ||
| <!-- | ||
| HomeCtaComponent | ||
| ================ | ||
| Final call-to-action section with title, subtitle, and dual CTA buttons. | ||
|
|
||
| USAGE: | ||
| <homeCtaComponent :setup="config.home.cta" /> | ||
|
|
||
| CONFIG EXAMPLE (setup object): | ||
| cta: { | ||
| variant: 'alternate', | ||
| title: 'Ready to get started?', | ||
| subtitle: 'One sentence reinforcing the key benefit.', | ||
| button: { title: 'Start Free', link: '/signup', color: 'primary' }, | ||
| secondaryButton: { title: 'See how it works', link: '/docs' }, | ||
| } | ||
| --> | ||
| <template> | ||
| <section id="cta" :style="sectionStyle"> | ||
| <v-container :style="containerStyle"> | ||
| <v-row align="center" justify="center" class="px-0 py-8"> | ||
| <v-col cols="12"> | ||
| <homeContentComponent :setup="{ title: setup.title, subtitle: setup.subtitle, alignment: 'center' }"></homeContentComponent> | ||
| </v-col> | ||
| <v-col cols="12" class="text-center"> | ||
| <v-btn | ||
| v-if="setup.button && setup.button.title && setup.button.link" | ||
| :color="setup.button.color || 'primary'" | ||
| variant="flat" | ||
| size="x-large" | ||
| :class="config.vuetify.theme.rounded" | ||
| :href="setup.button.link" | ||
| > | ||
| {{ setup.button.title }} | ||
| </v-btn> | ||
| <v-btn | ||
| v-if="setup.secondaryButton && setup.secondaryButton.title && setup.secondaryButton.link" | ||
| variant="outlined" | ||
| size="x-large" | ||
| :class="{ [config.vuetify.theme.rounded]: true, 'ml-4': setup.button && setup.button.title && setup.button.link }" | ||
| :href="setup.secondaryButton.link" | ||
| > | ||
| {{ setup.secondaryButton.title }} | ||
| </v-btn> | ||
|
PierreBrisorgueil marked this conversation as resolved.
|
||
| </v-col> | ||
| </v-row> | ||
| </v-container> | ||
| </section> | ||
| </template> | ||
|
|
||
| <script> | ||
| /** | ||
| * Module dependencies. | ||
| */ | ||
| import { useTheme } from 'vuetify'; | ||
| import { style, overlapStyle, colorModeStyle } from '../../../lib/helpers/theme'; | ||
| import homeContentComponent from './utils/home.content.component.vue'; | ||
|
|
||
| /** | ||
| * Component definition. | ||
| */ | ||
| export default { | ||
| name: 'HomeCtaComponent', | ||
| components: { | ||
| homeContentComponent, | ||
| }, | ||
| props: { | ||
| setup: { | ||
| type: Object, | ||
| required: true, | ||
| }, | ||
| }, | ||
| /** | ||
| * Initialise component data with the current Vuetify theme instance. | ||
| * @returns {{ theme: import('vuetify').ThemeInstance }} Reactive theme reference. | ||
| */ | ||
| data() { | ||
| const theme = useTheme(); | ||
| return { | ||
| theme, | ||
| }; | ||
| }, | ||
|
PierreBrisorgueil marked this conversation as resolved.
|
||
| computed: { | ||
| /** | ||
| * Active visual variant of the section. | ||
| * @returns {string} 'default' or 'alternate' | ||
| */ | ||
| variant() { | ||
| return this.setup.variant || 'default'; | ||
| }, | ||
| /** | ||
| * Inline styles for the v-container, including max-width and optional overlap. | ||
| * @returns {Object} | ||
| */ | ||
| containerStyle() { | ||
| return { | ||
| 'max-width': this.config.vuetify.theme.maxWidth, | ||
| ...overlapStyle(this.setup.overlap, this.$vuetify?.display), | ||
| }; | ||
| }, | ||
| /** | ||
| * Inline styles for the section element, using theme background based on variant. | ||
| * @returns {Object} | ||
| */ | ||
| sectionStyle() { | ||
| const bgColor = this.variant === 'alternate' ? this.theme.current.colors.surface : this.theme.current.colors.background; | ||
| return { | ||
| ...style('section', this.setup), | ||
| ...colorModeStyle(this.setup.colorMode), | ||
| background: bgColor, | ||
| }; | ||
| }, | ||
| }, | ||
| }; | ||
| </script> | ||
|
PierreBrisorgueil marked this conversation as resolved.
|
||
This file contains hidden or 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 hidden or 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
183 changes: 183 additions & 0 deletions
183
src/modules/home/tests/home.cta.component.unit.tests.js
This file contains hidden or 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,183 @@ | ||
| import { mount } from '@vue/test-utils'; | ||
| import { createVuetify } from 'vuetify'; | ||
| import * as components from 'vuetify/components'; | ||
| import * as directives from 'vuetify/directives'; | ||
| import { beforeEach, describe, it, expect, vi } from 'vitest'; | ||
| import HomeCtaComponent from '../components/home.cta.component.vue'; | ||
|
|
||
| /** | ||
| * Mock the homeContentComponent used inside CTA. | ||
| */ | ||
| vi.mock('../components/utils/home.content.component.vue', () => ({ | ||
| default: { name: 'homeContentComponent', template: '<div class="mock-content" />', props: ['setup'] }, | ||
| })); | ||
|
|
||
| /** | ||
| * Mock the theme helpers to isolate component logic. | ||
| */ | ||
| vi.mock('../../../lib/helpers/theme', () => ({ | ||
| style: vi.fn(() => ({ padding: '0' })), | ||
| overlapStyle: vi.fn(() => ({})), | ||
| colorModeStyle: vi.fn(() => ({})), | ||
| })); | ||
|
|
||
| const mockConfig = { | ||
| vuetify: { theme: { rounded: 'rounded-xl', maxWidth: '1200px', flat: false } }, | ||
| }; | ||
|
|
||
| /** | ||
| * Build global options with Vuetify + config global property. | ||
| * @param {object} vuetify - Vuetify instance. | ||
| * @returns {object} Vue test-utils global config. | ||
| */ | ||
| const globalOpts = (vuetify) => ({ | ||
| plugins: [vuetify], | ||
| config: { | ||
| globalProperties: { config: mockConfig }, | ||
| }, | ||
| }); | ||
|
|
||
| describe('HomeCtaComponent', () => { | ||
| let vuetify; | ||
|
|
||
| beforeEach(() => { | ||
| vuetify = createVuetify({ components, directives }); | ||
| }); | ||
|
|
||
| const baseSetup = { | ||
| title: 'Ready to start?', | ||
| subtitle: 'Get going now.', | ||
| button: { title: 'Sign Up', link: '/signup', color: 'primary' }, | ||
| secondaryButton: { title: 'Learn More', link: '/docs' }, | ||
| }; | ||
|
|
||
| it('renders primary and secondary buttons when both are provided', () => { | ||
| const wrapper = mount(HomeCtaComponent, { | ||
| props: { setup: baseSetup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| const buttons = wrapper.findAllComponents({ name: 'VBtn' }); | ||
| expect(buttons).toHaveLength(2); | ||
| expect(buttons[0].text()).toBe('Sign Up'); | ||
| expect(buttons[1].text()).toBe('Learn More'); | ||
| }); | ||
|
|
||
| it('renders only primary button when secondaryButton is absent', () => { | ||
| const setup = { ...baseSetup, secondaryButton: undefined }; | ||
| const wrapper = mount(HomeCtaComponent, { | ||
| props: { setup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| const buttons = wrapper.findAllComponents({ name: 'VBtn' }); | ||
| expect(buttons).toHaveLength(1); | ||
| expect(buttons[0].text()).toBe('Sign Up'); | ||
| }); | ||
|
|
||
| it('renders only secondary button when primary button is absent', () => { | ||
| const setup = { ...baseSetup, button: undefined }; | ||
| const wrapper = mount(HomeCtaComponent, { | ||
| props: { setup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| const buttons = wrapper.findAllComponents({ name: 'VBtn' }); | ||
| expect(buttons).toHaveLength(1); | ||
| expect(buttons[0].text()).toBe('Learn More'); | ||
| }); | ||
|
|
||
| it('does not render primary button when title is missing', () => { | ||
| const setup = { ...baseSetup, button: { link: '/signup', color: 'primary' } }; | ||
| const wrapper = mount(HomeCtaComponent, { | ||
| props: { setup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| const buttons = wrapper.findAllComponents({ name: 'VBtn' }); | ||
| expect(buttons).toHaveLength(1); // only secondary | ||
| expect(buttons[0].text()).toBe('Learn More'); | ||
| }); | ||
|
|
||
| it('does not render primary button when link is missing', () => { | ||
| const setup = { ...baseSetup, button: { title: 'Sign Up', color: 'primary' } }; | ||
| const wrapper = mount(HomeCtaComponent, { | ||
| props: { setup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| const buttons = wrapper.findAllComponents({ name: 'VBtn' }); | ||
| expect(buttons).toHaveLength(1); // only secondary | ||
| }); | ||
|
|
||
| it('applies ml-4 to secondary button only when primary button is present', () => { | ||
| const wrapper = mount(HomeCtaComponent, { | ||
| props: { setup: baseSetup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| const buttons = wrapper.findAllComponents({ name: 'VBtn' }); | ||
| expect(buttons[1].classes()).toContain('ml-4'); | ||
| }); | ||
|
|
||
| it('does not apply ml-4 to secondary button when primary button is absent', () => { | ||
| const setup = { ...baseSetup, button: undefined }; | ||
| const wrapper = mount(HomeCtaComponent, { | ||
| props: { setup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| const buttons = wrapper.findAllComponents({ name: 'VBtn' }); | ||
| expect(buttons[0].classes()).not.toContain('ml-4'); | ||
| }); | ||
|
|
||
| it('uses default variant when not specified', () => { | ||
| const wrapper = mount(HomeCtaComponent, { | ||
| props: { setup: baseSetup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| expect(wrapper.vm.variant).toBe('default'); | ||
| }); | ||
|
|
||
| it('uses alternate variant when specified', () => { | ||
| const setup = { ...baseSetup, variant: 'alternate' }; | ||
| const wrapper = mount(HomeCtaComponent, { | ||
| props: { setup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| expect(wrapper.vm.variant).toBe('alternate'); | ||
| }); | ||
|
|
||
| it('computes containerStyle with maxWidth from config', () => { | ||
| const wrapper = mount(HomeCtaComponent, { | ||
| props: { setup: baseSetup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| expect(wrapper.vm.containerStyle['max-width']).toBe('1200px'); | ||
| }); | ||
|
|
||
| it('uses href attribute for button links', () => { | ||
| const wrapper = mount(HomeCtaComponent, { | ||
| props: { setup: baseSetup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| const primaryBtn = wrapper.findAllComponents({ name: 'VBtn' })[0]; | ||
| expect(primaryBtn.props('href')).toBe('/signup'); | ||
| }); | ||
|
|
||
| it('renders no buttons when neither button is provided', () => { | ||
| const setup = { title: 'Title', subtitle: 'Sub' }; | ||
| const wrapper = mount(HomeCtaComponent, { | ||
| props: { setup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| const buttons = wrapper.findAllComponents({ name: 'VBtn' }); | ||
| expect(buttons).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('passes title and subtitle to homeContentComponent', () => { | ||
| const wrapper = mount(HomeCtaComponent, { | ||
| props: { setup: baseSetup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| const content = wrapper.findComponent({ name: 'homeContentComponent' }); | ||
| expect(content.props('setup')).toEqual({ | ||
| title: 'Ready to start?', | ||
| subtitle: 'Get going now.', | ||
| alignment: 'center', | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.