reducers/status-hover-card: add tests
This commit is contained in:
parent
04d7a161cd
commit
3b0543eb66
2 changed files with 74 additions and 3 deletions
72
app/soapbox/reducers/__tests__/status-hover-card.test.tsx
Normal file
72
app/soapbox/reducers/__tests__/status-hover-card.test.tsx
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
import {
|
||||||
|
STATUS_HOVER_CARD_OPEN,
|
||||||
|
STATUS_HOVER_CARD_CLOSE,
|
||||||
|
STATUS_HOVER_CARD_UPDATE,
|
||||||
|
} from 'soapbox/actions/status-hover-card';
|
||||||
|
|
||||||
|
import reducer, { ReducerRecord } from '../status-hover-card';
|
||||||
|
|
||||||
|
describe(STATUS_HOVER_CARD_OPEN, () => {
|
||||||
|
it('sets the ref and statusId', () => {
|
||||||
|
const ref = { current: document.createElement('div') };
|
||||||
|
|
||||||
|
const action = {
|
||||||
|
type: STATUS_HOVER_CARD_OPEN,
|
||||||
|
ref,
|
||||||
|
statusId: '1234',
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = reducer(undefined, action);
|
||||||
|
expect(result.ref).toBe(ref);
|
||||||
|
expect(result.statusId).toBe('1234');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe(STATUS_HOVER_CARD_CLOSE, () => {
|
||||||
|
it('flushes the state', () => {
|
||||||
|
const state = ReducerRecord({
|
||||||
|
ref: { current: document.createElement('div') },
|
||||||
|
statusId: '1234',
|
||||||
|
});
|
||||||
|
|
||||||
|
const action = { type: STATUS_HOVER_CARD_CLOSE };
|
||||||
|
|
||||||
|
const result = reducer(state, action);
|
||||||
|
expect(result.ref).toBe(null);
|
||||||
|
expect(result.statusId).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('leaves the state alone if hovered', () => {
|
||||||
|
const state = ReducerRecord({
|
||||||
|
ref: { current: document.createElement('div') },
|
||||||
|
statusId: '1234',
|
||||||
|
hovered: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const action = { type: STATUS_HOVER_CARD_CLOSE };
|
||||||
|
const result = reducer(state, action);
|
||||||
|
expect(result).toEqual(state);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('action.force flushes the state even if hovered', () => {
|
||||||
|
const state = ReducerRecord({
|
||||||
|
ref: { current: document.createElement('div') },
|
||||||
|
statusId: '1234',
|
||||||
|
hovered: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const action = { type: STATUS_HOVER_CARD_CLOSE, force: true };
|
||||||
|
const result = reducer(state, action);
|
||||||
|
expect(result.ref).toBe(null);
|
||||||
|
expect(result.statusId).toBe('');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe(STATUS_HOVER_CARD_UPDATE, () => {
|
||||||
|
it('sets hovered', () => {
|
||||||
|
const state = ReducerRecord();
|
||||||
|
const action = { type: STATUS_HOVER_CARD_UPDATE };
|
||||||
|
const result = reducer(state, action);
|
||||||
|
expect(result.hovered).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
|
@ -8,7 +8,7 @@ import {
|
||||||
|
|
||||||
import type { AnyAction } from 'redux';
|
import type { AnyAction } from 'redux';
|
||||||
|
|
||||||
const ReducerRecord = ImmutableRecord({
|
export const ReducerRecord = ImmutableRecord({
|
||||||
ref: null as React.MutableRefObject<HTMLDivElement> | null,
|
ref: null as React.MutableRefObject<HTMLDivElement> | null,
|
||||||
statusId: '',
|
statusId: '',
|
||||||
hovered: false,
|
hovered: false,
|
||||||
|
@ -26,7 +26,7 @@ export default function statusHoverCard(state: State = ReducerRecord(), action:
|
||||||
case STATUS_HOVER_CARD_UPDATE:
|
case STATUS_HOVER_CARD_UPDATE:
|
||||||
return state.set('hovered', true);
|
return state.set('hovered', true);
|
||||||
case STATUS_HOVER_CARD_CLOSE:
|
case STATUS_HOVER_CARD_CLOSE:
|
||||||
if (state.get('hovered') === true && !action.force)
|
if (state.hovered === true && !action.force)
|
||||||
return state;
|
return state;
|
||||||
else
|
else
|
||||||
return ReducerRecord();
|
return ReducerRecord();
|
||||||
|
@ -34,4 +34,3 @@ export default function statusHoverCard(state: State = ReducerRecord(), action:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue