generated from Seekra/repository-template
style: format code using Prettier
This commit is contained in:
@@ -15,8 +15,8 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
export class FetchError extends Error {
|
||||
constructor (message) {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = 'FetchError';
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -60,29 +60,25 @@ describe('fetchLegalContent', () => {
|
||||
describe('getLegalNotice', () => {
|
||||
describe('success', () => {
|
||||
test('returns HTML body', async () => {
|
||||
fetchSpy.mockResolvedValue(
|
||||
new Response(exampleHtmlDocument)
|
||||
);
|
||||
fetchSpy.mockResolvedValue(new Response(exampleHtmlDocument));
|
||||
|
||||
expect(
|
||||
(await getLegalNotice()).trim()
|
||||
).toBe(exampleHtmlWithLinkClass);
|
||||
expect((await getLegalNotice()).trim()).toBe(
|
||||
exampleHtmlWithLinkClass,
|
||||
);
|
||||
});
|
||||
|
||||
test('returns HTML <main>', async () => {
|
||||
fetchSpy.mockResolvedValue(
|
||||
new Response(exampleHtmlDocumentWithMain)
|
||||
new Response(exampleHtmlDocumentWithMain),
|
||||
);
|
||||
|
||||
expect(
|
||||
(await getLegalNotice()).trim()
|
||||
).toBe(exampleHtmlWithLinkClass);
|
||||
expect((await getLegalNotice()).trim()).toBe(
|
||||
exampleHtmlWithLinkClass,
|
||||
);
|
||||
});
|
||||
|
||||
test('does not fail on success status code', async () => {
|
||||
fetchSpy.mockResolvedValue(
|
||||
new Response(null, { status: 206 })
|
||||
);
|
||||
fetchSpy.mockResolvedValue(new Response(null, { status: 206 }));
|
||||
|
||||
await getLegalNotice();
|
||||
});
|
||||
@@ -95,9 +91,7 @@ describe('fetchLegalContent', () => {
|
||||
});
|
||||
|
||||
test('throws FetchError on HTTP error', async () => {
|
||||
fetchSpy.mockResolvedValue(
|
||||
new Response(null, { status: 404 })
|
||||
);
|
||||
fetchSpy.mockResolvedValue(new Response(null, { status: 404 }));
|
||||
await expect(getLegalNotice()).rejects.toThrow(FetchError);
|
||||
});
|
||||
|
||||
|
||||
@@ -30,15 +30,16 @@ const fetchHtml = async function fetchHtml(url, options) {
|
||||
};
|
||||
|
||||
export const getLegalNotice = async function getLegalNotice() {
|
||||
const legalNoticeUrl = new URL('legal/legal_notice.html', getAssetsUrl()).href;
|
||||
const legalNoticeUrl = new URL('legal/legal_notice.html', getAssetsUrl())
|
||||
.href;
|
||||
const html = await fetchHtml(legalNoticeUrl);
|
||||
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(html, 'text/html');
|
||||
|
||||
const legalNoticeContainer = doc.querySelector('main') ?? doc.body;
|
||||
legalNoticeContainer.querySelectorAll('a').forEach(
|
||||
(link) => link.classList.add('link')
|
||||
);
|
||||
legalNoticeContainer
|
||||
.querySelectorAll('a')
|
||||
.forEach((link) => link.classList.add('link'));
|
||||
return legalNoticeContainer.innerHTML;
|
||||
};
|
||||
|
||||
@@ -20,12 +20,14 @@ import { mountComponent } from '@/test-utils/mountComponent';
|
||||
import { flushPromises } from '@vue/test-utils';
|
||||
import { afterEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
const getLegalNotice = vi.hoisted(() => vi.fn().mockResolvedValue('legal notice'));
|
||||
const getLegalNotice = vi.hoisted(() =>
|
||||
vi.fn().mockResolvedValue('legal notice'),
|
||||
);
|
||||
vi.mock('../../services/fetchLegalContent', async (importOriginal) => {
|
||||
const actual = await importOriginal();
|
||||
return {
|
||||
...actual,
|
||||
getLegalNotice
|
||||
getLegalNotice,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user