summaryrefslogtreecommitdiffstats
path: root/tests/feed-atom.spec.js
diff options
context:
space:
mode:
authorSerghei Iakovlev <egrep@protonmail.ch>2024-08-18 19:16:54 +0200
committerSerghei Iakovlev <egrep@protonmail.ch>2024-08-18 21:35:36 +0200
commita571d0f988c866274cf260ddab6f3975328ae5e5 (patch)
tree7cadf3d51560be0b8cf4c8385e9865c8cf9a166d /tests/feed-atom.spec.js
parent1c5a7783ddada7e51641bfd2e7cceca04b568884 (diff)
downloadgohugo-theme-ed-a571d0f988c866274cf260ddab6f3975328ae5e5.tar.gz
Add test for atom feed dates
Diffstat (limited to 'tests/feed-atom.spec.js')
-rw-r--r--tests/feed-atom.spec.js44
1 files changed, 41 insertions, 3 deletions
diff --git a/tests/feed-atom.spec.js b/tests/feed-atom.spec.js
index 7e23328..4e62c2f 100644
--- a/tests/feed-atom.spec.js
+++ b/tests/feed-atom.spec.js
@@ -55,9 +55,6 @@ test('atom feed has correct author information', async ({ page }) => {
// Check if the name element exists
expect(nameElement).not.toBeNull();
- // Check if the name element has the correct type attribute
- expect(nameElement.getAttribute('type')).toBe('html');
-
// Check if the name element has the correct text content
expect(nameElement.textContent).not.toBeNull();
expect(nameElement.textContent.trim()).not.toBe('');
@@ -72,3 +69,44 @@ test('atom feed has correct author information', async ({ page }) => {
expect(emailElement.textContent).not.toBeNull();
expect(emailElement.textContent.trim()).not.toBe('');
});
+
+test('atom feed entries have correct published and updated fields', async ({ page }) => {
+ await page.goto('/feeds/feed.atom.xml');
+
+ // Get the content of the page
+ const content = await page.content();
+
+ // Create a new JSDOM instance
+ const dom = new JSDOM(content, { contentType: 'text/xml' });
+
+ // Get the global window object
+ const { window } = dom;
+
+ // Get all entry elements
+ const entries = window.document.querySelectorAll('feed > entry');
+
+ // Regex to match RFC 3339 date-time format
+ const rfc3339Regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:Z|[+-]\d{2}:\d{2})$/;
+
+ entries.forEach(entry => {
+ const publishedField = entry.querySelector('published');
+
+ // Check if the published field
+ // - exists
+ // - not empty
+ // - has the correct format
+ expect(publishedField).not.toBeNull();
+ expect(publishedField.textContent).not.toBe('');
+ expect(publishedField.textContent).toMatch(rfc3339Regex);
+
+ const updatedField = entry.querySelector('updated');
+
+ // Check if the updated field
+ // - exists
+ // - not empty
+ // - has the correct format
+ expect(updatedField).not.toBeNull();
+ expect(updatedField.textContent).not.toBe('');
+ expect(updatedField.textContent).toMatch(rfc3339Regex);
+ });
+});