reducers/status-hover-card: add tests

settings-alert
Alex Gleason 2022-06-21 13:36:14 -05:00
rodzic 04d7a161cd
commit 3b0543eb66
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 74 dodań i 3 usunięć

Wyświetl plik

@ -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);
});
});

Wyświetl plik

@ -8,7 +8,7 @@ import {
import type { AnyAction } from 'redux';
const ReducerRecord = ImmutableRecord({
export const ReducerRecord = ImmutableRecord({
ref: null as React.MutableRefObject<HTMLDivElement> | null,
statusId: '',
hovered: false,
@ -26,7 +26,7 @@ export default function statusHoverCard(state: State = ReducerRecord(), action:
case STATUS_HOVER_CARD_UPDATE:
return state.set('hovered', true);
case STATUS_HOVER_CARD_CLOSE:
if (state.get('hovered') === true && !action.force)
if (state.hovered === true && !action.force)
return state;
else
return ReducerRecord();
@ -34,4 +34,3 @@ export default function statusHoverCard(state: State = ReducerRecord(), action:
return state;
}
}