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

WIP: src/components/__tests__: use snapshot test for testing icon rendering #456

Open
wants to merge 66 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
b2b8df1
banner challenge description icon test
Jun 21, 2024
a9e4b72
banner routes test icon
Jun 21, 2024
815367b
banner routes refactor test
Jun 21, 2024
eb1468e
banner routes app icon test
Jun 21, 2024
e4341c2
card challenge icon test
Jun 21, 2024
85fc8bf
card event icon tests
Jun 21, 2024
90f7b0c
card event icon test update
Jun 22, 2024
475f71f
card offer icon test
Jun 22, 2024
2d19105
card progress + test tweak
Jun 22, 2024
9a278ba
card progress icon tests
Jun 22, 2024
0dd8a24
card progress icon tests
Jun 22, 2024
c08e1c1
card progress slider icon test
Jun 22, 2024
46a0809
card progress slider icon tests
Jun 22, 2024
49f3c4c
card stats
Jun 22, 2024
2f35e7b
card stats icon tests
Jun 22, 2024
54d3446
contact form icon test
Jun 22, 2024
b990985
drawer header test icon
Jun 22, 2024
3dd931c
drawer menu icon tests
Jun 22, 2024
2bcdd4e
footer bar icon tests
Jun 22, 2024
608985f
form field option icon test
Jun 22, 2024
dc03a2e
form field password icon tets
Jun 22, 2024
c7b1984
form field password confirm comment
Jun 22, 2024
41ca69e
form login test icones
Jun 22, 2024
9c41b48
form login + register comments
Jun 22, 2024
a8f193e
help button update size + test icons
Jun 23, 2024
92737f1
list card progress test icons
Jun 23, 2024
eddd4a2
login-register buttons test icons
Jun 23, 2024
7124dab
menu links icon tet
Jun 24, 2024
7190865
newsletter item icon test
Jun 24, 2024
0f450f7
offer validation icon test
Jun 24, 2024
3422ef1
route item display icon test
Jun 24, 2024
d53f93e
route item edit icon test
Jun 24, 2024
b416cb7
slider progress icon test
Jun 24, 2024
4a9053a
update icon test command
Jun 24, 2024
0503198
icon test command remove scrollbar
Jun 26, 2024
c880fe1
cleanup unnecessary command
Jun 27, 2024
8253608
update snapshot names
Jun 27, 2024
2d11e9b
tweak command order
Jul 1, 2024
2798973
simplify icon test command
Jul 2, 2024
bb910a3
update context naming
Jul 3, 2024
535a7e0
icon test fix
Jul 3, 2024
0fd9938
update tests for problematic icons
Jul 3, 2024
8cb86c1
simplify command - do not check for size
Jul 4, 2024
5b345f7
fix selector for form login password icon
Jul 4, 2024
aa46d9a
update tests for problematic components
Jul 5, 2024
1273e2a
reintroduce dpr command
Jul 6, 2024
0b369ae
divide snapshots by browser
Jul 7, 2024
6bfac7b
cleanup old commands
Jul 7, 2024
0bf30e2
fix slider progress snapshot names
Jul 7, 2024
15e0b00
divide snapshots to folders by browser
Jul 7, 2024
ef5fe12
slider progress reorder tests
Jul 7, 2024
ed585cd
route item components test fix
Jul 7, 2024
c930679
set timeout for tests
Jul 8, 2024
1dfc56b
cleanup command
Jul 8, 2024
892800f
card progres viewport
Jul 8, 2024
710730e
Refactoring test icons snapshots
tmszi Jul 15, 2024
27c1862
Fix icon snaphot image name
tmszi Jul 15, 2024
1a4d247
Extend testIcon command func by click param with default true value
tmszi Jul 15, 2024
797d310
Disable click on the button icon to allow make icon img snaphot
tmszi Jul 15, 2024
f2be5e2
Disable click on the icon to allow make icon img snaphot
tmszi Jul 15, 2024
7b079cb
Disable click on the icon to allow make icon img snaphot
tmszi Jul 15, 2024
ccad7a4
Fix DrawerMenu component making menu items icons image snaphots
tmszi Jul 16, 2024
7adabf7
Use default viewport size
tmszi Jul 16, 2024
03628c6
Fix making icons snaphots with custom viewport with size 500x500
tmszi Jul 17, 2024
ebf70b5
Fix making icons snaphots with custom viewport with size 500x500
tmszi Jul 17, 2024
8a143ca
use cy.wrap for translation string evaluation
Jul 24, 2024
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
4 changes: 2 additions & 2 deletions src/components/__tests__/BadgeAchievement.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('<BadgeAchievement>', () => {
badge,
},
});
cy.viewport('macbook-16', { deviceScaleFactor: 1 });
cy.viewport('macbook-16');
});

it('renders title', () => {
Expand Down Expand Up @@ -80,7 +80,7 @@ describe('<BadgeAchievement>', () => {
badge: badgeDark,
},
});
cy.viewport('iphone-6', { deviceScaleFactor: 1 });
cy.viewport('iphone-6');
});

it('has dark background', () => {
Expand Down
27 changes: 24 additions & 3 deletions src/components/__tests__/BannerChallengeDescription.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('<BannerChallengeDescription>', () => {
});

function coreTests() {
const iconSize = 18;
it('renders component', () => {
cy.fixture('bannerChallengeDescription').then(
(bannerChallengeDescription) => {
Expand All @@ -53,9 +54,21 @@ function coreTests() {
.and(
'contain',
i18n.global.t('bannerChallengeDescription.transportType'),
)
.and('contain', getRouteIcon('bike'))
.and('contain', getRouteIcon('walk'));
);
// loop over icons
bannerChallengeDescription.transportTypes.forEach((type) => {
cy.dataCy(`challenge-transport-icon-${getRouteIcon(type)}`).then(
(element) => {
// test icon
cy.testIcon({
element: element,
name: `${Cypress.currentTest.titlePath}-banner-challenge-description-${getRouteIcon(type)}`,
size: iconSize,
click: false,
});
},
);
});
cy.dataCy('challenge-description')
.should('be.visible')
// test v-html content
Expand All @@ -71,6 +84,14 @@ function coreTests() {
cy.dataCy('challenge-link')
.find('a')
.should('have.attr', 'href', bannerChallengeDescription.link.url);
cy.dataCy('challenge-link-icon').then((element) => {
cy.testIcon({
element: element,
name: `${Cypress.currentTest.titlePath}-banner-challenge-description-launch`,
size: iconSize,
click: false,
});
});
},
);
});
Expand Down
78 changes: 36 additions & 42 deletions src/components/__tests__/BannerRoutes.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ describe('<BannerRoutes>', () => {
cy.viewport('macbook-16');
});

coreTests();

it('renders button icon with correct spacing', () => {
// icon additional tests
cy.dataCy('banner-routes-button-icon')
.should('be.visible')
.and('have.color', white)
.and('have.css', 'margin-right', '8px');
});

it('renders title with the number of missing routes', () => {
cy.window().then(() => {
cy.dataCy('banner-routes-title').should('contain', routesCount);
Expand Down Expand Up @@ -58,20 +68,6 @@ describe('<BannerRoutes>', () => {
.and('contain', i18n.global.t('index.bannerRoutes.addRoutes'));
});

it('renders button icon with correct spacing', () => {
cy.dataCy('banner-routes-button-icon')
.should('be.visible')
.and('have.color', white)
.and('have.css', 'margin-right', '8px')
.and('contain', 'add');
cy.dataCy('banner-routes-button-icon')
.invoke('height')
.should('equal', 24);
cy.dataCy('banner-routes-button-icon')
.invoke('width')
.should('equal', 24);
});

it('has gray background', () => {
cy.window().then(() => {
cy.dataCy('banner-routes-card')
Expand Down Expand Up @@ -111,6 +107,8 @@ describe('<BannerRoutes>', () => {
cy.viewport('macbook-16');
});

coreTests();

it('renders title width the "start" message', () => {
cy.window().then(() => {
cy.dataCy('banner-routes-title').should(
Expand Down Expand Up @@ -142,20 +140,6 @@ describe('<BannerRoutes>', () => {
.and('contain', i18n.global.t('index.bannerRoutes.addFirstRoutes'));
});

it('renders button icon with correct spacing', () => {
cy.dataCy('banner-routes-button-icon')
.should('be.visible')
.and('have.color', white)
.and('have.css', 'margin-right', '8px')
.and('contain', 'add');
cy.dataCy('banner-routes-button-icon')
.invoke('height')
.should('equal', 24);
cy.dataCy('banner-routes-button-icon')
.invoke('width')
.should('equal', 24);
});

it('has gray background', () => {
cy.window().then(() => {
cy.dataCy('banner-routes-card')
Expand Down Expand Up @@ -195,6 +179,8 @@ describe('<BannerRoutes>', () => {
cy.viewport('iphone-6');
});

coreTests();

it('renders title with the number of missing routes', () => {
cy.window().then(() => {
cy.dataCy('banner-routes-title')
Expand All @@ -220,20 +206,6 @@ describe('<BannerRoutes>', () => {
.and('contain', i18n.global.t('index.bannerRoutes.addRoutes'));
});

it('renders button icon with correct spacing', () => {
cy.dataCy('banner-routes-button-icon')
.should('be.visible')
.and('have.color', white)
.and('have.css', 'margin-right', '8px')
.and('contain', 'add');
cy.dataCy('banner-routes-button-icon')
.invoke('height')
.should('equal', 24);
cy.dataCy('banner-routes-button-icon')
.invoke('width')
.should('equal', 24);
});

it('has gray background', () => {
cy.window().then(() => {
cy.dataCy('banner-routes-card')
Expand Down Expand Up @@ -262,3 +234,25 @@ describe('<BannerRoutes>', () => {
});
});
});

function coreTests() {
it('renders button icon with correct spacing', () => {
cy.viewport(1280, 800).then(() => {
cy.window().then(() => {
// icon core test
cy.dataCy('banner-routes-button-icon').then((element) => {
cy.testIcon({
element,
name: `${Cypress.currentTest.titlePath}-add`,
size: 24,
});
});
});
});
// icon additional tests
cy.dataCy('banner-routes-button-icon')
.should('be.visible')
.and('have.color', white)
.and('have.css', 'margin-right', '8px');
});
}
10 changes: 7 additions & 3 deletions src/components/__tests__/BannerRoutesApp.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,13 @@ function coreTests() {
.and('have.css', 'font-weight', '400')
.and('have.color', black);
// Icon (should be visible when app is linked)
cy.dataCy('banner-routes-app-icon')
.should('be.visible')
.and('have.css', 'font-size', '18px');
cy.dataCy('banner-routes-app-icon').then((element) => {
cy.testIcon({
element: element,
name: 'banner-routes-app-check',
size: 18,
});
});
// Status (linked)
cy.dataCy('banner-routes-app-status')
.should('be.visible')
Expand Down
13 changes: 9 additions & 4 deletions src/components/__tests__/CardChallenge.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ describe('<CardChallenge>', () => {
.should('be.visible')
.and('have.backgroundColor', 'rgba(0, 0, 0, 0.47)')
.and('contain', title);
cy.dataCy('card-title')
.find('i')
.should('be.visible')
.and('contain', 'person');
cy.dataCy('card-challenge-title-icon', { timeout: 5000 }).then(
(element) => {
cy.testIcon({
element,
name: 'card-challenge-title-person',
size: 18,
});
},
);
cy.dataCy('card-title')
.find('a')
.should('have.css', 'font-size', '16px')
Expand Down
87 changes: 56 additions & 31 deletions src/components/__tests__/CardEvent.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { i18n } from '../../boot/i18n';
import { rideToWorkByBikeConfig } from 'src/boot/global_vars';

const { getPaletteColor } = colors;
const black = getPaletteColor('black');
const grey10 = getPaletteColor('grey-10');
const white = getPaletteColor('white');
const blueGrey2 = getPaletteColor('blue-grey-2');
const blueGrey3 = getPaletteColor('blue-grey-3');
Expand All @@ -14,6 +14,8 @@ const blueGrey7 = getPaletteColor('blue-grey-7');
const { borderRadiusCard } = rideToWorkByBikeConfig;

describe('<CardEvent>', () => {
const iconSize24 = 24;
const iconSize18 = 18;
context('desktop', () => {
beforeEach(() => {
cy.fixture('cardEvent').then((cardEvent) => {
Expand Down Expand Up @@ -90,11 +92,15 @@ describe('<CardEvent>', () => {
.and('contain', date)
.and('contain', year)
.and('contain', hour);
cy.dataCy('card-dates')
.find('i')
.should('be.visible')
.and('have.color', blueGrey2)
.and('contain', 'event');
cy.dataCy('card-event-date-icon')
.should('have.color', blueGrey2)
.then((element) => {
cy.testIcon({
element: element,
name: 'card-event-event',
size: iconSize24,
});
});
});
});
});
Expand All @@ -107,25 +113,42 @@ describe('<CardEvent>', () => {
.and('have.css', 'font-size', '14px')
.and('have.css', 'font-weight', '400')
.and('contain', cardEvent.location);
cy.dataCy('card-location')
.find('i')
.should('be.visible')
.and('have.color', blueGrey2)
.and('contain', 'place');
cy.dataCy('card-event-location-icon')
.should('have.color', blueGrey2)
.then((element) => {
cy.testIcon({
element: element,
name: 'card-event-location',
size: iconSize24,
});
});
});
});
});

it('renders calendar button with an icon', () => {
cy.window().then(() => {
// button
cy.dataCy('calendar-button')
.should('be.visible')
.and('have.css', 'height', '42px')
.and('have.css', 'width', '42px');
cy.dataCy('calendar-button')
.find('i')
.should('be.visible')
.and('have.color', black);
// icon
/*
* Change viewport fix: `The "target" argument must be an instance
* of Buffer or Uint8Array. Received null` error
*/
cy.viewport(500, 500).then(() => {
cy.dataCy('card-event-calendar-icon')
.and('have.color', grey10)
.then((element) => {
cy.testIcon({
element: element,
name: 'card-event-calendar',
size: iconSize18,
});
});
});
});
});

Expand Down Expand Up @@ -168,27 +191,29 @@ describe('<CardEvent>', () => {
.should('contain', '1.')
.and('contain', '2023')
.and('contain', '12:00');
const $icon = $el.find('i');
if ($icon.length) {
cy.wrap($icon)
.should('be.visible')
.and('have.color', blueGrey3)
.and('have.css', 'width', '18px')
.and('have.css', 'height', '18px');
}
}
if (index === 1) {
cy.wrap($el).should('contain', cardEvent.location);
const $icon = $el.find('i');
if ($icon.length) {
cy.wrap($icon)
.should('be.visible')
.and('have.color', blueGrey3)
.and('have.css', 'width', '18px')
.and('have.css', 'height', '18px');
}
}
});
cy.dataCy('dialog-event-date-icon')
.should('have.color', blueGrey3)
.then((element) => {
cy.testIcon({
element: element,
name: 'card-event-dialog-event',
size: iconSize18,
});
});
cy.dataCy('dialog-event-location-icon')
.should('have.color', blueGrey3)
.then((element) => {
cy.testIcon({
element: element,
name: 'card-event-dialog-location',
size: iconSize18,
});
});
});
});
});
Expand Down
10 changes: 4 additions & 6 deletions src/components/__tests__/CardOffer.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,10 @@ function coreTests() {
it('renders icon', () => {
cy.window().then(() => {
cy.get('@card').then((card) => {
cy.dataCy('card-icon')
.should('be.visible')
.and('have.class', card.icon)
.and('have.css', 'height', '48px')
.and('have.css', 'width', '48px')
.and('have.color', 'rgb(176, 190, 197)');
cy.dataCy('card-icon').then((element) => {
cy.testIcon({ element, name: `card-offer-${card.icon}`, size: 48 });
});
cy.dataCy('card-icon').should('have.class', card.icon);
});
});
});
Expand Down
Loading