Skip to content

Commit

Permalink
chore(SLB-497): update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chindris committed Dec 3, 2024
1 parent 98fb30f commit 1d69722
Show file tree
Hide file tree
Showing 2 changed files with 262 additions and 25 deletions.
65 changes: 60 additions & 5 deletions tests/e2e/specs/drupal/metatags.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,74 @@ import { expect, test } from '@playwright/test';
import { websiteUrl } from '../../helpers/url';

test('Metatags on Basic page', async ({ page }) => {
const pageUrl = websiteUrl('/en/page-complete');
await page.goto(pageUrl);
// This is a page with all the SEO fields empty. In this case:
// - the title should fallback to the node title.
// - the description and image_src should be empty.
const allEmptyUrlEn = websiteUrl('/en/seo-test-all-empty');
await page.goto(allEmptyUrlEn);
await expect(page.locator('head meta[name="title"]')).toHaveAttribute(
'content',
'Page: complete | Silverback Drupal Template',
'SEO test - all empty | Silverback Drupal Template',
);
await expect(page.locator('head meta[name="description"]')).toHaveCount(0);
await expect(page.locator('head meta[rel="image_src"]')).toHaveCount(0);
await expect(page.locator('head link[rel="canonical"]')).toHaveAttribute(
'href',
allEmptyUrlEn,
);

// Check also its German translation.
const allEmptyUrlDe = websiteUrl('/de/seo-test-all-empty-de');
await page.goto(allEmptyUrlDe);
await expect(page.locator('head meta[name="title"]')).toHaveAttribute(
'content',
'SEO test - all empty DE | Silverback Drupal Template',
);
await expect(page.locator('head meta[name="description"]')).toHaveCount(0);
await expect(page.locator('head meta[rel="image_src"]')).toHaveCount(0);
await expect(page.locator('head link[rel="canonical"]')).toHaveAttribute(
'href',
allEmptyUrlDe,
);

// The next page is one where all the SEO fields (the title, description and
// image) are filled in.
const allFilledUrlEn = websiteUrl('/en/seo-test-all-filled');
await page.goto(allFilledUrlEn);
await expect(page.locator('head meta[name="title"]')).toHaveAttribute(
'content',
'Overwritten SEO title | Silverback Drupal Template',
);
await expect(page.locator('head meta[name="description"]')).toHaveAttribute(
'content',
'Headline Lead text Paragraph',
'SEO description',
);
await expect(page.locator('head link[rel="canonical"]')).toHaveAttribute(
'href',
pageUrl,
allFilledUrlEn,
);
await expect(page.locator('head link[rel="image_src"]')).toHaveAttribute(
'href',
'/sites/default/files/2024-04/the_silverback.jpeg',
);

const allFilledUrlDe = websiteUrl('/de/seo-test-all-filled-de');
await page.goto(allFilledUrlDe);
await expect(page.locator('head meta[name="title"]')).toHaveAttribute(
'content',
'Overwritten SEO title DE | Silverback Drupal Template',
);
await expect(page.locator('head meta[name="description"]')).toHaveAttribute(
'content',
'SEO description DE',
);
await expect(page.locator('head link[rel="canonical"]')).toHaveAttribute(
'href',
allFilledUrlDe,
);
await expect(page.locator('head link[rel="image_src"]')).toHaveAttribute(
'href',
'/sites/default/files/2024-04/the_silverback.jpeg',
);
});

Expand Down
222 changes: 202 additions & 20 deletions tests/schema/specs/content.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ test('Page', async () => {
minimal: _loadDrupalPage(id: "17626bb4-557f-48fc-b869-ae566f4ceae6") {
...Page
}
seo_all_empty: _loadDrupalPage(id: "5f108e07-62ca-4025-adca-069b3adfc22c") {
translations {
...Page
}
}
seo_all_filled_in: _loadDrupalPage(id: "6344bdc5-1b02-4542-b4ae-4e6df23b3e4c") {
translations {
...Page
}
}
}
`);
expect(result).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -65,16 +75,6 @@ test('Page', async () => {
},
"tag": "meta",
},
{
"attributes": {
"content": "Headline Lead text Paragraph",
"href": null,
"name": "description",
"property": null,
"rel": null,
},
"tag": "meta",
},
{
"attributes": {
"content": null,
Expand Down Expand Up @@ -113,16 +113,6 @@ test('Page', async () => {
},
"tag": "meta",
},
{
"attributes": {
"content": "",
"href": null,
"name": "description",
"property": null,
"rel": null,
},
"tag": "meta",
},
{
"attributes": {
"content": null,
Expand All @@ -138,6 +128,198 @@ test('Page', async () => {
"teaserImage": null,
"title": "Page: minimal",
},
"seo_all_empty": {
"translations": [
{
"content": [
{
"__typename": "BlockMarkup",
},
],
"hero": {
"__typename": "Hero",
},
"locale": "en",
"metaTags": [
{
"attributes": {
"content": "SEO test - all empty | Silverback Drupal Template",
"href": null,
"name": "title",
"property": null,
"rel": null,
},
"tag": "meta",
},
{
"attributes": {
"content": null,
"href": "http://127.0.0.1:8000/en/seo-test-all-empty",
"name": null,
"property": null,
"rel": "canonical",
},
"tag": "link",
},
],
"path": "/en/seo-test-all-empty",
"teaserImage": null,
"title": "SEO test - all empty",
},
{
"content": [
{
"__typename": "BlockMarkup",
},
],
"hero": {
"__typename": "Hero",
},
"locale": "de",
"metaTags": [
{
"attributes": {
"content": "SEO test - all empty DE | Silverback Drupal Template",
"href": null,
"name": "title",
"property": null,
"rel": null,
},
"tag": "meta",
},
{
"attributes": {
"content": null,
"href": "http://127.0.0.1:8000/de/seo-test-all-empty-de",
"name": null,
"property": null,
"rel": "canonical",
},
"tag": "link",
},
],
"path": "/de/seo-test-all-empty-de",
"teaserImage": null,
"title": "SEO test - all empty DE",
},
],
},
"seo_all_filled_in": {
"translations": [
{
"content": [
{
"__typename": "BlockMarkup",
},
],
"hero": {
"__typename": "Hero",
},
"locale": "en",
"metaTags": [
{
"attributes": {
"content": "Overwritten SEO title | Silverback Drupal Template",
"href": null,
"name": "title",
"property": null,
"rel": null,
},
"tag": "meta",
},
{
"attributes": {
"content": "SEO description",
"href": null,
"name": "description",
"property": null,
"rel": null,
},
"tag": "meta",
},
{
"attributes": {
"content": null,
"href": "http://127.0.0.1:8000/en/seo-test-all-filled",
"name": null,
"property": null,
"rel": "canonical",
},
"tag": "link",
},
{
"attributes": {
"content": null,
"href": "/sites/default/files/2024-04/the_silverback.jpeg",
"name": null,
"property": null,
"rel": "image_src",
},
"tag": "link",
},
],
"path": "/en/seo-test-all-filled",
"teaserImage": null,
"title": "SEO test - all filled in",
},
{
"content": [
{
"__typename": "BlockMarkup",
},
],
"hero": {
"__typename": "Hero",
},
"locale": "de",
"metaTags": [
{
"attributes": {
"content": "Overwritten SEO title DE | Silverback Drupal Template",
"href": null,
"name": "title",
"property": null,
"rel": null,
},
"tag": "meta",
},
{
"attributes": {
"content": "SEO description DE",
"href": null,
"name": "description",
"property": null,
"rel": null,
},
"tag": "meta",
},
{
"attributes": {
"content": null,
"href": "http://127.0.0.1:8000/de/seo-test-all-filled-de",
"name": null,
"property": null,
"rel": "canonical",
},
"tag": "link",
},
{
"attributes": {
"content": null,
"href": "/sites/default/files/2024-04/the_silverback.jpeg",
"name": null,
"property": null,
"rel": "image_src",
},
"tag": "link",
},
],
"path": "/de/seo-test-all-filled-de",
"teaserImage": null,
"title": "SEO test - all filled in DE",
},
],
},
},
}
`);
Expand Down

0 comments on commit 1d69722

Please sign in to comment.