@treely/strapi-slices 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treely/strapi-slices",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "license": "MIT",
5
5
  "author": "Tree.ly GmbH",
6
6
  "description": "@treely/strapi-slices is a open source library maintained by Tree.ly.",
@@ -18,4 +18,5 @@ export const SECTIONS_WITH_PROJECTS = [
18
18
  'sections.projects-grid',
19
19
  'sections.projects-map',
20
20
  'sections.project-facts',
21
+ 'sections.text-with-card',
21
22
  ];
@@ -1,10 +1,20 @@
1
- import IStrapi from './IStrapi';
2
1
  import IStrapiData from './IStrapiData';
2
+ import StrapiImage from './StrapiImage';
3
3
  import StrapiProject from './StrapiProject';
4
4
 
5
5
  interface StrapiProjectCard {
6
6
  id: number;
7
- project: IStrapi<IStrapiData<StrapiProject>>;
7
+ title: string;
8
+ facts: {
9
+ id: number;
10
+ text: string;
11
+ }[];
12
+ footerTitle: string;
13
+ footerSubTitle: string;
14
+ image: StrapiImage;
15
+ project?: {
16
+ data?: IStrapiData<StrapiProject>;
17
+ };
8
18
  }
9
19
 
10
20
  export default StrapiProjectCard;
@@ -3,6 +3,7 @@ import { StoryFn, Meta } from '@storybook/react';
3
3
 
4
4
  import ProjectsGrid from '.';
5
5
  import portfolioProjectMock from '../../test/integrationMocks/portfolioProjectMock';
6
+ import { strapiProjectMock } from '../../test/strapiMocks/strapiProject';
6
7
 
7
8
  export default {
8
9
  title: 'slices/ProjectsGrid',
@@ -16,4 +17,7 @@ const Template: StoryFn<typeof ProjectsGrid> = (args) => (
16
17
  export const Minimal = Template.bind({});
17
18
  Minimal.args = {
18
19
  projects: [portfolioProjectMock],
20
+ slice: {
21
+ projects: { data: [strapiProjectMock] },
22
+ },
19
23
  };
@@ -1,8 +1,7 @@
1
1
  import React from 'react';
2
2
  import { StoryFn, Meta } from '@storybook/react';
3
3
 
4
- import portfolioProjectMock from '../../test/integrationMocks/portfolioProjectMock';
5
- import { strapiProjectMock } from '../../test/strapiMocks/strapiProject';
4
+ import { storybookStrapiCoverMock } from '../../test/storybookMocks/storybookStrapiMedia';
6
5
  import TextWithCard from '.';
7
6
 
8
7
  export default {
@@ -22,9 +21,21 @@ const listItems = [
22
21
  const button = { id: 1, text: 'Button', url: 'https://tree.ly' };
23
22
  const card = {
24
23
  id: 1,
25
- project: { data: strapiProjectMock },
24
+ image: {
25
+ id: 1,
26
+ alt: 'Image alt text',
27
+ img: { data: storybookStrapiCoverMock },
28
+ },
29
+ title: 'Card title',
30
+ facts: [
31
+ { id: 1, text: 'Fact 1' },
32
+ { id: 2, text: 'Fact 2' },
33
+ { id: 3, text: 'Fact 3' },
34
+ { id: 4, text: 'Fact 4' },
35
+ ],
36
+ footerTitle: 'Footer title',
37
+ footerSubTitle: 'Footer sub title',
26
38
  };
27
- const projects = [{ ...portfolioProjectMock, slug: 'slug' }];
28
39
 
29
40
  export const Minimal = Template.bind({});
30
41
  Minimal.args = {
@@ -32,7 +43,6 @@ Minimal.args = {
32
43
  title: 'Title',
33
44
  cardPosition: 'left',
34
45
  },
35
- projects,
36
46
  };
37
47
 
38
48
  export const WithTagline = Template.bind({});
@@ -42,7 +52,6 @@ WithTagline.args = {
42
52
  title: 'Title',
43
53
  cardPosition: 'left',
44
54
  },
45
- projects,
46
55
  };
47
56
 
48
57
  export const WithTaglineAndText = Template.bind({});
@@ -53,7 +62,6 @@ WithTaglineAndText.args = {
53
62
  text: 'Text',
54
63
  cardPosition: 'left',
55
64
  },
56
- projects,
57
65
  };
58
66
 
59
67
  export const WithList = Template.bind({});
@@ -65,7 +73,6 @@ WithList.args = {
65
73
  listItems,
66
74
  cardPosition: 'left',
67
75
  },
68
- projects,
69
76
  };
70
77
 
71
78
  export const WithButton = Template.bind({});
@@ -78,7 +85,6 @@ WithButton.args = {
78
85
  button,
79
86
  cardPosition: 'left',
80
87
  },
81
- projects,
82
88
  };
83
89
 
84
90
  export const WithCard = Template.bind({});
@@ -92,7 +98,6 @@ WithCard.args = {
92
98
  card,
93
99
  cardPosition: 'left',
94
100
  },
95
- projects,
96
101
  };
97
102
 
98
103
  export const WithCardOnRight = Template.bind({});
@@ -106,5 +111,4 @@ WithCardOnRight.args = {
106
111
  card,
107
112
  cardPosition: 'right',
108
113
  },
109
- projects,
110
114
  };
@@ -3,27 +3,17 @@ import { render, screen } from '../../test/testUtils';
3
3
  import { strapiProjectCardMock } from '../../test/strapiMocks/strapiProjectCard';
4
4
  import TextWithCard from '.';
5
5
  import { TextWithCardProps } from './TextWithCard';
6
- import fpmProjectMock from '../../test/integrationMocks/fpmProjectMock';
7
- import { strapiMediaMock } from '../../test/strapiMocks/strapiMedia';
8
- import CreditsAvailableState from '../../models/CreditsAvailableState';
6
+ import { strapiProjectMock } from '../../test/strapiMocks/strapiProject';
7
+ import portfolioProjectMock from '../../test/mocks/portfolioProjectMock';
9
8
 
10
9
  const defaultProps: TextWithCardProps = {
10
+ projects: [],
11
11
  slice: {
12
12
  tagline: 'Tagline',
13
13
  title: 'Title',
14
14
  text: 'Text',
15
15
  cardPosition: 'left',
16
16
  },
17
- projects: [
18
- {
19
- ...fpmProjectMock,
20
- slug: 'slug',
21
- isPublic: true,
22
- thumbnail: { img: { data: strapiMediaMock }, alt: 'Alt Text', id: 1 },
23
- footerSubTitle: 'certified-123',
24
- creditsAvailable: CreditsAvailableState.YES,
25
- },
26
- ],
27
17
  };
28
18
 
29
19
  const setup = (props = {}) => {
@@ -74,15 +64,26 @@ describe('The TextWithCard component', () => {
74
64
  it('displays no card if there is no card in the slice', () => {
75
65
  setup();
76
66
 
77
- expect(screen.queryByText(fpmProjectMock.title)).not.toBeInTheDocument();
67
+ expect(
68
+ screen.queryByText(strapiProjectCardMock.title)
69
+ ).not.toBeInTheDocument();
78
70
  });
79
71
 
80
- it('displays the card if a project has been selected', () => {
72
+ it('displays a card if there is a card in the slice', () => {
81
73
  setup({
82
74
  slice: { ...defaultProps.slice, card: strapiProjectCardMock },
83
75
  });
84
76
 
85
- expect(screen.getByText(fpmProjectMock.title)).toBeInTheDocument();
77
+ expect(screen.getByText(strapiProjectCardMock.title)).toBeInTheDocument();
78
+ });
79
+
80
+ it('displays the card, filled with information from the FPM if a project is selected', () => {
81
+ setup({
82
+ projects: [portfolioProjectMock],
83
+ slice: { ...defaultProps.slice, project: { data: strapiProjectMock } },
84
+ });
85
+
86
+ expect(screen.getByText(portfolioProjectMock.title)).toBeInTheDocument();
86
87
  });
87
88
 
88
89
  const cardPositions = ['left', 'right'];
@@ -4,15 +4,18 @@ import {
4
4
  DefaultSectionHeader,
5
5
  Grid,
6
6
  GridItem,
7
+ ProjectCard,
7
8
  Spacer,
8
9
  BoemlyList,
9
10
  Wrapper,
10
11
  } from 'boemly';
12
+ import Image from 'next/image';
11
13
  import { ArrowRight } from '@phosphor-icons/react';
14
+ import strapiMediaUrl from '../../utils/strapiMediaUrl';
12
15
  import StrapiLink from '../../models/strapi/StrapiLink';
13
16
  import StrapiProjectCard from '../../models/strapi/StrapiProjectCard';
14
17
  import StrapiLinkButton from '../../components/StrapiLinkButton';
15
- import PortfolioProject from '../../models/PortfolioProject';
18
+ import { IStrapi, IStrapiData, PortfolioProject, StrapiProject } from '../..';
16
19
  import PortfolioProjectCard from '../../components/portfolio/PortfolioProjectCard';
17
20
 
18
21
  interface TextWithCardSlice {
@@ -25,6 +28,7 @@ interface TextWithCardSlice {
25
28
  }[];
26
29
  button?: StrapiLink;
27
30
  card?: StrapiProjectCard;
31
+ project?: IStrapi<IStrapiData<StrapiProject>>;
28
32
  cardPosition: 'left' | 'right';
29
33
  }
30
34
  export interface TextWithCardProps {
@@ -36,8 +40,10 @@ export const TextWithCard: React.FC<TextWithCardProps> = ({
36
40
  slice,
37
41
  projects,
38
42
  }: TextWithCardProps) => {
39
- const fpmData = projects.find(
40
- (project) => project.slug === slice.card?.project?.data.attributes.slug
43
+ const portfolioProject = projects.find(
44
+ (p) =>
45
+ slice.project?.data.attributes.fpmProjectId &&
46
+ p.id === slice.project?.data.attributes.fpmProjectId
41
47
  );
42
48
 
43
49
  const card = (
@@ -47,8 +53,22 @@ export const TextWithCard: React.FC<TextWithCardProps> = ({
47
53
  position="relative"
48
54
  data-testid={`card-position-${slice.cardPosition}`}
49
55
  >
50
- {slice.card && fpmData && (
51
- <PortfolioProjectCard project={{ ...slice.card, ...fpmData }} />
56
+ {portfolioProject && <PortfolioProjectCard project={portfolioProject} />}
57
+ {!portfolioProject && slice.card && (
58
+ <ProjectCard
59
+ facts={slice.card.facts}
60
+ footerSubTitle={slice.card.footerSubTitle}
61
+ footerTitle={slice.card.footerTitle}
62
+ title={slice.card.title}
63
+ image={
64
+ <Image
65
+ src={strapiMediaUrl(slice.card.image.img, 'medium')}
66
+ alt={slice.card.image.alt}
67
+ fill
68
+ style={{ objectFit: slice.card.image.objectFit || 'cover' }}
69
+ />
70
+ }
71
+ />
52
72
  )}
53
73
  </GridItem>
54
74
  );
@@ -1,7 +1,20 @@
1
1
  import StrapiProjectCard from '../../models/strapi/StrapiProjectCard';
2
+ import { strapiMediaMock } from './strapiMedia';
2
3
  import { strapiProjectMock } from './strapiProject';
3
4
 
4
5
  export const strapiProjectCardMock: StrapiProjectCard = {
5
6
  id: 1,
7
+ title: 'My forest',
8
+ facts: [
9
+ { id: 1, text: 'text1' },
10
+ { id: 2, text: 'text2' },
11
+ ],
12
+ footerTitle: 'Footer title',
13
+ footerSubTitle: 'Footer sub title',
14
+ image: {
15
+ id: 1,
16
+ alt: 'Alt text',
17
+ img: { data: strapiMediaMock },
18
+ },
6
19
  project: { data: strapiProjectMock },
7
20
  };