From 187c12f0b11f718df21cf5d5ce41c6c4b3235534 Mon Sep 17 00:00:00 2001 From: weareoutman Date: Thu, 29 Nov 2018 17:57:57 +0800 Subject: [PATCH] chore: add tests --- test/reducers/__snapshots__/jobs.spec.js.snap | 29 +++++++++++++- test/reducers/jobs.spec.js | 40 ++++++++++++++++++- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/test/reducers/__snapshots__/jobs.spec.js.snap b/test/reducers/__snapshots__/jobs.spec.js.snap index e22509e2..f964ea68 100644 --- a/test/reducers/__snapshots__/jobs.spec.js.snap +++ b/test/reducers/__snapshots__/jobs.spec.js.snap @@ -164,13 +164,40 @@ Object { "buffer": Array [], "cursor": 0, "returned": "$ ls -l -drwx + 100% done.", }, }, } `; +exports[`reducers jobs should handle JOB_OUTPUT when output is undefined 1`] = ` +Object { + "active": null, + "entities": Object { + "1": Object { + "cmd": "ls -l", + "cwd": "/tmp", + "id": 1, + "name": "test job for JOB_OUTPUT", + "running": true, + }, + }, + "ids": Array [ + 1, + ], + "outputs": Object { + "1": Object { + "buffer": Array [ + "drwx", + ], + "cursor": 0, + "returned": undefined, + }, + }, +} +`; + exports[`reducers jobs should handle REMOVE_JOB 1`] = ` Object { "active": null, diff --git a/test/reducers/jobs.spec.js b/test/reducers/jobs.spec.js index 431c846b..be0ef31e 100644 --- a/test/reducers/jobs.spec.js +++ b/test/reducers/jobs.spec.js @@ -211,7 +211,43 @@ describe('reducers', () => { 1: { returned: '$ ls -l', buffer: ['drwx'], - cursor: 4 + cursor: 0 + } + } + }, + { + type: JOB_OUTPUT, + job: { + id: 1, + name: 'test job for JOB_OUTPUT', + cmd: 'ls -l', + cwd: '/tmp' + }, + output: '\b\n10% run\b\b\b\b\b\b\b100% done.\n' + } + ) + ).toMatchSnapshot(); + }); + + it('should handle JOB_OUTPUT when output is undefined', () => { + expect( + jobs( + { + ids: [1], + entities: { + 1: { + id: 1, + name: 'test job for JOB_OUTPUT', + cmd: 'ls -l', + cwd: '/tmp', + running: true + } + }, + outputs: { + 1: { + returned: undefined, + buffer: ['drwx'], + cursor: 0 } } }, @@ -223,7 +259,7 @@ describe('reducers', () => { cmd: 'ls -l', cwd: '/tmp' }, - output: '\n10% run\b\b\b\b\b\b\b100% done.\n' + output: undefined } ) ).toMatchSnapshot();