From 99fa69f565a5b2bad2cc46dd6d37bb8a32e3d387 Mon Sep 17 00:00:00 2001 From: Axel Dahlberg Date: Sun, 17 Jan 2021 13:39:30 +0100 Subject: [PATCH] Merge fileselect tests with editor --- .../data/{fileselect => }/fileselect.html | 2 +- tests/end2end/features/editor.feature | 29 +++++++++ tests/end2end/features/fileselect.feature | 35 ----------- tests/end2end/features/test_editor_bdd.py | 17 +++++ tests/end2end/features/test_fileselect_bdd.py | 62 ------------------- 5 files changed, 47 insertions(+), 98 deletions(-) rename tests/end2end/data/{fileselect => }/fileselect.html (91%) delete mode 100644 tests/end2end/features/fileselect.feature delete mode 100644 tests/end2end/features/test_fileselect_bdd.py diff --git a/tests/end2end/data/fileselect/fileselect.html b/tests/end2end/data/fileselect.html similarity index 91% rename from tests/end2end/data/fileselect/fileselect.html rename to tests/end2end/data/fileselect.html index e9a710296..a31936c72 100644 --- a/tests/end2end/data/fileselect/fileselect.html +++ b/tests/end2end/data/fileselect.html @@ -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(", ")}`); }); } diff --git a/tests/end2end/features/editor.feature b/tests/end2end/features/editor.feature index db80c89ba..38d1a3d74 100644 --- a/tests/end2end/features/editor.feature +++ b/tests/end2end/features/editor.feature @@ -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 diff --git a/tests/end2end/features/fileselect.feature b/tests/end2end/features/fileselect.feature deleted file mode 100644 index 8e4f76d6d..000000000 --- a/tests/end2end/features/fileselect.feature +++ /dev/null @@ -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 diff --git a/tests/end2end/features/test_editor_bdd.py b/tests/end2end/features/test_editor_bdd.py index 36719324a..01e4aeea0 100644 --- a/tests/end2end/features/test_editor_bdd.py +++ b/tests/end2end/features/test_editor_bdd.py @@ -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) diff --git a/tests/end2end/features/test_fileselect_bdd.py b/tests/end2end/features/test_fileselect_bdd.py deleted file mode 100644 index b5e7c2ba4..000000000 --- a/tests/end2end/features/test_fileselect_bdd.py +++ /dev/null @@ -1,62 +0,0 @@ -# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: - -# Copyright 2016-2020 Florian Bruhin (The Compiler) -# -# 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 . - -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)