diff --git a/.storybook/preview.js b/.storybook/preview.js index b495817..6f54cf9 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.js @@ -2,6 +2,7 @@ import { setCustomElementsManifest } from '@storybook/web-components'; import customElements from '../custom-elements.json'; import { globalTypesPrimer, decoratorsPrimer } from './primer-preview'; import { viewports } from './viewports'; +import { stringify, parseify } from '../src/utils'; import "./storybook.css"; setCustomElementsManifest(customElements); @@ -14,7 +15,8 @@ global.attrGen = (args) => Object.entries(args) .map(([key, value]) => `\n ${key}="${value}"`) .join(' '); -global.stringify = (obj) => JSON.stringify(obj).replace(/"/g, """) +global.stringify = stringify; +global.parseify = parseify; /** @type { import('@storybook/web-components').Preview } */ const preview = { diff --git a/src/devto/helpers/testing.js b/src/devto/helpers/testing.js index b5c2976..7b06a4a 100644 --- a/src/devto/helpers/testing.js +++ b/src/devto/helpers/testing.js @@ -20,6 +20,8 @@ export const generateMockResponse = (content, type='article', status=200) => { if (type === 'article') { // calls /articleS/:id (adds 's' to type) url += `${type}s/${content.id}`; + } else if (type === 'articles') { + url += `${type}/latest?per_page=1000&username=fake`; } else if (type === 'users') { if (!content.id) { url += `${type}/by_username?url=${content.username}`; @@ -30,9 +32,21 @@ export const generateMockResponse = (content, type='article', status=200) => { if (status === 404) { return { + url, + method: 'GET', status: 404, - error: "Not Found" + delay: 0, + response: { + status: 404, + error: "Not Found" + }, } } - return content + return { + url, + method: 'GET', + status: 200, + delay: 0, + response: content, + } } \ No newline at end of file diff --git a/src/devto/post/content.js b/src/devto/post/content.js index 80474ff..8b3a5fa 100644 --- a/src/devto/post/content.js +++ b/src/devto/post/content.js @@ -28,9 +28,10 @@ import { getApiUrl } from '../helpers/index.js'; * @ignore */ export const fetchPost = async (id) => { - const response = await fetch(`${getApiUrl()}/articles/${id}`, { + const options = { cache: 'no-cache', - }); + }; + const response = await fetch(`${getApiUrl()}/articles/${id}`, options); const repoJson = await response.json(); return repoJson; } @@ -42,9 +43,10 @@ export const fetchPost = async (id) => { * @ignore */ export const fetchUserPosts = async (username) => { - const articles = await fetch(`${getApiUrl()}/articles/latest?per_page=1000&username=${username?.toLowerCase()}`, { + const options = { cache: 'no-cache', - }); + }; + const articles = await fetch(`${getApiUrl()}/articles/latest?per_page=1000&username=${username?.toLowerCase()}`, options); const articlesJson = await articles.json(); return articlesJson; } diff --git a/src/devto/post/html.js b/src/devto/post/html.js index f3632b6..4fbecd2 100644 --- a/src/devto/post/html.js +++ b/src/devto/post/html.js @@ -7,12 +7,16 @@ * @memberof DEVUtils.post */ function html(content) { - if (content.error || !content.url || !content.title) { - return ''; + if (content.error) { + return ` +
+

${content.error}

+
+ ` } return ` - +