mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-02 19:42:51 +08:00
refactor: extract settings dialogs and guard pending feedback
This commit is contained in:
1 parent
83b2430d18
commit
d2caaa8f3c
13 files changed
+497
-155
No files matched your search
@@ -0,0 +1,59 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { after, before, test } from "node:test";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { createServer } from "vite";
|
||||
import { effectScope, nextTick, reactive, ref } from "vue";
|
||||
|
||||
let vite, useWebClientConnection;
|
||||
before(async () => {
|
||||
vite = await createServer({ configFile: false, root: fileURLToPath(new URL("../", import.meta.url)),
|
||||
server: { middlewareMode: true, hmr: false, ws: false, watch: null },
|
||||
optimizeDeps: { noDiscovery: true, include: [] }, appType: "custom" });
|
||||
({ useWebClientConnection } = await vite.ssrLoadModule("/src/composables/useWebClientConnection.ts"));
|
||||
});
|
||||
after(async () => { await vite?.close(); });
|
||||
function mount(t) {
|
||||
const scope = effectScope(), errors = ref(""), message = ref(""), switched = ref(""), calls = [];
|
||||
const dialog = reactive({ open: true, channelId: "2", password: "draft", error: "", submitting: false });
|
||||
const connection = scope.run(() => useWebClientConnection({
|
||||
initialized: ref(true), accessMode: ref("fixed"), isConnecting: ref(false), errorCode: errors,
|
||||
errorMessage: message, channelSwitchedChannelId: switched,
|
||||
nickname: ref("Preview"), channelName: ref("Room"), serverHost: ref("fixture.invalid"), serverPort: ref("9987"),
|
||||
serverPassword: ref(""), rememberIdentity: ref(false), identityMaterial: ref(""), accelerationRelayId: ref(""),
|
||||
inviteToken: "", selectedChannelId: ref("2"), channels: ref([]), clientId: ref(1),
|
||||
channelPasswordDialog: dialog, serverPasswordDialog: reactive({ open: false, password: "", errorCode: "" }),
|
||||
chatTab: ref("channel"), switchChannel: (...args) => calls.push(args),
|
||||
clearError: () => { errors.value = ""; message.value = ""; }, t: key => key,
|
||||
}));
|
||||
t.after(() => scope.stop());
|
||||
return { dialog, connection, errors, message, switched, calls };
|
||||
}
|
||||
|
||||
test("a waiting channel password request cannot be submitted twice", t => {
|
||||
const { connection, calls, dialog } = mount(t);
|
||||
connection.submitChannelPassword(); connection.submitChannelPassword();
|
||||
assert.equal(dialog.submitting, true);
|
||||
assert.deepEqual(calls, [["2", "draft"]]);
|
||||
});
|
||||
|
||||
test("an ordinary channel error preserves the password and allows retry", async t => {
|
||||
const { connection, dialog, errors, message, calls } = mount(t);
|
||||
connection.submitChannelPassword();
|
||||
message.value = "Channel operation timed out"; errors.value = "COMMAND_TIMEOUT";
|
||||
await nextTick();
|
||||
assert.equal(dialog.open, true);
|
||||
assert.equal(dialog.submitting, false);
|
||||
assert.equal(dialog.password, "draft");
|
||||
assert.equal(dialog.error, "Channel operation timed out");
|
||||
assert.equal(errors.value, "");
|
||||
connection.submitChannelPassword();
|
||||
assert.equal(calls.length, 2);
|
||||
assert.equal(dialog.error, "");
|
||||
});
|
||||
|
||||
test("a successful channel switch closes and clears the password dialog", async t => {
|
||||
const { connection, dialog, switched } = mount(t);
|
||||
connection.submitChannelPassword(); switched.value = "2";
|
||||
await nextTick();
|
||||
assert.deepEqual({ ...dialog }, { open: false, channelId: "", password: "", error: "", submitting: false });
|
||||
});
|
||||
Reference in new issue
Block a user