{"size": 1145, "ext": "js", "max_stars_repo_path": "actions/select-files/index.test.js", "max_stars_repo_name": "splayd/puppet-strings", "max_stars_repo_stars_event_min_datetime": "2018-05-17T02:45:59.000Z", "max_stars_repo_stars_event_max_datetime": "2018-08-28T00:03:55.000Z", "max_issues_repo_path": "actions/select-files/index.test.js", "max_issues_repo_name": "vinsonchuong/puppet-strings", "max_issues_repo_issues_event_min_datetime": "2019-01-03T18:14:21.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-27T00:53:48.000Z", "max_forks_repo_path": "actions/select-files/index.test.js", "max_forks_repo_name": "splayd/puppet-strings", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 5, "max_issues_count": 39, "max_forks_count": null, "avg_line_length": 28.625, "max_line_length": 80, "alphanum_fraction": 0.6611353712}
import path from 'node:path'
import test from 'ava'
import {withChrome, withDirectory, writeFile} from '../../test/helpers/index.js'
import {openTab, findElement, selectFiles} from '../../index.js'

withChrome(test)
withDirectory(test)

test('selecting files for a file input element', async (t) => {
  const {browser} = global
  const {directory} = t.context

  const htmlPath = await writeFile(
    directory,
    'index.html',
    `
    <!doctype html>
    <meta charset="utf-8">
    <script>
      function updateStatus() {
        const fileNames = Array.from(window.fileInput.files)
          .map(file => file.name)
          .join(', ')
        window.statusText.textContent = fileNames
      }
    </script>
    <span id="statusText"></span>
    <input id="fileInput" type="file" multiple onChange="updateStatus()">
  `,
  )

  const tab = await openTab(browser, `file://${htmlPath}`)

  const fileInput = await findElement(tab, '#fileInput')
  await selectFiles(fileInput, htmlPath, path.resolve('package.json'))

  const statusText = await findElement(tab, '#statusText')
  t.is(statusText.textContent, 'index.html, package.json')
})
