-
Notifications
You must be signed in to change notification settings - Fork 6
feat(home): add grid layout option to features component #3859
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
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
272 changes: 272 additions & 0 deletions
272
src/modules/home/tests/home.features.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,272 @@ | ||
| 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 HomeFeaturesComponent from '../components/home.features.component.vue'; | ||
|
|
||
| /** | ||
| * Mock child components. | ||
| */ | ||
| vi.mock('../components/utils/home.content.component.vue', () => ({ | ||
| default: { name: 'homeContentComponent', template: '<div class="mock-content" />', props: ['setup', 'alignment', 'color', 'variant'] }, | ||
| })); | ||
| vi.mock('../components/utils/home.dynamicIsland.component.vue', () => ({ | ||
| default: { name: 'homeDynamicIsland', template: '<div class="mock-island" />', props: ['container', 'step', 'steps', 'action'] }, | ||
| })); | ||
| vi.mock('../components/utils/home.img.component.vue', () => ({ | ||
| default: { name: 'homeImgComponent', template: '<div class="mock-img" />', props: ['img', 'imgMode'] }, | ||
| })); | ||
|
|
||
| /** | ||
| * Mock theme helpers. | ||
| */ | ||
| 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 }, | ||
| }, | ||
| }); | ||
|
|
||
| const makeItem = (overrides = {}) => ({ | ||
| subtitle: 'Feature', | ||
| img: '/images/feature.webp', | ||
| text: 'Description', | ||
| ...overrides, | ||
| }); | ||
|
|
||
| describe('HomeFeaturesComponent', () => { | ||
| let vuetify; | ||
|
|
||
| beforeEach(() => { | ||
| vuetify = createVuetify({ components, directives }); | ||
| }); | ||
|
|
||
| const carouselSetup = { | ||
| title: 'Features', | ||
| slide: { interval: 5000 }, | ||
| content: [makeItem({ subtitle: 'A' }), makeItem({ subtitle: 'B' })], | ||
| }; | ||
|
|
||
| const gridSetup = { | ||
| title: 'Features', | ||
| layout: 'grid', | ||
| slide: { interval: 5000 }, | ||
| content: [makeItem({ subtitle: 'A' }), makeItem({ subtitle: 'B' }), makeItem({ subtitle: 'C' })], | ||
| }; | ||
|
|
||
| // --- Layout detection --- | ||
|
|
||
| it('defaults to carousel layout when layout is not specified', () => { | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup: carouselSetup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| expect(wrapper.vm.isGrid).toBe(false); | ||
| }); | ||
|
|
||
| it('detects grid layout when layout is "grid"', () => { | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup: gridSetup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| expect(wrapper.vm.isGrid).toBe(true); | ||
| }); | ||
|
|
||
| // --- Grid rendering --- | ||
|
|
||
| it('renders grid cards when layout is grid', () => { | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup: gridSetup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| const cards = wrapper.findAllComponents({ name: 'VCard' }); | ||
| expect(cards).toHaveLength(3); | ||
| }); | ||
|
|
||
| it('does not render carousel when layout is grid', () => { | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup: gridSetup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| const carousel = wrapper.findComponent({ name: 'VCarousel' }); | ||
| expect(carousel.exists()).toBe(false); | ||
| }); | ||
|
|
||
| it('does not render dynamic island when layout is grid', () => { | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup: gridSetup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| const island = wrapper.findComponent({ name: 'homeDynamicIsland' }); | ||
| expect(island.exists()).toBe(false); | ||
| }); | ||
|
|
||
| // --- Grid column sizing --- | ||
|
|
||
| it('auto-computes gridColSize=6 for 2 items', () => { | ||
| const setup = { ...gridSetup, content: [makeItem(), makeItem()] }; | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| expect(wrapper.vm.gridColSize).toBe(6); | ||
| }); | ||
|
|
||
| it('auto-computes gridColSize=4 for 3 items', () => { | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup: gridSetup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| expect(wrapper.vm.gridColSize).toBe(4); | ||
| }); | ||
|
|
||
| it('auto-computes gridColSize=3 for 4+ items', () => { | ||
| const setup = { ...gridSetup, content: [makeItem(), makeItem(), makeItem(), makeItem()] }; | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| expect(wrapper.vm.gridColSize).toBe(3); | ||
| }); | ||
|
|
||
| it('uses explicit cols when provided', () => { | ||
| const setup = { ...gridSetup, cols: 2 }; | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| expect(wrapper.vm.gridColSize).toBe(6); | ||
| }); | ||
|
|
||
| it('uses explicit cols=3 for 4-col grid', () => { | ||
| const setup = { ...gridSetup, cols: 3 }; | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| expect(wrapper.vm.gridColSize).toBe(4); | ||
| }); | ||
|
|
||
| it('coerces string cols from env var config', () => { | ||
| const setup = { ...gridSetup, cols: '4' }; | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| expect(wrapper.vm.gridColSize).toBe(3); | ||
| }); | ||
|
|
||
| it('falls back to auto when cols is an invalid string', () => { | ||
| const setup = { ...gridSetup, cols: 'abc' }; | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| expect(wrapper.vm.gridColSize).toBe(4); // 3 items → auto 4 | ||
| }); | ||
|
|
||
| it('falls back to auto when cols is not a valid divisor', () => { | ||
| const setup = { ...gridSetup, cols: 5 }; | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| expect(wrapper.vm.gridColSize).toBe(4); // 3 items → auto 4 | ||
| }); | ||
|
|
||
| // --- fullWidth in grid --- | ||
|
|
||
| it('honors fullWidth in grid layout', () => { | ||
| const setup = { | ||
| ...gridSetup, | ||
| content: [makeItem({ fullWidth: true }), makeItem()], | ||
| }; | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| const cols = wrapper.findAllComponents({ name: 'VCol' }); | ||
| // First col after the header col should have md=12 (fullWidth) | ||
| // cols[0] is the header, cols[1] is the fullWidth item, cols[2] is the normal item | ||
| const fullWidthCol = cols[1]; | ||
| const normalCol = cols[2]; | ||
| expect(fullWidthCol.props('md')).toBe(12); | ||
| expect(normalCol.props('md')).toBe(6); | ||
| }); | ||
|
|
||
| // --- Carousel rendering (default) --- | ||
|
|
||
| it('renders carousel when layout is not grid', () => { | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup: carouselSetup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| const carousel = wrapper.findComponent({ name: 'VCarousel' }); | ||
| expect(carousel.exists()).toBe(true); | ||
| }); | ||
|
|
||
| // --- Null-safety --- | ||
|
|
||
| it('handles undefined content gracefully in grid mode', () => { | ||
| const setup = { title: 'Features', layout: 'grid', slide: { interval: 5000 } }; | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| expect(wrapper.vm.gridColSize).toBe(6); | ||
| expect(wrapper.vm.isGrid).toBe(true); | ||
| }); | ||
|
|
||
| it('handles undefined content gracefully in carousel mode', () => { | ||
| const setup = { title: 'Features', slide: { interval: 5000 } }; | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| expect(wrapper.vm.steps).toBe(-1); | ||
| expect(wrapper.vm.content).toEqual([]); | ||
| }); | ||
|
|
||
| // --- Computed properties --- | ||
|
|
||
| it('uses default variant when not specified', () => { | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup: carouselSetup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| expect(wrapper.vm.variant).toBe('default'); | ||
| }); | ||
|
|
||
| it('uses alternate variant when specified', () => { | ||
| const setup = { ...carouselSetup, variant: 'alternate' }; | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| expect(wrapper.vm.variant).toBe('alternate'); | ||
| }); | ||
|
|
||
| it('computes containerStyle with maxWidth from config', () => { | ||
| const wrapper = mount(HomeFeaturesComponent, { | ||
| props: { setup: carouselSetup }, | ||
| global: globalOpts(vuetify), | ||
| }); | ||
| expect(wrapper.vm.containerStyle['max-width']).toBe('1200px'); | ||
| }); | ||
| }); |
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.