From d8c71c616b2dc8a7973714907a3dd5e775bb0722 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sun, 5 Feb 2023 11:26:21 +0800 Subject: [PATCH] inline globals --- jest.config.json | 8 +- plugins/config-generator/assets/generator.ts | 7 +- .../assets/modifyButton.ts | 6 +- .../mojang-verification/assets/update-uuid.ts | 9 +- .../assets/ConfigEditor.svelte | 17 ++-- .../assets/DomainsList.svelte | 9 +- .../assets/autocomplete.ts | 27 +++--- .../assets/registration.ts | 13 +-- .../assets/Description.svelte | 46 +++++----- .../assets/Description.test.ts | 3 +- .../assets/UploadEditor.svelte | 6 +- .../assets/UploadEditor.test.ts | 3 +- .../assets/UploadEditor.ts | 3 +- setup-test.ts | 85 +++++++++++++++++++ tsconfig.json | 2 +- 15 files changed, 167 insertions(+), 77 deletions(-) create mode 100644 setup-test.ts diff --git a/jest.config.json b/jest.config.json index 3ed77d5..bead9a7 100644 --- a/jest.config.json +++ b/jest.config.json @@ -2,12 +2,12 @@ "preset": "ts-jest", "resetMocks": true, "timers": "modern", - "moduleNameMapper": { - "blessing-skin": "/types.ts" - }, "transform": { "^.+\\.svelte$": "@gplane/svelte-jest", "^.+\\.tsx?$": "ts-jest" }, - "setupFilesAfterEnv": ["@testing-library/jest-dom/extend-expect"] + "setupFilesAfterEnv": [ + "@testing-library/jest-dom/extend-expect", + "/setup-test.ts" + ] } diff --git a/plugins/config-generator/assets/generator.ts b/plugins/config-generator/assets/generator.ts index c14e30e..f75fb5c 100644 --- a/plugins/config-generator/assets/generator.ts +++ b/plugins/config-generator/assets/generator.ts @@ -1,6 +1,5 @@ import hljs from 'highlight.js/lib/core' import json from 'highlight.js/lib/languages/json' -import { site_name, base_url } from 'blessing-skin' hljs.registerLanguage('json', json) @@ -10,14 +9,14 @@ document .querySelector('#download-extra-list') ?.addEventListener('click', () => { const content = JSON.stringify({ - name: site_name, + name: globalThis.blessing.site_name, type: 'CustomSkinAPI', - root: `${base_url}/csl/`, + root: `${globalThis.blessing.base_url}/csl/`, }) const a = document.createElement('a') const blob = new Blob([content], { type: 'application/json' }) - a.download = `${site_name}.json` + a.download = `${globalThis.blessing.site_name}.json` a.href = URL.createObjectURL(blob) a.click() a.remove() diff --git a/plugins/disable-registration/assets/modifyButton.ts b/plugins/disable-registration/assets/modifyButton.ts index 64e1107..8c04c25 100644 --- a/plugins/disable-registration/assets/modifyButton.ts +++ b/plugins/disable-registration/assets/modifyButton.ts @@ -1,9 +1,7 @@ -import { base_url, t } from 'blessing-skin' - const button = document.querySelector('.main-button') if (button && button.href.endsWith('/auth/register')) { - button.textContent = t('auth.login') - const url = new URL(base_url) + button.textContent = globalThis.blessing.t('auth.login') + const url = new URL(globalThis.blessing.base_url) url.pathname = '/auth/login' button.href = url.toString() } diff --git a/plugins/mojang-verification/assets/update-uuid.ts b/plugins/mojang-verification/assets/update-uuid.ts index 8079858..fd43db1 100644 --- a/plugins/mojang-verification/assets/update-uuid.ts +++ b/plugins/mojang-verification/assets/update-uuid.ts @@ -1,10 +1,7 @@ -import { fetch, notify } from 'blessing-skin' - document.querySelector('#update-uuid')?.addEventListener('click', async () => { - const { code, message }: { code: null; message: string } = await fetch.post( - '/mojang/update-uuid', - ) - const { toast } = notify + const { code, message }: { code: null; message: string } = + await globalThis.blessing.fetch.post('/mojang/update-uuid') + const { toast } = globalThis.blessing.notify if (code === 0) { toast.success(message) } else { diff --git a/plugins/restricted-email-domains/assets/ConfigEditor.svelte b/plugins/restricted-email-domains/assets/ConfigEditor.svelte index b6c245e..cc9395b 100644 --- a/plugins/restricted-email-domains/assets/ConfigEditor.svelte +++ b/plugins/restricted-email-domains/assets/ConfigEditor.svelte @@ -1,9 +1,10 @@ - - {#if canEdit || !isEmptyDescription}
@@ -77,7 +61,8 @@ {/if} @@ -107,7 +92,8 @@
@@ -125,3 +112,20 @@ {/if}
{/if} + + diff --git a/plugins/texture-description/assets/Description.test.ts b/plugins/texture-description/assets/Description.test.ts index ffa374c..944298c 100644 --- a/plugins/texture-description/assets/Description.test.ts +++ b/plugins/texture-description/assets/Description.test.ts @@ -1,8 +1,9 @@ import { render, fireEvent, waitFor } from '@testing-library/svelte' import { tick } from 'svelte' -import { fetch, t } from 'blessing-skin' import Description from './Description.svelte' +const { fetch, t } = globalThis.blessing + test('render description', async () => { const spy = jest.spyOn(fetch, 'get').mockResolvedValue('
') render(Description, { props: { tid: 1 } }) diff --git a/plugins/texture-description/assets/UploadEditor.svelte b/plugins/texture-description/assets/UploadEditor.svelte index 71f8bd7..a063267 100644 --- a/plugins/texture-description/assets/UploadEditor.svelte +++ b/plugins/texture-description/assets/UploadEditor.svelte @@ -1,6 +1,7 @@