debugged reducer tests

tl-language-filters
crockwave 2020-07-08 19:22:49 -05:00
rodzic 3635d669f4
commit 41ed27751e
2 zmienionych plików z 152 dodań i 24 usunięć

Wyświetl plik

@ -1,6 +1,6 @@
import reducer from '../list_adder'; import reducer from '../list_adder';
import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
import * as actions from '../list_adder'; import * as actions from 'soapbox/actions/lists';
describe('list_adder reducer', () => { describe('list_adder reducer', () => {
it('should return the initial state', () => { it('should return the initial state', () => {
@ -39,29 +39,29 @@ describe('list_adder reducer', () => {
})); }));
}); });
// it('should handle LIST_ADDER_LISTS_FETCH_REQUEST', () => { it('should handle LIST_ADDER_LISTS_FETCH_REQUEST', () => {
// const state = ImmutableMap({ const state = ImmutableMap({
// accountId: null, accountId: null,
//
// lists: ImmutableMap({ lists: ImmutableMap({
// items: ImmutableList(), items: ImmutableList(),
// loaded: false, loaded: false,
// isLoading: false, isLoading: false,
// }), }),
// }); });
// const action = { const action = {
// type: actions.LIST_ADDER_LISTS_FETCH_REQUEST, type: actions.LIST_ADDER_LISTS_FETCH_REQUEST,
// }; };
// expect(reducer(state, action)).toEqual(ImmutableMap({ expect(reducer(state, action)).toEqual(ImmutableMap({
// accountId: null, accountId: null,
//
// lists: ImmutableMap({ lists: ImmutableMap({
// items: ImmutableList(), items: ImmutableList(),
// loaded: false, loaded: false,
// isLoading: true, isLoading: true,
// }), }),
// })); }));
// }); });
it('should handle LIST_ADDER_LISTS_FETCH_FAIL', () => { it('should handle LIST_ADDER_LISTS_FETCH_FAIL', () => {
const state = ImmutableMap({ const state = ImmutableMap({

Wyświetl plik

@ -1,5 +1,6 @@
import reducer from '../list_editor'; import reducer from '../list_editor';
import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
import * as actions from 'soapbox/actions/lists';
describe('list_editor reducer', () => { describe('list_editor reducer', () => {
it('should return the initial state', () => { it('should return the initial state', () => {
@ -21,4 +22,131 @@ describe('list_editor reducer', () => {
}), }),
})); }));
}); });
it('should handle LIST_EDITOR_RESET', () => {
const state = ImmutableMap({
listId: null,
isSubmitting: false,
isChanged: false,
title: '',
accounts: ImmutableMap({
items: ImmutableList(),
loaded: false,
isLoading: false,
}),
suggestions: ImmutableMap({
value: '',
items: ImmutableList(),
}),
});
const action = {
type: actions.LIST_EDITOR_RESET,
};
expect(reducer(state, action)).toEqual(ImmutableMap({
listId: null,
isSubmitting: false,
isChanged: false,
title: '',
accounts: ImmutableMap({
items: ImmutableList(),
loaded: false,
isLoading: false,
}),
suggestions: ImmutableMap({
value: '',
items: ImmutableList(),
}),
}));
});
it('should handle LIST_EDITOR_SETUP', () => {
const state = ImmutableMap({
listId: null,
isSubmitting: false,
isChanged: false,
title: '',
accounts: ImmutableMap({
items: ImmutableList(),
loaded: false,
isLoading: false,
}),
suggestions: ImmutableMap({
value: '',
items: ImmutableList(),
}),
});
const action = {
type: actions.LIST_EDITOR_SETUP,
list: ImmutableMap({
id: '22',
title: 'list 1',
}),
};
expect(reducer(state, action)).toEqual(ImmutableMap({
listId: '22',
isSubmitting: false,
isChanged: false,
title: 'list 1',
accounts: ImmutableMap({
items: ImmutableList(),
loaded: false,
isLoading: false,
}),
suggestions: ImmutableMap({
value: '',
items: ImmutableList(),
}),
}));
});
it('should handle LIST_EDITOR_TITLE_CHANGE', () => {
const state = ImmutableMap({
title: 'list 1',
isChanged: false,
});
const action = {
type: actions.LIST_EDITOR_TITLE_CHANGE,
value: 'list 1 edited',
};
expect(reducer(state, action).toJS()).toMatchObject({
isChanged: true,
title: 'list 1 edited',
});
});
it('should handle LIST_UPDATE_REQUEST', () => {
const state = ImmutableMap({
isSubmitting: false,
isChanged: true,
});
const action = {
type: actions.LIST_UPDATE_REQUEST,
};
expect(reducer(state, action).toJS()).toMatchObject({
isSubmitting: true,
isChanged: false,
});
});
it('should handle LIST_UPDATE_FAIL', () => {
debugger;
const state = ImmutableMap({
isSubmitting: true,
});
const action = {
type: actions.LIST_UPDATE_FAIL,
};
expect(reducer(state, action).toJS()).toMatchObject({
isSubmitting: false,
});
});
}); });