Skip to content

Commit bf4e720

Browse files
committed
feat: nano contract list component
1 parent 5b2f129 commit bf4e720

35 files changed

+994
-816
lines changed

__tests__/sagas/nanoContracts/historyNanoContract.test.js

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -72,53 +72,33 @@ describe('sagas/nanoContract/fetchHistory', () => {
7272
});
7373

7474
describe('sagas/nanoContract/requestHistoryNanoContract', () => {
75-
test('history loading', () => {
76-
// arrange Nano Contract registration inputs
77-
const { ncId } = fixtures;
78-
79-
// call effect to request history
80-
const gen = requestHistoryNanoContract(nanoContractHistoryRequest({ ncId }));
81-
// select wallet
82-
gen.next();
83-
// feed back historyMeta
84-
gen.next({ [ncId]: { isLoading: true, after: null } });
85-
86-
// assert termination
87-
expect(gen.next().value).toBeUndefined();
88-
});
89-
9075
test('history without registered contract', () => {
9176
// arrange Nano Contract registration inputs
92-
const { ncId } = fixtures;
77+
const { address, ncId } = fixtures;
9378

9479
// call effect to request history
95-
const gen = requestHistoryNanoContract(nanoContractHistoryRequest({ ncId }));
80+
const gen = requestHistoryNanoContract(nanoContractHistoryRequest({ address, ncId }));
9681
// select wallet
9782
gen.next();
98-
// feed back historyMeta
99-
gen.next({});
10083
// feed back wallet
10184
gen.next(fixtures.wallet.readyAndMine);
10285

10386
// expect failure
10487
// feed back isNanoContractRegistered
105-
expect(gen.next(false).value).toStrictEqual(
106-
put(nanoContractHistoryFailure({ ncId, error: failureMessage.notRegistered }))
107-
);
88+
expect(gen.next(false).value)
89+
.toStrictEqual(put(nanoContractHistoryFailure(failureMessage.notRegistered)));
10890
});
10991

11092
test('fetch history fails', () => {
11193
// arrange Nano Contract registration inputs
112-
const { ncId } = fixtures;
94+
const { address, ncId } = fixtures;
11395
const storage = STORE.getStorage();
11496
storage.registerNanoContract(ncId, { ncId });
11597

11698
// call effect to request history
117-
const gen = requestHistoryNanoContract(nanoContractHistoryRequest({ ncId }));
99+
const gen = requestHistoryNanoContract(nanoContractHistoryRequest({ address, ncId }));
118100
// select wallet
119101
gen.next();
120-
// feed back historyMeta
121-
gen.next({});
122102
// feed back wallet
123103
gen.next(fixtures.wallet.readyAndMine);
124104
// feed back isNanoContractRegistered
@@ -130,39 +110,40 @@ describe('sagas/nanoContract/requestHistoryNanoContract', () => {
130110

131111
// assert failure
132112
expect(fetchHistoryCall.payload.fn).toBe(fetchHistory);
133-
expect(failureCall).toStrictEqual(
134-
put(nanoContractHistoryFailure({ ncId, error: failureMessage.nanoContractHistoryFailure }))
135-
);
113+
expect(failureCall).toStrictEqual(put(nanoContractHistoryFailure(failureMessage.nanoContractHistoryFailure, new Error('history'))));
136114
expect(onErrorCall).toStrictEqual(put(onExceptionCaptured(new Error('history'), false)));
137115
});
138116

139117
test('history with success', () => {
140118
// arrange Nano Contract registration inputs
141-
const { ncId } = fixtures;
119+
const { address, ncId } = fixtures;
142120

143121
// call effect to request history
144-
const gen = requestHistoryNanoContract(nanoContractHistoryRequest({ ncId }));
122+
const gen = requestHistoryNanoContract(nanoContractHistoryRequest({ address, ncId }));
145123
// select wallet
146124
gen.next();
147-
// feed back historyMeta
148-
gen.next({});
149125
// feed back wallet
150126
gen.next(fixtures.wallet.readyAndMine);
151127
// feed back isNanoContractRegistered
152128
const fetchHistoryCall = gen.next(true).value;
153129
// feed back fetchHistory
154-
const sucessCall = gen.next(fixtures.ncSaga.fetchHistory.successResponse).value;
130+
gen.next(fixtures.ncSaga.fetchHistory.successResponse);
131+
// feed back getNanoContract
132+
gen.next({ ncId });
133+
// call registerNanoContract and yield put nanoContractHistoryLoad
134+
const historyLoadCall = gen.next().value;
135+
136+
const sucessCall = gen.next().value;
155137

156138
// assert success
157-
const expectedHistory = fixtures.ncSaga.fetchHistory.successResponse.history;
158139
expect(fetchHistoryCall.payload.fn).toBe(fetchHistory);
159-
expect(sucessCall.payload).toHaveProperty('action.payload.ncId');
160-
expect(sucessCall.payload).toHaveProperty('action.payload.history');
161-
expect(sucessCall.payload.action.payload.ncId).toStrictEqual(ncId);
162-
expect(sucessCall.payload.action.payload.history).toStrictEqual(expectedHistory);
163-
expect(sucessCall).toStrictEqual(
164-
put(nanoContractHistorySuccess({ ncId, history: expectedHistory, after: null }))
140+
expect(historyLoadCall.payload).toHaveProperty('action.payload.ncId');
141+
expect(historyLoadCall.payload).toHaveProperty('action.payload.history');
142+
expect(historyLoadCall.payload.action.payload.ncId).toStrictEqual(ncId);
143+
expect(historyLoadCall.payload.action.payload.history).toStrictEqual(
144+
fixtures.ncSaga.fetchHistory.successResponse.history
165145
);
146+
expect(sucessCall).toStrictEqual(put(nanoContractHistorySuccess()));
166147
// assert termination
167148
expect(gen.next().value).toBeUndefined();
168149
});

0 commit comments

Comments
 (0)