start adding media upload test

This commit is contained in:
Nolan Lawson 2018-03-02 17:54:38 -08:00
parent 2cb0dc81f5
commit 9f8b4fa9d8
8 changed files with 55 additions and 18 deletions

View file

@ -96,7 +96,11 @@
"__assets__", "__assets__",
"test", "test",
"fixture", "fixture",
"Element" "Element",
"FormData",
"atob",
"btoa",
"Blob"
], ],
"ignore": [ "ignore": [
"dist", "dist",

View file

@ -32,6 +32,17 @@
import { doMediaUpload } from '../../_actions/media' import { doMediaUpload } from '../../_actions/media'
export default { export default {
oncreate() {
if (process.env.NODE_ENV !== 'production') {
window.__fakeFileInput = (file) => {
this.onFileChange({
target: {
files: [file]
}
})
}
}
},
components: { components: {
IconButton IconButton
}, },

15
tests/blobUtils.js Normal file
View file

@ -0,0 +1,15 @@
export function base64StringToBlob (base64, type) {
function binaryStringToArrayBuffer (binary) {
let length = binary.length
let buf = new ArrayBuffer(length)
let arr = new Uint8Array(buf)
let i = -1
while (++i < length) {
arr[i] = binary.charCodeAt(i)
}
return buf
}
let parts = [binaryStringToArrayBuffer(atob(base64))]
return type ? new Blob(parts, {type: type}) : new Blob(parts)
}

1
tests/images.js Normal file
View file

@ -0,0 +1 @@
export const image1 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=='

View file

@ -2,7 +2,7 @@ import { Selector as $ } from 'testcafe'
import { import {
composeButton, composeInput, composeLengthIndicator, emojiButton, getComposeSelectionStart, getUrl, composeButton, composeInput, composeLengthIndicator, emojiButton, getComposeSelectionStart, getUrl,
homeNavButton, homeNavButton,
notificationsNavButton notificationsNavButton, uploadMedia
} from '../utils' } from '../utils'
import { foobarRole } from '../roles' import { foobarRole } from '../roles'
import times from 'lodash/times' import times from 'lodash/times'
@ -91,3 +91,9 @@ test('inserts emoji without typing anything', async t => {
.click($('button img[title=":blobpeek:"]')) .click($('button img[title=":blobpeek:"]'))
.expect(composeInput.value).eql(':blobpeek: :blobpats: ') .expect(composeInput.value).eql(':blobpeek: :blobpats: ')
}) })
test('inserts media', async t => {
await t.useRole(foobarRole)
await uploadMedia()
await t.expect($('.compose-media:nth-child(1) img').getAttribute('alt')).eql('foo.png')
})

View file

@ -1,10 +1,11 @@
import { ClientFunction as exec, Selector as $ } from 'testcafe' import { ClientFunction as exec, Selector as $ } from 'testcafe'
import * as images from './images'
import * as blobUtils from './blobUtils'
const SCROLL_INTERVAL = 3 const SCROLL_INTERVAL = 3
export const settingsButton = $('nav a[aria-label=Settings]') export const settingsButton = $('nav a[aria-label=Settings]')
export const instanceInput = $('#instanceInput') export const instanceInput = $('#instanceInput')
export const addInstanceButton = $('.add-new-instance button')
export const modalDialogContents = $('.modal-dialog-contents') export const modalDialogContents = $('.modal-dialog-contents')
export const closeDialogButton = $('.close-dialog-button') export const closeDialogButton = $('.close-dialog-button')
export const notificationsNavButton = $('nav a[href="/notifications"]') export const notificationsNavButton = $('nav a[href="/notifications"]')
@ -38,6 +39,17 @@ export const getComposeSelectionStart = exec(() => composeInput().selectionStart
dependencies: { composeInput } dependencies: { composeInput }
}) })
export const uploadMedia = exec(() => {
let blob = blobUtils.base64StringToBlob(images.image1, 'image/png')
blob.name = 'foo.png'
window.__fakeFileInput(blob)
}, {
dependencies: {
images,
blobUtils
}
})
export function getNthStatus (n) { export function getNthStatus (n) {
return $(`div[aria-hidden="false"] > article[aria-posinset="${n}"]`) return $(`div[aria-hidden="false"] > article[aria-posinset="${n}"]`)
} }
@ -106,18 +118,6 @@ export async function validateTimeline (t, timeline) {
} }
} }
export async function scrollTimelineUp (t) {
let oldFirstItem = await getFirstVisibleStatus().getAttribute('aria-posinset')
await t.hover(getFirstVisibleStatus())
let newFirstItem
while (true) {
newFirstItem = await getFirstVisibleStatus().getAttribute('aria-posinset')
if (newFirstItem === '0' || newFirstItem !== oldFirstItem) {
break
}
}
}
export async function scrollToTopOfTimeline (t) { export async function scrollToTopOfTimeline (t) {
let i = await getFirstVisibleStatus().getAttribute('aria-posinset') let i = await getFirstVisibleStatus().getAttribute('aria-posinset')
while (true) { while (true) {