| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- const test = require('node:test');
- const assert = require('node:assert/strict');
- const fs = require('node:fs');
- test('sidepanel loads hotmail manager before sidepanel bootstrap', () => {
- const html = fs.readFileSync('sidepanel/sidepanel.html', 'utf8');
- const hotmailManagerIndex = html.indexOf('<script src="hotmail-manager.js"></script>');
- const sidepanelIndex = html.indexOf('<script src="sidepanel.js"></script>');
- assert.notEqual(hotmailManagerIndex, -1);
- assert.notEqual(sidepanelIndex, -1);
- assert.ok(hotmailManagerIndex < sidepanelIndex);
- });
- test('hotmail manager exposes a factory and renders empty state', () => {
- const source = fs.readFileSync('sidepanel/hotmail-manager.js', 'utf8');
- const windowObject = {};
- const localStorageMock = {
- getItem() {
- return null;
- },
- setItem() {},
- };
- const api = new Function('window', 'localStorage', `${source}; return window.SidepanelHotmailManager;`)(
- windowObject,
- localStorageMock
- );
- assert.equal(typeof api?.createHotmailManager, 'function');
- const hotmailAccountsList = { innerHTML: '' };
- const toggleButton = {
- textContent: '',
- disabled: false,
- setAttribute() {},
- };
- const noopClassList = { toggle() {} };
- const manager = api.createHotmailManager({
- state: {
- getLatestState: () => ({ currentHotmailAccountId: null }),
- syncLatestState() {},
- },
- dom: {
- btnClearUsedHotmailAccounts: { textContent: '', disabled: false },
- btnDeleteAllHotmailAccounts: { textContent: '', disabled: false },
- btnToggleHotmailList: toggleButton,
- hotmailAccountsList,
- hotmailListShell: { classList: noopClassList },
- selectMailProvider: { value: 'hotmail-api' },
- inputEmail: { value: '' },
- },
- helpers: {
- getHotmailAccounts: () => [],
- getCurrentHotmailEmail: () => '',
- escapeHtml: (value) => String(value || ''),
- showToast() {},
- openConfirmModal: async () => true,
- copyTextToClipboard: async () => {},
- },
- runtime: {
- sendMessage: async () => ({}),
- },
- constants: {
- copyIcon: '',
- displayTimeZone: 'Asia/Shanghai',
- expandedStorageKey: 'multipage-hotmail-list-expanded',
- },
- hotmailUtils: {},
- });
- assert.equal(typeof manager.renderHotmailAccounts, 'function');
- assert.equal(typeof manager.bindHotmailEvents, 'function');
- assert.equal(typeof manager.initHotmailListExpandedState, 'function');
- manager.renderHotmailAccounts();
- assert.match(hotmailAccountsList.innerHTML, /还没有 Hotmail 账号/);
- });
|