Skip to content
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

refactor: create contentful entryHasContentType util #2359

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/portal/src/components/content/ContentSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
</template>

<script>
import contentfulMixin from '@/mixins/contentful.js';
import contentfulEntryHasContentType from '@/utils/contentful/entryHasContentType.js';

export default {
name: 'ContentSection',
Expand All @@ -86,8 +86,6 @@
StoryImageTextSlideScroller: () => import('../story/StoryImageTextSlideScroller')
},

mixins: [contentfulMixin],

props: {
richTextIsCard: {
type: Boolean,
Expand All @@ -101,6 +99,7 @@
},

methods: {
contentfulEntryHasContentType,
attributionFields(fields) {
return {
name: fields?.name,
Expand Down
5 changes: 3 additions & 2 deletions packages/portal/src/components/landing/LandingPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
import kebabCase from 'lodash/kebabCase';
import LandingHero from './LandingHero';
import landingPageMixin from '@/mixins/landingPage.js';
import contentfulMixin from '@/mixins/contentful.js';
import contentfulEntryHasContentType from '@/utils/contentful/entryHasContentType.js';

export default {
name: 'LandingPage',
Expand All @@ -112,7 +112,6 @@
},

mixins: [
contentfulMixin,
landingPageMixin
],

Expand Down Expand Up @@ -156,6 +155,8 @@
},

methods: {
contentfulEntryHasContentType,

getClasses(section) {
const classes = [];
if (section.profile?.background) {
Expand Down
8 changes: 6 additions & 2 deletions packages/portal/src/components/landing/LandingSubSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</template>

<script>
import contentfulMixin from '@/mixins/contentful.js';
import contentfulEntryHasContentType from '@/utils/contentful/entryHasContentType.js';
import parseMarkdownHtmlMixin from '@/mixins/parseMarkdownHtml';

export default {
Expand All @@ -66,7 +66,7 @@
LandingInfoCardGroup: () => import('@/components/landing/LandingInfoCardGroup')
},

mixins: [contentfulMixin, parseMarkdownHtmlMixin],
mixins: [parseMarkdownHtmlMixin],

props: {
/**
Expand Down Expand Up @@ -105,6 +105,10 @@
return {
LandingInfoCardGroupClass: this.$route.params.pathMatch === 'share-your-data' ? 'logo' : null
};
},

methods: {
contentfulEntryHasContentType
}
};
</script>
Expand Down
7 changes: 0 additions & 7 deletions packages/portal/src/mixins/contentful.js

This file was deleted.

3 changes: 3 additions & 0 deletions packages/portal/src/utils/contentful/entryHasContentType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default (entry, contentType) => {
return entry && (entry['__typename'] === contentType);
};
41 changes: 0 additions & 41 deletions packages/portal/tests/unit/mixins/contentful.spec.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import contentfulEntryHasContentType from '@/utils/contentful/entryHasContentType.js';

describe('utils/contentful/entryHasContentType', () => {
describe('contentfulEntryHasContentType', () => {
it('is true when `__typename` property matches', () => {
const hasType = contentfulEntryHasContentType(
{ '__typename': 'blogPosting' }, 'blogPosting'
);

expect(hasType).toBe(true);
});

it('is false when `__typename` property does not match', () => {
const hasType = contentfulEntryHasContentType(
{ '__typename': 'landingPage' }, 'blogPosting'
);

expect(hasType).toBe(false);
});
});
});
Loading