From cef4be9873d736c7830c254304430d32bffd2510 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Mon, 9 Apr 2018 18:29:52 -0700 Subject: [PATCH] fix alts mixed with no-alts --- routes/_actions/compose.js | 4 ++-- tests/spec/109-compose-media.js | 30 ++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/routes/_actions/compose.js b/routes/_actions/compose.js index a8926b03..f221178e 100644 --- a/routes/_actions/compose.js +++ b/routes/_actions/compose.js @@ -36,8 +36,8 @@ export async function postStatus (realm, text, inReplyToId, mediaIds, postingStatus: true }) try { - await Promise.all(mediaDescriptions.filter(Boolean).map((description, i) => { - return putMediaDescription(instanceName, accessToken, mediaIds[i], description) + await Promise.all(mediaDescriptions.map(async (description, i) => { + return description && putMediaDescription(instanceName, accessToken, mediaIds[i], description) })) let status = await postStatusToServer(instanceName, accessToken, text, inReplyToId, mediaIds, sensitive, spoilerText, visibility) diff --git a/tests/spec/109-compose-media.js b/tests/spec/109-compose-media.js index 1b8f0934..fbc8f164 100644 --- a/tests/spec/109-compose-media.js +++ b/tests/spec/109-compose-media.js @@ -1,7 +1,7 @@ import { composeButton, getNthDeleteMediaButton, getNthMedia, getNthMediaAltInput, getNthStatusAndImage, getUrl, homeNavButton, - mediaButton, notificationsNavButton, sleep, + mediaButton, notificationsNavButton, uploadKittenImage } from '../utils' import { foobarRole } from '../roles' @@ -9,11 +9,18 @@ import { foobarRole } from '../roles' fixture`109-compose-media.js` .page`http://localhost:4002` +async function uploadTwoKittens (t) { + await (uploadKittenImage(1)()) + await t.expect(getNthMedia(1).getAttribute('alt')).eql('kitten1.jpg') + await (uploadKittenImage(2)()) + await t.expect(getNthMedia(1).getAttribute('alt')).eql('kitten1.jpg') + .expect(getNthMedia(2).getAttribute('alt')).eql('kitten2.jpg') +} + test('uploads alts for media', async t => { await t.useRole(foobarRole) .expect(mediaButton.hasAttribute('disabled')).notOk() - await (uploadKittenImage(1)()) - await (uploadKittenImage(2)()) + await uploadTwoKittens(t) await t.typeText(getNthMediaAltInput(2), 'kitten 2') .typeText(getNthMediaAltInput(1), 'kitten 1') .click(composeButton) @@ -36,14 +43,21 @@ test('uploads alts when deleting and re-uploading media', async t => { .expect(getNthStatusAndImage(0, 0).getAttribute('alt')).eql('this will not be deleted') }) +test('uploads alts mixed with no-alts', async t => { + await t.useRole(foobarRole) + .expect(mediaButton.hasAttribute('disabled')).notOk() + await uploadTwoKittens(t) + await t.typeText(getNthMediaAltInput(2), 'kitten numero dos') + .click(composeButton) + .expect(getNthStatusAndImage(0, 0).getAttribute('alt')).eql('') + .expect(getNthStatusAndImage(0, 1).getAttribute('alt')).eql('kitten numero dos') +}) + test('saves alts to local storage', async t => { await t.useRole(foobarRole) .expect(mediaButton.hasAttribute('disabled')).notOk() - await (uploadKittenImage(1)()) - await (uploadKittenImage(2)()) - await t.expect(getNthMedia(1).getAttribute('alt')).eql('kitten1.jpg') - .expect(getNthMedia(2).getAttribute('alt')).eql('kitten2.jpg') - .typeText(getNthMediaAltInput(1), 'kitten numero uno') + await uploadTwoKittens(t) + await t.typeText(getNthMediaAltInput(1), 'kitten numero uno') .typeText(getNthMediaAltInput(2), 'kitten numero dos') .click(notificationsNavButton) .expect(getUrl()).contains('/notifications')