Merge fileselect tests with editor

This commit is contained in:
Axel Dahlberg 2021-01-17 13:39:30 +01:00
parent ed2c3ea451
commit 99fa69f565
5 changed files with 47 additions and 98 deletions

View File

@ -7,7 +7,7 @@
function onLoad() {
for (let id of ['#single_file', '#multiple_files']) {
const input = document.querySelector(id);
input.addEventListener('input', function (e) {
input.addEventListener('change', function (e) {
console.log(`Files: ${Array.from(input.files).map(f => f.name).join(", ")}`);
});
}

View File

@ -188,3 +188,32 @@ Feature: Opening external editors
And I run :edit-command
Then the error "command must start with one of :/?" should be shown
And "Leaving mode KeyMode.command *" should not be logged
## select single file
Scenario: Select one file with single command
When I set up a fake "single_file" fileselector selecting "tests/end2end/data/numbers/1.txt"
And I open data/fileselect.html
And I run :click-element id single_file
Then the javascript message "Files: 1.txt" should be logged
Scenario: Select two files with single command
When I set up a fake "single_file" fileselector selecting "tests/end2end/data/numbers/1.txt tests/end2end/data/numbers/2.txt"
And I open data/fileselect.html
And I run :click-element id single_file
Then the javascript message "Files: 1.txt" should be logged
And the warning "More than one files choosen, using only the first" should be shown
## select multiple files
Scenario: Select one file with multiple command
When I set up a fake "multiple_files" fileselector selecting "tests/end2end/data/numbers/1.txt"
And I open data/fileselect.html
And I run :click-element id multiple_files
Then the javascript message "Files: 1.txt" should be logged
Scenario: Select two files with multiple command
When I set up a fake "multiple_files" fileselector selecting "tests/end2end/data/numbers/1.txt tests/end2end/data/numbers/2.txt"
And I open data/fileselect.html
And I run :click-element id multiple_files
Then the javascript message "Files: 1.txt, 2.txt" should be logged

View File

@ -1,35 +0,0 @@
# vim: ft=cucumber fileencoding=utf-8 sts=4 sw=4 et:
Feature: Selecting files
Background:
Given I have a fresh instance
## select single file
Scenario: Select one file with single command
When I set up a fake single file fileselector selecting "tests/end2end/data/numbers/1.txt"
And I open data/fileselect/fileselect.html
And I run :click-element id single_file
Then the javascript message "Files: 1.txt" should be logged
Scenario: Select two files with single command
When I set up a fake single file fileselector selecting "tests/end2end/data/numbers/1.txt tests/end2end/data/numbers/2.txt"
And I open data/fileselect/fileselect.html
And I run :click-element id single_file
Then the javascript message "Files: 1.txt" should be logged
And the warning "More than one files choosen, using only the first" should be shown
## select multiple files
Scenario: Select one file with multiple command
When I set up a fake multiple files fileselector selecting "tests/end2end/data/numbers/1.txt"
And I open data/fileselect/fileselect.html
And I run :click-element id multiple_files
Then the javascript message "Files: 1.txt" should be logged
Scenario: Select two files with multiple command
When I set up a fake multiple files fileselector selecting "tests/end2end/data/numbers/1.txt tests/end2end/data/numbers/2.txt"
And I open data/fileselect/fileselect.html
And I run :click-element id multiple_files
Then the javascript message "Files: 1.txt, 2.txt" should be logged

View File

@ -178,3 +178,20 @@ def save_editor_wait(tmpdir):
# for posix, there IS a member so we need to ignore useless-suppression
# pylint: disable=no-member,useless-suppression
os.kill(pid, signal.SIGUSR2)
@bdd.when(bdd.parsers.parse('I set up a fake "{kind}" fileselector '
'selecting "{files}"'))
def set_up_fileselector(quteproc, py_proc, kind, files):
"""Set up fileselect.xxx.command to select the file(s)."""
cmd, args = py_proc(r"""
import os
import sys
tmp_file = sys.argv[1]
with open(tmp_file, 'w') as f:
for selected_file in sys.argv[2:]:
f.write(os.path.abspath(selected_file) + "\n")
""")
fileselect_cmd = json.dumps([cmd, *args, '{}', *files.split(' ')])
quteproc.set_setting('fileselect.handler', 'external')
quteproc.set_setting(f'fileselect.{kind}.command', fileselect_cmd)

View File

@ -1,62 +0,0 @@
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2016-2020 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
import json
import pytest_bdd as bdd
bdd.scenarios('fileselect.feature')
@bdd.when(bdd.parsers.parse('I set up a fake single file fileselector '
'selecting "{choosefiles}"'))
def set_up_single_fileselector(quteproc, py_proc, choosefiles):
"""Set up fileselect.single_file.command to select the file."""
set_up_fileselector(
quteproc=quteproc,
py_proc=py_proc,
choosefiles=choosefiles,
setting_cmd='fileselect.single_file.command'
)
@bdd.when(bdd.parsers.parse('I set up a fake multiple files fileselector '
'selecting "{choosefiles}"'))
def set_up_multiple_fileselector(quteproc, py_proc, choosefiles):
"""Set up fileselect.multiple_file.command to select the files."""
set_up_fileselector(
quteproc=quteproc,
py_proc=py_proc,
choosefiles=choosefiles,
setting_cmd='fileselect.multiple_files.command'
)
def set_up_fileselector(quteproc, py_proc, choosefiles, setting_cmd):
"""Set up fileselect.xxx.command to select the file(s)."""
cmd, args = py_proc(r"""
import os
import sys
tmp_file = sys.argv[1]
with open(tmp_file, 'w') as f:
for choosenfile in sys.argv[2:]:
f.write(os.path.abspath(choosenfile) + "\n")
""")
fileselect_cmd = json.dumps([cmd, *args, '{}', *choosefiles.split(' ')])
quteproc.set_setting('fileselect.handler', 'external')
quteproc.set_setting(setting_cmd, fileselect_cmd)