diff --git a/src/routes/_actions/addStatusOrNotification.js b/src/routes/_actions/addStatusOrNotification.js index fb81b318..25248374 100644 --- a/src/routes/_actions/addStatusOrNotification.js +++ b/src/routes/_actions/addStatusOrNotification.js @@ -3,7 +3,7 @@ import { store } from '../_store/store' import uniqBy from 'lodash-es/uniqBy' import isEqual from 'lodash-es/isEqual' import { database } from '../_database/database' -import { concat, indexWhere } from '../_utils/arrays' +import { concat } from '../_utils/arrays' import { scheduleIdleTask } from '../_utils/scheduleIdleTask' import { timelineItemToSummary } from '../_utils/timelineItemToSummary' @@ -47,9 +47,9 @@ function isValidStatusForThread (thread, timelineName, itemSummariesToAdd) { let itemSummariesToAddIdSet = new Set(itemSummariesToAdd.map(_ => _.id)) let threadIdSet = new Set(thread.map(_ => _.id)) let focusedStatusId = timelineName.split('/')[1] // e.g. "status/123456" - let focusedStatusIdx = indexWhere(thread, _ => _.id === focusedStatusId) + let focusedStatusIdx = thread.findIndex(_ => _.id === focusedStatusId) return status => { - let repliedToStatusIdx = indexWhere(thread, _ => _.id === status.in_reply_to_id) + let repliedToStatusIdx = thread.findIndex(_ => _.id === status.in_reply_to_id) return ( // A reply to an ancestor status is not valid for this thread, but for the focused status // itself or any of its descendents, it is valid. diff --git a/src/routes/_utils/arrays.js b/src/routes/_utils/arrays.js index 4a4cd6cf..665c8a02 100644 --- a/src/routes/_utils/arrays.js +++ b/src/routes/_utils/arrays.js @@ -44,12 +44,3 @@ export function concat () { } return res } - -export function indexWhere (arr, cb) { - for (let i = 0; i < arr.length; i++) { - if (cb(arr[i], i)) { - return i - } - } - return -1 -} diff --git a/tests/spec/008-status-media.js b/tests/spec/008-status-media.js index 9d5fc7d2..e643a204 100644 --- a/tests/spec/008-status-media.js +++ b/tests/spec/008-status-media.js @@ -2,7 +2,6 @@ import { closeDialogButton, getNthStatus, getNthStatusSelector, modalDialogConte import { loginAsFoobar } from '../roles' import { Selector as $ } from 'testcafe' import { homeTimeline } from '../fixtures' -import { indexWhere } from '../../src/routes/_utils/arrays' fixture`008-status-media.js` .page`http://localhost:4002` @@ -10,8 +9,8 @@ fixture`008-status-media.js` test('shows sensitive images and videos', async t => { await loginAsFoobar(t) - let kittenIdx = indexWhere(homeTimeline, _ => _.spoiler === 'kitten CW') - let videoIdx = indexWhere(homeTimeline, _ => _.content === 'secret video') + let kittenIdx = homeTimeline.findIndex(_ => _.spoiler === 'kitten CW') + let videoIdx = homeTimeline.findIndex(_ => _.content === 'secret video') await scrollToStatus(t, 1 + kittenIdx) await t.expect($(`${getNthStatusSelector(1 + kittenIdx)} .status-media img`).exists).notOk() @@ -27,8 +26,8 @@ test('shows sensitive images and videos', async t => { test('click and close image and video modals', async t => { await loginAsFoobar(t) - let videoIdx = indexWhere(homeTimeline, _ => _.content === "here's a video") - let kittenIdx = indexWhere(homeTimeline, _ => _.content === "here's an animated kitten gif") + let videoIdx = homeTimeline.findIndex(_ => _.content === "here's a video") + let kittenIdx = homeTimeline.findIndex(_ => _.content === "here's an animated kitten gif") await scrollToStatus(t, 1 + videoIdx) await t.expect(modalDialogContents.exists).notOk() diff --git a/tests/spec/010-focus.js b/tests/spec/010-focus.js index 981cc3f8..21442f63 100644 --- a/tests/spec/010-focus.js +++ b/tests/spec/010-focus.js @@ -5,7 +5,7 @@ import { } from '../utils' import { loginAsFoobar } from '../roles' import { Selector as $ } from 'testcafe' -import { indexWhere } from '../../src/routes/_utils/arrays' + import { homeTimeline } from '../fixtures' fixture`010-focus.js` @@ -14,7 +14,7 @@ fixture`010-focus.js` test('modal preserves focus', async t => { await loginAsFoobar(t) - let idx = indexWhere(homeTimeline, _ => _.content === "here's a video") + let idx = homeTimeline.findIndex(_ => _.content === "here's a video") await scrollToStatus(t, 1 + idx) // explicitly hover-focus-click diff --git a/tests/spec/017-compose-reply.js b/tests/spec/017-compose-reply.js index 0d01a4e6..40ca1d0c 100644 --- a/tests/spec/017-compose-reply.js +++ b/tests/spec/017-compose-reply.js @@ -7,7 +7,6 @@ import { } from '../utils' import { loginAsFoobar } from '../roles' import { homeTimeline } from '../fixtures' -import { indexWhere } from '../../src/routes/_utils/arrays' fixture`017-compose-reply.js` .page`http://localhost:4002` @@ -63,7 +62,7 @@ test('replies have same privacy as replied-to status by default', async t => { test('replies have same CW as replied-to status', async t => { await loginAsFoobar(t) - let kittenIdx = indexWhere(homeTimeline, _ => _.spoiler === 'kitten CW') + let kittenIdx = homeTimeline.findIndex(_ => _.spoiler === 'kitten CW') await scrollToStatus(t, 1 + kittenIdx) await t.click(getNthReplyButton(1 + kittenIdx)) .expect(getNthReplyContentWarningInput(1 + kittenIdx).value).eql('kitten CW') @@ -75,7 +74,7 @@ test('replies have same CW as replied-to status', async t => { test('replies save deletions of CW', async t => { await loginAsFoobar(t) - let kittenIdx = indexWhere(homeTimeline, _ => _.spoiler === 'kitten CW') + let kittenIdx = homeTimeline.findIndex(_ => _.spoiler === 'kitten CW') await scrollToStatus(t, 1 + kittenIdx) await t.click(getNthReplyButton(1 + kittenIdx)) .expect(getNthReplyContentWarningInput(1 + kittenIdx).value).eql('kitten CW') @@ -89,7 +88,7 @@ test('replies save deletions of CW', async t => { test('replies save changes to CW', async t => { await loginAsFoobar(t) - let kittenIdx = indexWhere(homeTimeline, _ => _.spoiler === 'kitten CW') + let kittenIdx = homeTimeline.findIndex(_ => _.spoiler === 'kitten CW') await scrollToStatus(t, 1 + kittenIdx) await t.click(getNthReplyButton(1 + kittenIdx)) .expect(getNthReplyContentWarningInput(1 + kittenIdx).value).eql('kitten CW') diff --git a/tests/spec/022-status-aria-label.js b/tests/spec/022-status-aria-label.js index b5dd808d..7978b656 100644 --- a/tests/spec/022-status-aria-label.js +++ b/tests/spec/022-status-aria-label.js @@ -8,7 +8,7 @@ import { settingsNavButton } from '../utils' import { Selector as $ } from 'testcafe' -import { indexWhere } from '../../src/routes/_utils/arrays' + import { homeTimeline } from '../fixtures' fixture`022-status-aria-label.js` @@ -29,7 +29,7 @@ test('basic aria-labels for statuses', async t => { test('aria-labels for CWed statuses', async t => { await loginAsFoobar(t) - let kittenIdx = indexWhere(homeTimeline, _ => _.spoiler === 'kitten CW') + let kittenIdx = homeTimeline.findIndex(_ => _.spoiler === 'kitten CW') await scrollToStatus(t, 1 + kittenIdx) await t .hover(getNthStatus(1 + kittenIdx)) diff --git a/tests/spec/023-mark-media-as-sensitive.js b/tests/spec/023-mark-media-as-sensitive.js index 4d4763b9..50040d1e 100644 --- a/tests/spec/023-mark-media-as-sensitive.js +++ b/tests/spec/023-mark-media-as-sensitive.js @@ -4,7 +4,7 @@ import { getNthStatus, getNthStatusMedia, getNthStatusSensitiveMediaButton, homeNavButton, markMediaSensitiveInput, scrollToStatus, settingsNavButton, neverMarkMediaSensitiveInput } from '../utils' -import { indexWhere } from '../../src/routes/_utils/arrays' + import { homeTimeline } from '../fixtures' fixture`023-mark-media-as-sensitive.js` @@ -23,11 +23,11 @@ async function checkSensitivityForStatus (t, idx, sensitive) { } async function checkSensitivity (t, shouldBeSensitive) { - let sensitiveKittenIdx = indexWhere(homeTimeline, _ => _.spoiler === 'kitten CW') - let sensitiveVideoIdx = indexWhere(homeTimeline, _ => _.content === 'secret video') - let videoIdx = indexWhere(homeTimeline, _ => _.content === "here's a video") - let sensitiveAnimatedKittenIdx = indexWhere(homeTimeline, _ => _.content === "here's a secret animated kitten gif") - let animatedKittenIdx = indexWhere(homeTimeline, _ => _.content === "here's an animated kitten gif") + let sensitiveKittenIdx = homeTimeline.findIndex(_ => _.spoiler === 'kitten CW') + let sensitiveVideoIdx = homeTimeline.findIndex(_ => _.content === 'secret video') + let videoIdx = homeTimeline.findIndex(_ => _.content === "here's a video") + let sensitiveAnimatedKittenIdx = homeTimeline.findIndex(_ => _.content === "here's a secret animated kitten gif") + let animatedKittenIdx = homeTimeline.findIndex(_ => _.content === "here's an animated kitten gif") await t.hover(getNthStatus(1)) diff --git a/tests/spec/025-shortcuts-status.js b/tests/spec/025-shortcuts-status.js index 7349ba5b..c1413686 100644 --- a/tests/spec/025-shortcuts-status.js +++ b/tests/spec/025-shortcuts-status.js @@ -13,7 +13,7 @@ import { } from '../utils' import { homeTimeline } from '../fixtures' import { loginAsFoobar } from '../roles' -import { indexWhere } from '../../src/routes/_utils/arrays' + import { Selector as $ } from 'testcafe' fixture`025-shortcuts-status.js` @@ -80,7 +80,7 @@ test('Shortcut o opens active status, backspace goes back', async t => { }) test('Shortcut x shows/hides spoilers', async t => { - let idx = indexWhere(homeTimeline, _ => _.spoiler === 'kitten CW') + let idx = homeTimeline.findIndex(_ => _.spoiler === 'kitten CW') await loginAsFoobar(t) await t .expect(getUrl()).eql('http://localhost:4002/') @@ -96,7 +96,7 @@ test('Shortcut x shows/hides spoilers', async t => { }) test('Shortcut y shows/hides sensitive image', async t => { - let idx = indexWhere(homeTimeline, _ => _.content === "here's a secret kitten") + let idx = homeTimeline.findIndex(_ => _.content === "here's a secret kitten") await loginAsFoobar(t) await t .expect(getUrl()).eql('http://localhost:4002/') @@ -112,7 +112,7 @@ test('Shortcut y shows/hides sensitive image', async t => { }) test('Shortcut f toggles favorite status', async t => { - let idx = indexWhere(homeTimeline, _ => _.content === 'this is unlisted') + let idx = homeTimeline.findIndex(_ => _.content === 'this is unlisted') await loginAsFoobar(t) await t .expect(getUrl()).eql('http://localhost:4002/') @@ -127,7 +127,7 @@ test('Shortcut f toggles favorite status', async t => { }) test('Shortcut p toggles profile', async t => { - let idx = indexWhere(homeTimeline, _ => _.content === 'pinned toot 1') + let idx = homeTimeline.findIndex(_ => _.content === 'pinned toot 1') await loginAsFoobar(t) await t .expect(getUrl()).eql('http://localhost:4002/') @@ -139,7 +139,7 @@ test('Shortcut p toggles profile', async t => { }) test('Shortcut m toggles mention', async t => { - let idx = indexWhere(homeTimeline, _ => _.content === 'pinned toot 1') + let idx = homeTimeline.findIndex(_ => _.content === 'pinned toot 1') await loginAsFoobar(t) await t .expect(getUrl()).eql('http://localhost:4002/') diff --git a/tests/spec/029-back-button-modal.js b/tests/spec/029-back-button-modal.js index c70ed124..322f5c43 100644 --- a/tests/spec/029-back-button-modal.js +++ b/tests/spec/029-back-button-modal.js @@ -20,7 +20,7 @@ import { visibleModalDialog } from '../utils' import { loginAsFoobar } from '../roles' -import { indexWhere } from '../../src/routes/_utils/arrays' + import { homeTimeline } from '../fixtures' fixture`029-back-button-modal.js` @@ -28,7 +28,7 @@ fixture`029-back-button-modal.js` test('Back button dismisses the modal', async t => { await loginAsFoobar(t) - let idx = indexWhere(homeTimeline, _ => (_.content || '').includes('2 kitten photos')) + let idx = homeTimeline.findIndex(_ => (_.content || '').includes('2 kitten photos')) await scrollToStatus(t, idx + 1) await t .expect(getUrl()).eql('http://localhost:4002/') diff --git a/tests/spec/030-shortcuts-modal.js b/tests/spec/030-shortcuts-modal.js index a39e1d82..82e82822 100644 --- a/tests/spec/030-shortcuts-modal.js +++ b/tests/spec/030-shortcuts-modal.js @@ -4,7 +4,7 @@ import { modalDialog, scrollToStatus, sleep } from '../utils' import { loginAsFoobar } from '../roles' -import { indexWhere } from '../../src/routes/_utils/arrays' + import { homeTimeline } from '../fixtures' fixture`030-shortcuts-modal.js` @@ -23,7 +23,7 @@ test('Backspace dismisses modal', async t => { test('Backspace dismisses media modal', async t => { await loginAsFoobar(t) - let idx = indexWhere(homeTimeline, _ => (_.content || '').includes('2 kitten photos')) + let idx = homeTimeline.findIndex(_ => (_.content || '').includes('2 kitten photos')) await scrollToStatus(t, idx + 1) await t .click(getNthStatusMediaButton(idx + 1)) @@ -36,7 +36,7 @@ test('Backspace dismisses media modal', async t => { test('Left/right changes active media in modal', async t => { await loginAsFoobar(t) - let idx = indexWhere(homeTimeline, _ => (_.content || '').includes('2 kitten photos')) + let idx = homeTimeline.findIndex(_ => (_.content || '').includes('2 kitten photos')) await scrollToStatus(t, idx + 1) await t .click(getNthStatusMediaButton(idx + 1)) diff --git a/tests/spec/100-favorite-unfavorite.js b/tests/spec/100-favorite-unfavorite.js index 8da9f216..8546295c 100644 --- a/tests/spec/100-favorite-unfavorite.js +++ b/tests/spec/100-favorite-unfavorite.js @@ -4,7 +4,7 @@ import { scrollToBottom, scrollToTop, sleep } from '../utils' import { loginAsFoobar } from '../roles' -import { indexWhere } from '../../src/routes/_utils/arrays' + import { homeTimeline } from '../fixtures' fixture`100-favorite-unfavorite.js` @@ -63,7 +63,7 @@ test('unfavorites a status', async t => { test('Keeps the correct favorites count', async t => { await loginAsFoobar(t) - let idx = indexWhere(homeTimeline, _ => _.content === 'this is unlisted') + let idx = homeTimeline.findIndex(_ => _.content === 'this is unlisted') await t .hover(getNthStatus(1 + idx)) .click(getNthFavoriteButton(1 + idx))