fix(#24,#25,#26,#27,#30): action按钮顺序; group边界; Notification权限; queue catch; 新增功能测试
This commit is contained in:
@@ -1931,3 +1931,67 @@ describe('边界情况', () => {
|
||||
expect(MeToast.getToast()).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
// ========== 新增功能测试 ==========
|
||||
|
||||
describe('新增功能', () => {
|
||||
beforeEach(() => {
|
||||
MeToast._toasts.clear();
|
||||
});
|
||||
|
||||
test('resetTimerOnUpdate — update后重置计时器', () => {
|
||||
const t = MeToast.info('test', { duration: 5000, resetTimerOnUpdate: true });
|
||||
const oldRemaining = t.remaining;
|
||||
t.update({ message: 'updated' });
|
||||
expect(t.remaining).toBe(5000);
|
||||
expect(t.paused).toBe(false);
|
||||
});
|
||||
|
||||
test('onUpdate 回调触发', () => {
|
||||
const fn = jest.fn();
|
||||
const t = MeToast.success('test', { onUpdate: fn });
|
||||
t.update({ message: 'changed' });
|
||||
expect(fn).toHaveBeenCalledWith(t);
|
||||
});
|
||||
|
||||
test('action 返回控制对象', () => {
|
||||
const a = MeToast.action('test', [{ text: 'OK', onClick: () => {} }]);
|
||||
expect(a).toBeDefined();
|
||||
expect(a.id).toBeDefined();
|
||||
expect(a.toast).toBeDefined();
|
||||
expect(a.dismiss).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
test('queue 返回可取消对象', () => {
|
||||
const q = MeToast.queue(['a', 'b'], { delay: 10, duration: 10 });
|
||||
expect(q.then).toBeInstanceOf(Function);
|
||||
expect(q.catch).toBeInstanceOf(Function);
|
||||
expect(q.cancel).toBeInstanceOf(Function);
|
||||
q.cancel();
|
||||
});
|
||||
|
||||
test('group 创建分组并正常工作', () => {
|
||||
const g = MeToast.group('test-group');
|
||||
expect(g._group).toBe('test-group');
|
||||
expect(g.dismiss).toBeInstanceOf(Function);
|
||||
expect(g.count).toBeInstanceOf(Function);
|
||||
const t = g.info('grouped message');
|
||||
expect(t.group).toBe('test-group');
|
||||
});
|
||||
|
||||
test('dismissGroup 按组关闭', () => {
|
||||
const g = MeToast.group('batch');
|
||||
g.success('m1');
|
||||
g.error('m2');
|
||||
expect(MeToast._groupCount('batch')).toBe(2);
|
||||
MeToast.dismissGroup('batch');
|
||||
});
|
||||
|
||||
test('自定义渲染函数', () => {
|
||||
const t = MeToast.show({
|
||||
render: (toast) => `<b>${toast.message}</b>`,
|
||||
message: 'rendered',
|
||||
});
|
||||
expect(t.config.render).toBeInstanceOf(Function);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user