Skip to content

Commit bd228ff

Browse files
committed
feat: add unit tests for link-list block
1 parent 9c95bac commit bd228ff

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

blocks/hero/hero.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('Hero Block', () => {
2121
const sources = await page.$$('.hero-wrapper picture source');
2222
expect(sources.length).toBe(3);
2323

24+
await page.waitForSelector('.hero-wrapper picture img[loading="eager"]');
2425
const img = await page.$('.hero-wrapper picture img[loading="eager"]');
2526
expect(img).toExist();
2627
});

blocks/link-list/link-list.test.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
describe('Link-List Block', () => {
2+
beforeAll(async () => {
3+
await page.goto(`${global.BASE_URL}pattern-library/`);
4+
});
5+
6+
it('should render the link-list block', async () => {
7+
await page.waitForSelector('.link-list');
8+
const linkLists = await page.$$('.link-list');
9+
expect(linkLists.length).toBeGreaterThanOrEqual(1);
10+
});
11+
12+
it('should render the link-list title', async () => {
13+
await page.waitForSelector('.link-list__title');
14+
const linkListTitles = await page.$$('.link-list__title');
15+
expect(linkListTitles.length).toBeGreaterThanOrEqual(1);
16+
});
17+
18+
it('should render the link-list footer link, if it exists', async () => {
19+
await page.waitForSelector('.link-list > a');
20+
const linkListsWithFooterLink = await page.$$('.link-list > a');
21+
22+
if (linkListsWithFooterLink) {
23+
expect(linkListsWithFooterLink.length).toBeGreaterThanOrEqual(1);
24+
};
25+
})
26+
27+
describe('Link-List-Item', () => {
28+
beforeAll(async () => {
29+
await page.waitForSelector('.link-list-item');
30+
});
31+
32+
it('should apply an external link class when the link points outside of adobe.design', async () => {
33+
const linkListItemWithExternalLink = await page.$('.link-list-item:not([href^="https://adobe.design"])');
34+
35+
if (linkListItemWithExternalLink) {
36+
const hasExternalLinkClass = await linkListItemWithExternalLink.evaluate((el) => el.classList.contains('link-list-item--external'));
37+
expect(hasExternalLinkClass).toBe(true);
38+
} else {
39+
console.log('No link-list-items with external links found.');
40+
};
41+
});
42+
43+
it('should have job post classes applied when the link is a job posting', async () => {
44+
const linkListItemWithjobLink = await page.$('.link-list-item[href^="https://adobe.design/jobs/job-posts/"]');
45+
46+
if (linkListItemWithjobLink) {
47+
const linkListItemWithJobLinkChildren = await linkListItemWithjobLink.$$('span');
48+
49+
linkListItemWithJobLinkChildren.forEach(async (child) => {
50+
const classes = await child.evaluate((el) => el.classList);
51+
const hasJobClass = classes[0].startsWith('link-list-item__job');
52+
expect(hasJobClass).toBe(true);
53+
});
54+
} else {
55+
console.log('No link-list-items with job links found.');
56+
};
57+
});
58+
});
59+
});

0 commit comments

Comments
 (0)