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

src/components/homepage: update NewsletterFeature styling based on graphic design #552

Merged
merged 5 commits into from
Sep 6, 2024
Merged
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
Binary file not shown.
163 changes: 94 additions & 69 deletions src/components/__tests__/NewsletterFeature.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,43 @@ import { colors } from 'quasar';
import NewsletterFeature from '../homepage/NewsletterFeature.vue';
import { i18n } from '../../boot/i18n';

// colors
const { getPaletteColor } = colors;
const black = getPaletteColor('black');
const grey10 = getPaletteColor('grey-10');
const primary = getPaletteColor('primary');

// selectors
const selectorSectionHeadingTitle = 'section-heading-title';
const selectorSectionHeadingPerex = 'section-heading-perex';
const selectorNewsletterFeatureImage = 'newsletter-feature-image';
const selectorNewsletterFeatureItem = 'newsletter-feature-item';
const selectorNewsletterFeatureSeparator = 'newsletter-feature-separator';
const selectorNewsletterColImage = 'newsletter-col-image';
const selectorNewsletterColContent = 'newsletter-col-content';

// variables
const fontSizeTitle = '24px';
const fontWeightBold = '700';
const fontSizePerex = '14px';
const fontWeightRegular = '400';
const marginMd = '16px';
const props = {
title: 'Custom title',
description: 'Custom description',
};

describe('<NewsletterFeature>', () => {
it('has translation for all strings', () => {
cy.testLanguageStringsInContext(
[
'title',
'description',
'aboutChallenges',
'aboutEvents',
'aboutMobility',
'description',
'following',
'follow',
'hint',
'title',
],
'index.newsletterFeature',
i18n,
Expand All @@ -30,43 +53,15 @@ describe('<NewsletterFeature>', () => {
cy.viewport('macbook-16');
});

it('renders title', () => {
cy.window().then(() => {
cy.dataCy('section-heading-title')
.should('have.css', 'font-size', '20px')
.and('have.css', 'font-weight', '500')
.and('have.color', black)
.and('contain', i18n.global.t('index.newsletterFeature.title'))
.then(($title) => {
expect($title.text()).to.contain(
i18n.global.t('index.newsletterFeature.title'),
);
});
});
});

it('renders description', () => {
cy.window().then(() => {
cy.dataCy('section-heading-perex')
.should('have.css', 'font-size', '14px')
.and('have.css', 'font-weight', '400')
.and('have.color', black)
.and('contain', i18n.global.t('index.newsletterFeature.description'))
.then(($title) => {
expect($title.text()).to.contain(
i18n.global.t('index.newsletterFeature.description'),
);
});
});
});
coreTests();

it('renders image', () => {
cy.window().then(() => {
cy.dataCy('newsletter-feature-image')
cy.dataCy(selectorNewsletterFeatureImage)
.should('be.visible')
.find('img')
.should('be.visible');
cy.dataCy('newsletter-feature-image').matchImageSnapshot({
cy.dataCy(selectorNewsletterFeatureImage).matchImageSnapshot({
failureThreshold: 0.5,
failureThresholdType: 'percent',
});
Expand All @@ -75,7 +70,7 @@ describe('<NewsletterFeature>', () => {

it('renders correct number of items', () => {
cy.window().then(() => {
cy.dataCy('newsletter-feature-item')
cy.dataCy(selectorNewsletterFeatureItem)
.should('have.length', 3)
.each(($item) => {
cy.wrap($item).should('be.visible');
Expand All @@ -85,73 +80,103 @@ describe('<NewsletterFeature>', () => {

it('renders divider between items', () => {
cy.window().then(() => {
cy.dataCy('newsletter-feature-separator')
cy.dataCy(selectorNewsletterFeatureSeparator)
.should('be.visible')
.and('have.length', 2)
.and('have.css', 'margin-top', '16px')
.and('have.css', 'margin-bottom', '16px');
.and('have.css', 'margin-top', marginMd)
.and('have.css', 'margin-bottom', marginMd);
});
});

it('renders grid', () => {
cy.window().then(() => {
cy.testElementPercentageWidth(cy.dataCy('newsletter-col-image'), 16.6);
cy.testElementPercentageWidth(
cy.dataCy('newsletter-col-content'),
83.3,
cy.dataCy(selectorNewsletterColImage),
25,
);
cy.testElementPercentageWidth(
cy.dataCy(selectorNewsletterColContent),
75,
);
});
});
});

context('mobile', () => {
context('desktop override props', () => {
beforeEach(() => {
cy.mount(NewsletterFeature, {
props: {},
props,
});
cy.viewport('iphone-6');
cy.viewport('macbook-16');
});

it('renders title', () => {
cy.window().then(() => {
cy.dataCy('section-heading-title')
.should('have.css', 'font-size', '20px')
.and('have.css', 'font-weight', '500')
.and('have.color', black)
.and('contain', i18n.global.t('index.newsletterFeature.title'))
.then(($title) => {
expect($title.text()).to.contain(
i18n.global.t('index.newsletterFeature.title'),
);
});
});
cy.dataCy(selectorSectionHeadingTitle).should('contain', props.title);
});

it('renders description', () => {
cy.window().then(() => {
cy.dataCy('section-heading-perex')
.should('have.css', 'font-size', '14px')
.and('have.css', 'font-weight', '400')
.and('have.color', black)
.and('contain', i18n.global.t('index.newsletterFeature.description'))
.then(($title) => {
expect($title.text()).to.contain(
i18n.global.t('index.newsletterFeature.description'),
);
});
cy.dataCy(selectorSectionHeadingPerex).should(
'contain',
props.description,
);
});
});

context('mobile', () => {
beforeEach(() => {
cy.mount(NewsletterFeature, {
props: {},
});
cy.viewport('iphone-6');
});

coreTests();

it('does not render image', () => {
cy.window().then(() => {
cy.dataCy('newsletter-feature-image').should('not.be.visible');
cy.dataCy(selectorNewsletterFeatureImage).should('not.be.visible');
});
});

it('renders grid', () => {
cy.window().then(() => {
cy.testElementPercentageWidth(cy.dataCy('newsletter-col-content'), 100);
cy.testElementPercentageWidth(
cy.dataCy(selectorNewsletterColContent),
100,
);
});
});
});
});

function coreTests() {
it('renders title', () => {
cy.window().then(() => {
cy.dataCy(selectorSectionHeadingTitle)
.should('have.css', 'font-size', fontSizeTitle)
.and('have.css', 'font-weight', fontWeightBold)
.and('have.color', primary)
.and('contain', i18n.global.t('index.newsletterFeature.title'))
.then(($title) => {
expect($title.text()).to.contain(
i18n.global.t('index.newsletterFeature.title'),
);
});
});
});

it('renders description', () => {
cy.window().then(() => {
cy.dataCy(selectorSectionHeadingPerex)
.should('have.css', 'font-size', fontSizePerex)
.and('have.css', 'font-weight', fontWeightRegular)
.and('have.color', grey10)
.and('contain', i18n.global.t('index.newsletterFeature.description'))
.then(($title) => {
expect($title.text()).to.contain(
i18n.global.t('index.newsletterFeature.description'),
);
});
});
});
}
Loading
Loading