mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-07-28 04:08:05 +00:00
test: drop state from AsyncSaga constructor params
This uses the real rootReducer to populate the initial state in the test AsyncSaga. This way we don't have to populate default values. Since it isn't used often, we can omit the parameter and just call the updateState() method after creating the object if modifications are needed.
This commit is contained in:
@@ -13,7 +13,7 @@ jest.mock('file-saver');
|
||||
|
||||
test('open', async () => {
|
||||
const mockEditor = mock<monaco.editor.ICodeEditor>();
|
||||
const saga = new AsyncSaga(editor, {}, { editor: mockEditor });
|
||||
const saga = new AsyncSaga(editor, { editor: mockEditor });
|
||||
|
||||
const data = new Uint8Array().buffer;
|
||||
saga.put(open(data));
|
||||
@@ -26,7 +26,7 @@ test('open', async () => {
|
||||
describe('saveAs', () => {
|
||||
test('web file system api can succeed', async () => {
|
||||
const mockEditor = mock<monaco.editor.ICodeEditor>();
|
||||
const saga = new AsyncSaga(editor, {}, { editor: mockEditor });
|
||||
const saga = new AsyncSaga(editor, { editor: mockEditor });
|
||||
|
||||
// window.showSaveFilePicker is not defined in the test environment
|
||||
// so we can't use spyOn().
|
||||
@@ -55,7 +55,7 @@ describe('saveAs', () => {
|
||||
|
||||
test('web file system api can fail', async () => {
|
||||
const mockEditor = mock<monaco.editor.ICodeEditor>();
|
||||
const saga = new AsyncSaga(editor, {}, { editor: mockEditor });
|
||||
const saga = new AsyncSaga(editor, { editor: mockEditor });
|
||||
|
||||
// window.showSaveFilePicker is not defined in the test environment
|
||||
// so we can't use spyOn().
|
||||
@@ -82,7 +82,7 @@ describe('saveAs', () => {
|
||||
|
||||
test('fallback can succeed', async () => {
|
||||
const mockEditor = mock<monaco.editor.ICodeEditor>();
|
||||
const saga = new AsyncSaga(editor, {}, { editor: mockEditor });
|
||||
const saga = new AsyncSaga(editor, { editor: mockEditor });
|
||||
|
||||
const mockFileSaverSaveAs = jest.spyOn(FileSaver, 'saveAs');
|
||||
|
||||
@@ -101,7 +101,7 @@ describe('saveAs', () => {
|
||||
|
||||
test('fallback can fail', async () => {
|
||||
const mockEditor = mock<monaco.editor.ICodeEditor>();
|
||||
const saga = new AsyncSaga(editor, {}, { editor: mockEditor });
|
||||
const saga = new AsyncSaga(editor, { editor: mockEditor });
|
||||
|
||||
const testError = new Error('test error');
|
||||
const mockFileSaverSaveAs = jest
|
||||
|
||||
@@ -21,7 +21,7 @@ describe('handleExplorerImportFiles', () => {
|
||||
const testFileName = 'test.py';
|
||||
const testFileContents = '# test';
|
||||
|
||||
const saga = new AsyncSaga(explorer, { fileStorage: { fileNames: [] } });
|
||||
const saga = new AsyncSaga(explorer);
|
||||
|
||||
jest.spyOn(browserFsAccess, 'fileOpen').mockResolvedValueOnce([
|
||||
mock<FileWithHandle>({
|
||||
|
||||
+66
-208
@@ -78,16 +78,11 @@ describe('flashFirmware', () => {
|
||||
new Response(await zip.generateAsync({ type: 'blob' })),
|
||||
);
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false, hubName: 'test name' },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
saga.updateState({ settings: { hubName: 'test name' } });
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -230,16 +225,9 @@ describe('flashFirmware', () => {
|
||||
new Response(await zip.generateAsync({ type: 'blob' })),
|
||||
);
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -286,16 +274,9 @@ describe('flashFirmware', () => {
|
||||
new Response(await zip.generateAsync({ type: 'blob' })),
|
||||
);
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -360,16 +341,9 @@ describe('flashFirmware', () => {
|
||||
new Response(await zip.generateAsync({ type: 'blob' })),
|
||||
);
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -430,16 +404,9 @@ describe('flashFirmware', () => {
|
||||
new Response(await zip.generateAsync({ type: 'blob' })),
|
||||
);
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -503,16 +470,9 @@ describe('flashFirmware', () => {
|
||||
new Response(await zip.generateAsync({ type: 'blob' })),
|
||||
);
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -569,16 +529,9 @@ describe('flashFirmware', () => {
|
||||
const response = new Response(undefined, { status: 404 });
|
||||
jest.spyOn(window, 'fetch').mockResolvedValueOnce(response);
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -641,16 +594,9 @@ describe('flashFirmware', () => {
|
||||
new Response(await zip.generateAsync({ type: 'blob' })),
|
||||
);
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -729,16 +675,9 @@ describe('flashFirmware', () => {
|
||||
new Response(await zip.generateAsync({ type: 'blob' })),
|
||||
);
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -801,16 +740,9 @@ describe('flashFirmware', () => {
|
||||
new Response(await zip.generateAsync({ type: 'blob' })),
|
||||
);
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -902,16 +834,9 @@ describe('flashFirmware', () => {
|
||||
new Response(await zip.generateAsync({ type: 'blob' })),
|
||||
);
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -1012,16 +937,9 @@ describe('flashFirmware', () => {
|
||||
new Response(await zip.generateAsync({ type: 'blob' })),
|
||||
);
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -1162,16 +1080,9 @@ describe('flashFirmware', () => {
|
||||
new Response(await zip.generateAsync({ type: 'blob' })),
|
||||
);
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -1310,16 +1221,9 @@ describe('flashFirmware', () => {
|
||||
zip.file('main.py', 'print("test")');
|
||||
zip.file('ReadMe_OSS.txt', 'test');
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -1461,16 +1365,9 @@ describe('flashFirmware', () => {
|
||||
zip.file('main.py', 'print("test")');
|
||||
zip.file('ReadMe_OSS.txt', 'test');
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -1511,16 +1408,9 @@ describe('flashFirmware', () => {
|
||||
zip.file('main.py', 'print("test")');
|
||||
zip.file('ReadMe_OSS.txt', 'test');
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -1560,16 +1450,9 @@ describe('flashFirmware', () => {
|
||||
zip.file('main.py', 'print("test")');
|
||||
zip.file('ReadMe_OSS.txt', 'test');
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -1622,16 +1505,9 @@ describe('flashFirmware', () => {
|
||||
zip.file('main.py', 'print("test")');
|
||||
zip.file('ReadMe_OSS.txt', 'test');
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -1685,16 +1561,9 @@ describe('flashFirmware', () => {
|
||||
zip.file('main.py', 'print("test")');
|
||||
zip.file('ReadMe_OSS.txt', 'test');
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -1751,16 +1620,9 @@ describe('flashFirmware', () => {
|
||||
zip.file('main.py', 'print("test")');
|
||||
zip.file('ReadMe_OSS.txt', 'test');
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -1846,14 +1708,10 @@ describe('flashFirmware', () => {
|
||||
getValue: () => 'print("test")',
|
||||
});
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: true },
|
||||
},
|
||||
{ editor, nextMessageId: createCountFunc() },
|
||||
);
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
editor,
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
|
||||
+6
-10
@@ -27,14 +27,10 @@ jest.mock('react-monaco-editor');
|
||||
describe('downloadAndRun', () => {
|
||||
test('no errors', async () => {
|
||||
const mockEditor = mock<monaco.editor.ICodeEditor>();
|
||||
const saga = new AsyncSaga(
|
||||
hub,
|
||||
{},
|
||||
{
|
||||
editor: mockEditor,
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
const saga = new AsyncSaga(hub, {
|
||||
editor: mockEditor,
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
saga.put(downloadAndRun());
|
||||
|
||||
@@ -87,7 +83,7 @@ describe('downloadAndRun', () => {
|
||||
});
|
||||
|
||||
test('repl', async () => {
|
||||
const saga = new AsyncSaga(hub, {}, { nextMessageId: createCountFunc() });
|
||||
const saga = new AsyncSaga(hub, { nextMessageId: createCountFunc() });
|
||||
|
||||
saga.put(repl());
|
||||
|
||||
@@ -98,7 +94,7 @@ test('repl', async () => {
|
||||
});
|
||||
|
||||
test('stop', async () => {
|
||||
const saga = new AsyncSaga(hub, {}, { nextMessageId: createCountFunc() });
|
||||
const saga = new AsyncSaga(hub, { nextMessageId: createCountFunc() });
|
||||
|
||||
saga.put(stop());
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2020-2021 The Pybricks Authors
|
||||
// Copyright (c) 2020-2022 The Pybricks Authors
|
||||
|
||||
// Tests for license sagas.
|
||||
|
||||
@@ -15,7 +15,7 @@ afterAll(() => {
|
||||
describe('fetchLicenses', () => {
|
||||
test('first call', async () => {
|
||||
const testLicenseList: LicenseList = [];
|
||||
const saga = new AsyncSaga(license, { licenses: { list: null } });
|
||||
const saga = new AsyncSaga(license);
|
||||
|
||||
jest.spyOn(globalThis, 'fetch').mockResolvedValue(
|
||||
new Response(JSON.stringify(testLicenseList)),
|
||||
@@ -30,12 +30,15 @@ describe('fetchLicenses', () => {
|
||||
|
||||
await saga.end();
|
||||
});
|
||||
|
||||
test('second call', async () => {
|
||||
const testLicenseList: LicenseList = [];
|
||||
const saga = new AsyncSaga(license, { licenses: { list: testLicenseList } });
|
||||
const saga = new AsyncSaga(license);
|
||||
|
||||
saga.updateState({ licenses: { list: testLicenseList } });
|
||||
|
||||
jest.spyOn(globalThis, 'fetch').mockRejectedValue(
|
||||
'fetch () should not have been called',
|
||||
'fetch() should not have been called',
|
||||
);
|
||||
|
||||
// after we have the list, we don't fetch it again since it will
|
||||
@@ -47,9 +50,10 @@ describe('fetchLicenses', () => {
|
||||
|
||||
await saga.end();
|
||||
});
|
||||
|
||||
test('failed fetch', async () => {
|
||||
const failResponse = new Response(undefined, { status: 404 });
|
||||
const saga = new AsyncSaga(license, { licenses: { list: null } });
|
||||
const saga = new AsyncSaga(license);
|
||||
|
||||
jest.spyOn(globalThis, 'fetch').mockResolvedValue(failResponse);
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ function createTestToasterSaga(): { toaster: IToaster; saga: AsyncSaga } {
|
||||
jest.spyOn(toaster, 'getToasts');
|
||||
jest.spyOn(toaster, 'show');
|
||||
|
||||
const saga = new AsyncSaga(notification, {}, { notification: { toaster } });
|
||||
const saga = new AsyncSaga(notification, { notification: { toaster } });
|
||||
|
||||
return { toaster, saga };
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2020-2021 The Pybricks Authors
|
||||
// Copyright (c) 2020-2022 The Pybricks Authors
|
||||
//
|
||||
// Tests for settings sagas.
|
||||
|
||||
@@ -218,9 +218,7 @@ describe('startup', () => {
|
||||
|
||||
describe('store settings to local storage', () => {
|
||||
test('failed storage', async () => {
|
||||
const saga = new AsyncSaga(settings, {
|
||||
settings: { showDocs: false, hubName: '' },
|
||||
});
|
||||
const saga = new AsyncSaga(settings);
|
||||
|
||||
const testError = new Error('local storage is disabled');
|
||||
|
||||
@@ -260,7 +258,7 @@ describe('store settings to local storage', () => {
|
||||
});
|
||||
|
||||
test('showDocs', async () => {
|
||||
const saga = new AsyncSaga(settings, { settings: { showDocs: false } });
|
||||
const saga = new AsyncSaga(settings);
|
||||
|
||||
const mockSetItem = jest
|
||||
.spyOn(Object.getPrototypeOf(window.localStorage), 'setItem')
|
||||
@@ -279,7 +277,9 @@ describe('store settings to local storage', () => {
|
||||
});
|
||||
|
||||
test('darkMode', async () => {
|
||||
const saga = new AsyncSaga(settings, { settings: { darkMode: true } });
|
||||
const saga = new AsyncSaga(settings);
|
||||
|
||||
saga.updateState({ settings: { darkMode: true } });
|
||||
|
||||
const mockSetItem = jest
|
||||
.spyOn(Object.getPrototypeOf(window.localStorage), 'setItem')
|
||||
@@ -298,9 +298,9 @@ describe('store settings to local storage', () => {
|
||||
});
|
||||
|
||||
test('flashCurrentProgram', async () => {
|
||||
const saga = new AsyncSaga(settings, {
|
||||
settings: { flashCurrentProgram: true },
|
||||
});
|
||||
const saga = new AsyncSaga(settings);
|
||||
|
||||
saga.updateState({ settings: { flashCurrentProgram: true } });
|
||||
|
||||
const mockSetItem = jest
|
||||
.spyOn(Object.getPrototypeOf(window.localStorage), 'setItem')
|
||||
@@ -375,7 +375,7 @@ describe('storage monitor', () => {
|
||||
|
||||
describe('toggle', () => {
|
||||
test('showDocs', async () => {
|
||||
const saga = new AsyncSaga(settings, { settings: { showDocs: false } });
|
||||
const saga = new AsyncSaga(settings);
|
||||
|
||||
const mockSetItem = jest
|
||||
.spyOn(Object.getPrototypeOf(window.localStorage), 'setItem')
|
||||
|
||||
+13
-20
@@ -19,11 +19,7 @@ const encoder = new TextEncoder();
|
||||
|
||||
describe('Data receiver filters out hub status', () => {
|
||||
test('normal message - no status', async () => {
|
||||
const saga = new AsyncSaga(
|
||||
terminal,
|
||||
{ hub: { runtime: HubRuntimeState.Unknown } },
|
||||
{ nextMessageId: createCountFunc() },
|
||||
);
|
||||
const saga = new AsyncSaga(terminal, { nextMessageId: createCountFunc() });
|
||||
|
||||
// sending ASCII space character
|
||||
saga.put(didNotify(new DataView(new Uint8Array([0x20]).buffer)));
|
||||
@@ -35,11 +31,9 @@ describe('Data receiver filters out hub status', () => {
|
||||
});
|
||||
|
||||
test('checksum message', async () => {
|
||||
const saga = new AsyncSaga(
|
||||
terminal,
|
||||
{ hub: { runtime: HubRuntimeState.Loading } },
|
||||
{ nextMessageId: createCountFunc() },
|
||||
);
|
||||
const saga = new AsyncSaga(terminal, { nextMessageId: createCountFunc() });
|
||||
|
||||
saga.updateState({ hub: { runtime: HubRuntimeState.Loading } });
|
||||
|
||||
saga.put(didNotify(new DataView(new Uint8Array([0xaa]).buffer)));
|
||||
|
||||
@@ -52,11 +46,10 @@ describe('Data receiver filters out hub status', () => {
|
||||
|
||||
test('Terminal data source responds to send data actions', async () => {
|
||||
const dataSource = new PushStream<string>();
|
||||
const saga = new AsyncSaga(
|
||||
terminal,
|
||||
{},
|
||||
{ nextMessageId: createCountFunc(), terminal: { dataSource } },
|
||||
);
|
||||
const saga = new AsyncSaga(terminal, {
|
||||
nextMessageId: createCountFunc(),
|
||||
terminal: { dataSource },
|
||||
});
|
||||
|
||||
const data = new Array<string>();
|
||||
dataSource.observable.subscribe({ next: (v) => data.push(v) });
|
||||
@@ -77,7 +70,7 @@ describe('Terminal data source responds to receive data actions', () => {
|
||||
const expected = encoder.encode('test1234');
|
||||
|
||||
test('basic function works', async () => {
|
||||
const saga = new AsyncSaga(terminal, {}, { nextMessageId: createCountFunc() });
|
||||
const saga = new AsyncSaga(terminal, { nextMessageId: createCountFunc() });
|
||||
|
||||
saga.put(receiveData('test1234'));
|
||||
|
||||
@@ -88,7 +81,7 @@ describe('Terminal data source responds to receive data actions', () => {
|
||||
});
|
||||
|
||||
test('messages are queued until previous has completed', async () => {
|
||||
const saga = new AsyncSaga(terminal, {}, { nextMessageId: createCountFunc() });
|
||||
const saga = new AsyncSaga(terminal, { nextMessageId: createCountFunc() });
|
||||
|
||||
saga.put(receiveData('test1234'));
|
||||
await delay(50); // without delay, messages are combined
|
||||
@@ -114,7 +107,7 @@ describe('Terminal data source responds to receive data actions', () => {
|
||||
});
|
||||
|
||||
test('messages are queued until previous has failed', async () => {
|
||||
const saga = new AsyncSaga(terminal, {}, { nextMessageId: createCountFunc() });
|
||||
const saga = new AsyncSaga(terminal, { nextMessageId: createCountFunc() });
|
||||
|
||||
saga.put(receiveData('test1234'));
|
||||
await delay(50); // without delay, messages are combined
|
||||
@@ -140,7 +133,7 @@ describe('Terminal data source responds to receive data actions', () => {
|
||||
});
|
||||
|
||||
test('small messages are combined', async () => {
|
||||
const saga = new AsyncSaga(terminal, {}, { nextMessageId: createCountFunc() });
|
||||
const saga = new AsyncSaga(terminal, { nextMessageId: createCountFunc() });
|
||||
|
||||
saga.put(receiveData('test1234'));
|
||||
saga.put(receiveData('test1234'));
|
||||
@@ -154,7 +147,7 @@ describe('Terminal data source responds to receive data actions', () => {
|
||||
test('long messages are split', async () => {
|
||||
const testData = '012345678901234567890123456789';
|
||||
|
||||
const saga = new AsyncSaga(terminal, {}, { nextMessageId: createCountFunc() });
|
||||
const saga = new AsyncSaga(terminal, { nextMessageId: createCountFunc() });
|
||||
|
||||
saga.put(receiveData(testData));
|
||||
|
||||
|
||||
+3
-7
@@ -14,18 +14,14 @@ export class AsyncSaga {
|
||||
private channel: MulticastChannel<AnyAction>;
|
||||
private dispatches: (AnyAction | END)[];
|
||||
private takers: { put: (action: AnyAction | END) => void }[];
|
||||
private state: DeepPartial<RootState>;
|
||||
private state: RootState;
|
||||
private task: Task;
|
||||
|
||||
public constructor(
|
||||
saga: Saga,
|
||||
state: DeepPartial<RootState> = {},
|
||||
context?: Partial<RootSagaContext>,
|
||||
) {
|
||||
public constructor(saga: Saga, context?: Partial<RootSagaContext>) {
|
||||
this.channel = stdChannel();
|
||||
this.dispatches = [];
|
||||
this.takers = [];
|
||||
this.state = state;
|
||||
this.state = createStore(rootReducer).getState();
|
||||
this.task = runSaga(
|
||||
{
|
||||
channel: this.channel,
|
||||
|
||||
Reference in New Issue
Block a user