Ensured visits loading is cancelled when the visits page is unmounted

This commit is contained in:
Alejandro Celaya
2019-03-08 19:40:43 +01:00
parent 24bbbf6cb1
commit 3982d77775
5 changed files with 45 additions and 9 deletions

View File

@@ -29,6 +29,7 @@ describe('<ShortUrlVisits />', () => {
match={match}
shortUrlVisits={shortUrlVisits}
shortUrlDetail={{}}
cancelGetShortUrlVisits={identity}
/>
);

View File

@@ -5,6 +5,7 @@ import reducer, {
GET_SHORT_URL_VISITS_ERROR,
GET_SHORT_URL_VISITS,
GET_SHORT_URL_VISITS_LARGE,
GET_SHORT_URL_VISITS_CANCEL,
} from '../../../src/visits/reducers/shortUrlVisits';
describe('shortUrlVisitsReducer', () => {
@@ -23,6 +24,13 @@ describe('shortUrlVisitsReducer', () => {
expect(loadingLarge).toEqual(true);
});
it('returns cancelLoad on GET_SHORT_URL_VISITS_CANCEL', () => {
const state = reducer({ cancelLoad: false }, { type: GET_SHORT_URL_VISITS_CANCEL });
const { cancelLoad } = state;
expect(cancelLoad).toEqual(true);
});
it('stops loading and returns error on GET_SHORT_URL_VISITS_ERROR', () => {
const state = reducer({ loading: true, error: false }, { type: GET_SHORT_URL_VISITS_ERROR });
const { loading, error } = state;
@@ -58,7 +66,9 @@ describe('shortUrlVisitsReducer', () => {
getShortUrlVisits: typeof returned === 'function' ? sinon.fake(returned) : sinon.fake.returns(returned),
});
const dispatchMock = sinon.spy();
const getState = () => ({});
const getState = () => ({
shortUrlVisits: { cancelVisits: false },
});
beforeEach(() => dispatchMock.resetHistory());