-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@dpc-sdp/ripple-tide-landing-page): add compact card collection …
…i.e. category grid support
- Loading branch information
David Featherston
committed
Aug 8, 2023
1 parent
b59d4db
commit 9f9b2ff
Showing
10 changed files
with
405 additions
and
2 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
33 changes: 33 additions & 0 deletions
33
packages/ripple-test-utils/step_definitions/components/category-grid.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,33 @@ | ||
import { Then, DataTable } from '@badeball/cypress-cucumber-preprocessor' | ||
|
||
Then( | ||
'a category grid with ID {string} should exist with the following cards', | ||
(id: string, dataTable: DataTable) => { | ||
const table = dataTable.hashes() | ||
|
||
cy.get(`[data-component-id="${id}"]`).as('component') | ||
cy.get('@component') | ||
.should('exist') | ||
.should('have.attr', 'data-component-type', 'TideLandingPageCategoryGrid') | ||
|
||
cy.get('@component').within(() => { | ||
cy.get('.rpl-card--category-grid').as('items') | ||
}) | ||
|
||
table.forEach((row, i: number) => { | ||
cy.get('@items') | ||
.eq(i) | ||
.then((item) => { | ||
cy.wrap(item).as('item') | ||
cy.get('@item').find('.rpl-card__cta').should('contain', row.title) | ||
cy.get('@item') | ||
.find('.rpl-card__content') | ||
.should('contain', row.content) | ||
cy.get('@item') | ||
.find('.rpl-image') | ||
.should('have.attr', 'src') | ||
.and('contain', row.image) | ||
}) | ||
}) | ||
} | ||
) |
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 |
---|---|---|
|
@@ -14,3 +14,4 @@ import './sliders' | |
import './stats-grid' | ||
import './timeline' | ||
import './data-table' | ||
import './category-grid' |
35 changes: 35 additions & 0 deletions
35
packages/ripple-tide-landing-page/components/global/TideLandingPage/CategoryGrid.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,35 @@ | ||
<script setup lang="ts"> | ||
import { computed } from 'vue' | ||
import { ITideCompactCard } from '../../../mapping/components/compact-cards/compact-cards-mapping' | ||
const props = defineProps<{ | ||
items: ITideCompactCard[] | ||
hasSidebar: boolean | ||
}>() | ||
const columns = computed(() => { | ||
let classes = 'rpl-col-12 rpl-col-6-s' | ||
if (props.hasSidebar) { | ||
return `${classes} rpl-col-7-m rpl-col-3-xl` | ||
} | ||
return `${classes} rpl-col-4-l rpl-col-3-xl` | ||
}) | ||
</script> | ||
|
||
<template> | ||
<ul class="rpl-grid"> | ||
<RplCategoryGridCard | ||
v-for="(item, index) of items" | ||
:key="index" | ||
el="li" | ||
:image="item?.image" | ||
:url="item.url" | ||
:title="item.title" | ||
:class="columns" | ||
> | ||
<p v-if="item.summary">{{ item.summary }}</p> | ||
</RplCategoryGridCard> | ||
</ul> | ||
</template> |
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
39 changes: 39 additions & 0 deletions
39
...s/ripple-tide-landing-page/mapping/components/compact-cards/compact-cards-mapping.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,39 @@ | ||
import { TideDynamicPageComponent } from '@dpc-sdp/ripple-tide-api/types' | ||
import { expect, describe, it } from '@jest/globals' | ||
import { compactCardsMapping, ITideCompactCards } from './compact-cards-mapping' | ||
import rawData from './compact-cards' | ||
|
||
const result: TideDynamicPageComponent<ITideCompactCards> = { | ||
component: 'TideLandingPageCategoryGrid', | ||
id: '7052', | ||
title: 'Compact Cards', | ||
props: { | ||
items: [ | ||
{ | ||
title: 'Card one', | ||
summary: 'Card one summary', | ||
image: { | ||
src: 'https://develop.content.reference.sdp.vic.gov.au/sites/default/files/2023-08/Image2.jpg', | ||
alt: '', | ||
focalPoint: undefined, | ||
height: 667, | ||
title: '', | ||
width: 1000 | ||
}, | ||
url: '/landing-page-cc-2' | ||
}, | ||
{ | ||
title: 'Card two', | ||
summary: 'Card two summary', | ||
image: null, | ||
url: '/tav2-social-sharing-exists-landing-page-fe827f16' | ||
} | ||
] | ||
} | ||
} | ||
|
||
describe('compactCardsMapping', () => { | ||
it('maps a raw json api response to the correct structure', () => { | ||
expect(compactCardsMapping(rawData)).toEqual(result) | ||
}) | ||
}) |
50 changes: 50 additions & 0 deletions
50
packages/ripple-tide-landing-page/mapping/components/compact-cards/compact-cards-mapping.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,50 @@ | ||
import { getImageFromField } from '@dpc-sdp/ripple-tide-api' | ||
import { | ||
TideDynamicPageComponent, | ||
TideImageField | ||
} from '@dpc-sdp/ripple-tide-api/types' | ||
|
||
export interface ITideCompactCard { | ||
title: string | ||
summary?: string | ||
image?: TideImageField | ||
url: string | ||
} | ||
|
||
export interface ITideCompactCards { | ||
items: ITideCompactCard[] | ||
} | ||
|
||
export const compactCardsMapping = ( | ||
field | ||
): TideDynamicPageComponent<ITideCompactCards> => { | ||
return { | ||
component: 'TideLandingPageCategoryGrid', | ||
id: field.drupal_internal__id.toString(), | ||
title: field?.field_paragraph_title, | ||
props: { | ||
items: field.field_compact_card.map((item) => { | ||
return { | ||
title: item.field_paragraph_title, | ||
summary: item?.field_paragraph_summary, | ||
image: getImageFromField( | ||
item, | ||
'field_paragraph_media.field_media_image' | ||
), | ||
url: item.field_paragraph_link?.url | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
|
||
export const compactCardsIncludes = [ | ||
'field_landing_page_component.field_compact_card', | ||
'field_landing_page_component.field_compact_card.field_paragraph_media.field_media_image' | ||
] | ||
|
||
export default { | ||
includes: compactCardsIncludes, | ||
mapping: compactCardsMapping, | ||
contentTypes: ['landing_page'] | ||
} |
Oops, something went wrong.