mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
refactor: cleanup (#348)
* some wip code Co-authored-by: Jacob Nguyen <jacoobes@users.noreply.github.com> * general idea * style * making shrimple truly optional * got optional localizer working * proposing api notation? * prepare for localization map * add localsFor * merge some internals * boss call * add test for init functionality * add documentation * inline and cleanup * feat: logging for experimental json loading * loosen typings * dev workflow and cleaning up comments * cleaning up a bit more * rename Localizer -> Localization * more documentation, change dir for default localizer * some tests * " * move stuff, refactor, deprecate * yarnb * Update index.ts --------- Co-authored-by: Jacob Nguyen <jacoobes@users.noreply.github.com> Co-authored-by: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Co-authored-by: jacob <jacoobes@sern.dev>
This commit is contained in:
64
test/core/id.test.ts
Normal file
64
test/core/id.test.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { CommandType } from '../../src/core';
|
||||
import * as Id from '../../src/core/id'
|
||||
import { expect, test } from 'vitest'
|
||||
|
||||
test('id -> Text', () => {
|
||||
const bothCmdId = Id.create("ping", CommandType.Text)
|
||||
expect(bothCmdId).toBe("ping_T")
|
||||
})
|
||||
|
||||
test('id -> Both', () => {
|
||||
const bothCmdId = Id.create("ping", CommandType.Both)
|
||||
expect(bothCmdId).toBe("ping_B")
|
||||
})
|
||||
|
||||
test('id -> CtxMsg', () => {
|
||||
const bothCmdId = Id.create("ping", CommandType.CtxMsg)
|
||||
expect(bothCmdId).toBe("ping_A3")
|
||||
})
|
||||
test('id -> CtxUsr', () => {
|
||||
const bothCmdId = Id.create("ping", CommandType.CtxUser)
|
||||
expect(bothCmdId).toBe("ping_A2")
|
||||
})
|
||||
test('id -> Modal', () => {
|
||||
const modal = Id.create("my-modal", CommandType.Modal)
|
||||
expect(modal).toBe("my-modal_M");
|
||||
})
|
||||
|
||||
test('id -> Button', () => {
|
||||
const modal = Id.create("my-button", CommandType.Button)
|
||||
expect(modal).toBe("my-button_C2");
|
||||
})
|
||||
|
||||
test('id -> Slash', () => {
|
||||
const modal = Id.create("myslash", CommandType.Slash)
|
||||
expect(modal).toBe("myslash_A1");
|
||||
})
|
||||
|
||||
test('id -> StringSelect', () => {
|
||||
const modal = Id.create("mystringselect", CommandType.StringSelect)
|
||||
expect(modal).toBe("mystringselect_C3");
|
||||
})
|
||||
|
||||
test('id -> UserSelect', () => {
|
||||
const modal = Id.create("myuserselect", CommandType.UserSelect)
|
||||
expect(modal).toBe("myuserselect_C5");
|
||||
})
|
||||
|
||||
test('id -> RoleSelect', () => {
|
||||
const modal = Id.create("myroleselect", CommandType.RoleSelect)
|
||||
expect(modal).toBe("myroleselect_C6");
|
||||
})
|
||||
|
||||
test('id -> MentionSelect', () => {
|
||||
const modal = Id.create("mymentionselect", CommandType.MentionableSelect)
|
||||
expect(modal).toBe("mymentionselect_C7");
|
||||
})
|
||||
|
||||
test('id -> ChannelSelect', () => {
|
||||
const modal = Id.create("mychannelselect", CommandType.ChannelSelect)
|
||||
expect(modal).toBe("mychannelselect_C8");
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { CoreContainer } from '../../src/core/ioc/container';
|
||||
import { EventEmitter } from 'events';
|
||||
import { DefaultLogging, Disposable, Init, Logging } from '../../src/core';
|
||||
import { DefaultLogging, Disposable, Emitter, Init, Logging } from '../../src/core';
|
||||
import { CoreDependencies } from '../../src/types/ioc';
|
||||
|
||||
describe('ioc container', () => {
|
||||
let container: CoreContainer<{}> = new CoreContainer();
|
||||
let dependency: Logging & Init & Disposable;
|
||||
let dependency2: Emitter
|
||||
beforeEach(() => {
|
||||
dependency = {
|
||||
init: vi.fn(),
|
||||
@@ -16,6 +17,11 @@ describe('ioc container', () => {
|
||||
debug(): void {},
|
||||
dispose: vi.fn()
|
||||
};
|
||||
dependency2 = {
|
||||
addListener: vi.fn(),
|
||||
removeListener: vi.fn(),
|
||||
emit: vi.fn()
|
||||
};
|
||||
container = new CoreContainer();
|
||||
});
|
||||
const wait = (seconds: number) => new Promise((resolve) => setTimeout(resolve, seconds));
|
||||
@@ -83,4 +89,13 @@ describe('ioc container', () => {
|
||||
container.ready();
|
||||
expect(dependency.init).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it('should init dependency depending on something else', () => {
|
||||
container.add({ '@sern/client': dependency2 });
|
||||
container.upsert((cntr) => ({
|
||||
'@sern/logger': dependency
|
||||
}));
|
||||
container.ready();
|
||||
expect(dependency.init).toHaveBeenCalledTimes(1);
|
||||
})
|
||||
});
|
||||
|
||||
@@ -74,4 +74,7 @@ describe('services', () => {
|
||||
expect(consoleMock).toHaveBeenCalledOnce();
|
||||
expect(consoleMock).toHaveBeenLastCalledWith({ message: 'error' });
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user