From c66f5c040ff0f4d1540789c970cf1422dc7392f7 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 6 Jul 2022 11:57:32 -0500 Subject: [PATCH] Fix utils tests types --- app/soapbox/utils/__tests__/accounts.test.ts | 4 +++- app/soapbox/utils/__tests__/status.test.ts | 11 +++++---- app/soapbox/utils/__tests__/timelines.test.ts | 24 ++++++++++--------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/app/soapbox/utils/__tests__/accounts.test.ts b/app/soapbox/utils/__tests__/accounts.test.ts index cafedce35..878d278dd 100644 --- a/app/soapbox/utils/__tests__/accounts.test.ts +++ b/app/soapbox/utils/__tests__/accounts.test.ts @@ -4,11 +4,13 @@ import { getDomain, } from '../accounts'; +import type { ReducerAccount } from 'soapbox/reducers/accounts'; + describe('getDomain', () => { const account = AccountRecord({ acct: 'alice', url: 'https://party.com/users/alice', - }); + }) as ReducerAccount; it('returns the domain', () => { expect(getDomain(account)).toEqual('party.com'); }); diff --git a/app/soapbox/utils/__tests__/status.test.ts b/app/soapbox/utils/__tests__/status.test.ts index 4556382de..2bc803ee5 100644 --- a/app/soapbox/utils/__tests__/status.test.ts +++ b/app/soapbox/utils/__tests__/status.test.ts @@ -1,4 +1,3 @@ -import { fromJS } from 'immutable'; import { normalizeStatus } from 'soapbox/normalizers/status'; @@ -7,9 +6,11 @@ import { defaultMediaVisibility, } from '../status'; +import type { ReducerStatus } from 'soapbox/reducers/statuses'; + describe('hasIntegerMediaIds()', () => { it('returns true for a Pleroma deleted status', () => { - const status = normalizeStatus(fromJS(require('soapbox/__fixtures__/pleroma-status-deleted.json'))); + const status = normalizeStatus(require('soapbox/__fixtures__/pleroma-status-deleted.json')) as ReducerStatus; expect(hasIntegerMediaIds(status)).toBe(true); }); }); @@ -20,17 +21,17 @@ describe('defaultMediaVisibility()', () => { }); it('hides sensitive media by default', () => { - const status = normalizeStatus({ sensitive: true }); + const status = normalizeStatus({ sensitive: true }) as ReducerStatus; expect(defaultMediaVisibility(status, 'default')).toBe(false); }); it('hides media when displayMedia is hide_all', () => { - const status = normalizeStatus({}); + const status = normalizeStatus({}) as ReducerStatus; expect(defaultMediaVisibility(status, 'hide_all')).toBe(false); }); it('shows sensitive media when displayMedia is show_all', () => { - const status = normalizeStatus({ sensitive: true }); + const status = normalizeStatus({ sensitive: true }) as ReducerStatus; expect(defaultMediaVisibility(status, 'show_all')).toBe(true); }); }); diff --git a/app/soapbox/utils/__tests__/timelines.test.ts b/app/soapbox/utils/__tests__/timelines.test.ts index 9be55575d..852a76ef6 100644 --- a/app/soapbox/utils/__tests__/timelines.test.ts +++ b/app/soapbox/utils/__tests__/timelines.test.ts @@ -4,70 +4,72 @@ import { normalizeStatus } from 'soapbox/normalizers/status'; import { shouldFilter } from '../timelines'; +import type { ReducerStatus } from 'soapbox/reducers/statuses'; + describe('shouldFilter', () => { it('returns false under normal circumstances', () => { const columnSettings = fromJS({}); - const status = normalizeStatus({}); + const status = normalizeStatus({}) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(false); }); it('reblog: returns true when `shows.reblog == false`', () => { const columnSettings = fromJS({ shows: { reblog: false } }); - const status = normalizeStatus({ reblog: {} }); + const status = normalizeStatus({ reblog: {} }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(true); }); it('reblog: returns false when `shows.reblog == true`', () => { const columnSettings = fromJS({ shows: { reblog: true } }); - const status = normalizeStatus({ reblog: {} }); + const status = normalizeStatus({ reblog: {} }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(false); }); it('reply: returns true when `shows.reply == false`', () => { const columnSettings = fromJS({ shows: { reply: false } }); - const status = normalizeStatus({ in_reply_to_id: '1234' }); + const status = normalizeStatus({ in_reply_to_id: '1234' }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(true); }); it('reply: returns false when `shows.reply == true`', () => { const columnSettings = fromJS({ shows: { reply: true } }); - const status = normalizeStatus({ in_reply_to_id: '1234' }); + const status = normalizeStatus({ in_reply_to_id: '1234' }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(false); }); it('direct: returns true when `shows.direct == false`', () => { const columnSettings = fromJS({ shows: { direct: false } }); - const status = normalizeStatus({ visibility: 'direct' }); + const status = normalizeStatus({ visibility: 'direct' }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(true); }); it('direct: returns false when `shows.direct == true`', () => { const columnSettings = fromJS({ shows: { direct: true } }); - const status = normalizeStatus({ visibility: 'direct' }); + const status = normalizeStatus({ visibility: 'direct' }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(false); }); it('direct: returns false for a public post when `shows.direct == false`', () => { const columnSettings = fromJS({ shows: { direct: false } }); - const status = normalizeStatus({ visibility: 'public' }); + const status = normalizeStatus({ visibility: 'public' }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(false); }); it('multiple settings', () => { const columnSettings = fromJS({ shows: { reblog: false, reply: false, direct: false } }); - const status = normalizeStatus({ reblog: null, in_reply_to_id: null, visibility: 'direct' }); + const status = normalizeStatus({ reblog: null, in_reply_to_id: null, visibility: 'direct' }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(true); }); it('multiple settings', () => { const columnSettings = fromJS({ shows: { reblog: false, reply: true, direct: false } }); - const status = normalizeStatus({ reblog: null, in_reply_to_id: '1234', visibility: 'public' }); + const status = normalizeStatus({ reblog: null, in_reply_to_id: '1234', visibility: 'public' }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(false); }); it('multiple settings', () => { const columnSettings = fromJS({ shows: { reblog: true, reply: false, direct: true } }); - const status = normalizeStatus({ reblog: {}, in_reply_to_id: '1234', visibility: 'direct' }); + const status = normalizeStatus({ reblog: {}, in_reply_to_id: '1234', visibility: 'direct' }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(true); }); });