Exemple #1
0
    public static bool SetDirectoryText(MainWindow window, string text)
    {
        var filesPanelView   = ActiveFilePanelProvider.GetActiveFilePanelView(window);
        var directoryTextBox = filesPanelView
                               .GetVisualDescendants()
                               .OfType <TextBox>()
                               .SingleOrDefault(t => t.Name == "DirectoryTextBox");

        if (directoryTextBox is null)
        {
            return(false);
        }

        var separatorPosition = directoryTextBox.Text.LastIndexOf(Path.DirectorySeparatorChar);

        if (separatorPosition < 0)
        {
            return(false);
        }

        directoryTextBox.CaretIndex = directoryTextBox.Text.Length;
        var commonLength = directoryTextBox.Text.Length;

        while (!text.StartsWith(directoryTextBox.Text))
        {
            Keyboard.PressKey(window, Key.Back);
            commonLength--;
        }

        directoryTextBox.SendText(text[commonLength..]);
Exemple #2
0
    public async Task TestSearch()
    {
        var window = AvaloniaApp.GetMainWindow();

        await FocusFilePanelStep.FocusFilePanelAsync(window);

        CreateNewTabStep.CreateNewTab(window);

        var viewModel = ActiveFilePanelProvider.GetActiveFilePanelViewModel(window);

        _directoryFullPath = Path.Combine(viewModel.CurrentDirectory, DirectoryName);
        Directory.CreateDirectory(_directoryFullPath);

        var filesPanel = ActiveFilePanelProvider.GetActiveFilePanelView(window);

        Assert.NotNull(filesPanel);

        ToggleSearchPanelStep.ToggleSearchPanelVisibility(window);

        await Task.Delay(100);

        var searchPanel = filesPanel
                          .GetVisualDescendants()
                          .OfType <SearchView>()
                          .SingleOrDefault();

        Assert.NotNull(searchPanel);

        var searchTextBox = searchPanel
                            .GetVisualDescendants()
                            .OfType <TextBox>()
                            .SingleOrDefault();

        Assert.NotNull(searchTextBox);

        searchTextBox.SendText(DirectoryName);

        await Task.Delay(1000);

        ChangeActiveFilePanelStep.ChangeActiveFilePanel(window);
        ChangeActiveFilePanelStep.ChangeActiveFilePanel(window);
        Keyboard.PressKey(window, Key.Down);
        Keyboard.PressKey(window, Key.Down);

        await Task.Delay(100);

        var selectedItemText = GetSelectedItemText(filesPanel);

        Assert.Equal(DirectoryName, selectedItemText);

        _fileFullPath = Path.Combine(viewModel.CurrentDirectory, FileName);
        await File.Create(_fileFullPath).DisposeAsync();

        await Task.Delay(1000);

        var fileIsVisible = CheckIfFilesExist(filesPanel);

        Assert.False(fileIsVisible);
    }
Exemple #3
0
    public async Task TestCopyFile()
    {
        var window = AvaloniaApp.GetMainWindow();

        await FocusFilePanelStep.FocusFilePanelAsync(window);

        CreateNewTabStep.CreateNewTab(window);

        var viewModel = ActiveFilePanelProvider.GetActiveFilePanelViewModel(window);

        _directoryFullPath = Path.Combine(viewModel.CurrentDirectory, DirectoryName);
        Directory.CreateDirectory(_directoryFullPath);

        _fileFullPath = Path.Combine(viewModel.CurrentDirectory, FileName);
        await File.WriteAllTextAsync(_fileFullPath, FileContent);

        ChangeActiveFilePanelStep.ChangeActiveFilePanel(window);
        CreateNewTabStep.CreateNewTab(window);
        FocusDirectorySelectorStep.FocusDirectorySelector(window);
        var textSet = SetDirectoryTextStep.SetDirectoryText(window, _directoryFullPath);

        Assert.True(textSet);

        await Task.Delay(1000);

        ChangeActiveFilePanelStep.ChangeActiveFilePanel(window);
        await Task.Delay(100);

        ToggleSearchPanelStep.ToggleSearchPanelVisibility(window);

        await Task.Delay(100);

        SearchNodeStep.SearchNode(window, FileName);

        await Task.Delay(300);

        ChangeActiveFilePanelStep.ChangeActiveFilePanel(window);
        ChangeActiveFilePanelStep.ChangeActiveFilePanel(window);
        Keyboard.PressKey(window, Key.Down);
        Keyboard.PressKey(window, Key.Down);

        CopySelectedNodesStep.CopySelectedNodes(window);

        ToggleSearchPanelStep.ToggleSearchPanelVisibility(window);
        await Task.Delay(1000);

        var copiedFullPath = Path.Combine(_directoryFullPath, FileName);
        var fileExists     = await WaitService.WaitForConditionAsync(() => File.Exists(copiedFullPath));

        Assert.True(fileExists);

        var fileContent = await File.ReadAllTextAsync(copiedFullPath);

        Assert.Equal(FileContent, fileContent);

        Assert.True(File.Exists(_fileFullPath));
    }
Exemple #4
0
    public async Task TestRemoveDirectory(bool removePermanently)
    {
        var app    = AvaloniaApp.GetApp();
        var window = AvaloniaApp.GetMainWindow();

        await FocusFilePanelStep.FocusFilePanelAsync(window);

        var viewModel = ActiveFilePanelProvider.GetActiveFilePanelViewModel(window);

        _directoryFullPath = Path.Combine(viewModel.CurrentDirectory, DirectoryName);
        Directory.CreateDirectory(_directoryFullPath);

        ToggleSearchPanelStep.ToggleSearchPanelVisibility(window);

        await Task.Delay(100);

        var filesPanel = ActiveFilePanelProvider.GetActiveFilePanelView(window);

        Assert.NotNull(filesPanel);

        SearchNodeStep.SearchNode(window, DirectoryName);

        await Task.Delay(1000);

        ChangeActiveFilePanelStep.ChangeActiveFilePanel(window);
        ChangeActiveFilePanelStep.ChangeActiveFilePanel(window);
        Keyboard.PressKey(window, Key.Down);
        Keyboard.PressKey(window, Key.Down);

        if (removePermanently)
        {
            OpenRemoveDialogStep.OpenPermanentRemoveDialog(window);
        }
        else
        {
            OpenRemoveDialogStep.OpenRemoveDialog(window);
        }

        var isRemoveDialogOpened =
            await DialogOpenedCondition.CheckIfDialogIsOpenedAsync <RemoveNodesConfirmationDialog>(app);

        Assert.True(isRemoveDialogOpened);

        Keyboard.PressKey(window, Key.Enter);
        await Task.Delay(100);

        var isRemoveDialogClosed =
            await DialogClosedCondition.CheckIfDialogIsClosedAsync <RemoveNodesConfirmationDialog>(app);

        Assert.True(isRemoveDialogClosed);

        ToggleSearchPanelStep.ToggleSearchPanelVisibility(window);

        Assert.False(Directory.Exists(_directoryFullPath));
    }
Exemple #5
0
    public static void SearchNode(MainWindow window, string text)
    {
        var filesPanel  = ActiveFilePanelProvider.GetActiveFilePanelView(window);
        var searchPanel = filesPanel
                          .GetVisualDescendants()
                          .OfType <SearchView>()
                          .Single();
        var searchTextBox = searchPanel
                            .GetVisualDescendants()
                            .OfType <TextBox>()
                            .Single();

        searchTextBox.SendText(text);
    }
    public async Task GoToParentDirectoryTest()
    {
        var window = AvaloniaApp.GetMainWindow();
        await FocusFilePanelStep.FocusFilePanelAsync(window);

        CreateNewTabStep.CreateNewTab(window);
        var filesPanelViewModel = ActiveFilePanelProvider.GetActiveFilePanelViewModel(window);
        var currentDirectory    = filesPanelViewModel.CurrentDirectory;

        GoToParentDirectoryStep.GoToParentDirectoryViaFilePanel(window);

        var isParentDirectoryOpened = await DirectoryOpenedCondition.CheckIfParentDirectoryIsOpenedAsync(window, currentDirectory);

        Assert.True(isParentDirectoryOpened);
    }
Exemple #7
0
    public async Task GoToParentDirectoryAndBackTest()
    {
        var window = AvaloniaApp.GetMainWindow();

        await FocusFilePanelStep.FocusFilePanelAsync(window);

        CreateNewTabStep.CreateNewTab(window);
        var viewModel = ActiveFilePanelProvider.GetActiveFilePanelViewModel(window);

        _directoryFullPath = viewModel.CurrentDirectory;

        for (var i = 0; i < 10; i++)
        {
            GoToPreviousDirectoryStep.GoToPreviousDirectory(window);
            var isCurrentDirectoryStillOpened = await DirectoryOpenedCondition.CheckIfDirectoryIsOpenedAsync(window, _directoryFullPath);

            Assert.True(isCurrentDirectoryStillOpened);
        }

        GoToParentDirectoryStep.GoToParentDirectoryViaFilePanel(window);
        var isParentDirectoryOpened = await DirectoryOpenedCondition.CheckIfParentDirectoryIsOpenedAsync(window, _directoryFullPath);

        Assert.True(isParentDirectoryOpened);

        GoToPreviousDirectoryStep.GoToPreviousDirectory(window);
        var isChildDirectoryOpened = await DirectoryOpenedCondition.CheckIfDirectoryIsOpenedAsync(window, _directoryFullPath);

        Assert.True(isChildDirectoryOpened);

        for (var i = 0; i < 10; i++)
        {
            GoToNextDirectoryStep.GoToNextDirectory(window);
            var parentDirectoryWasReopened = await DirectoryOpenedCondition.CheckIfParentDirectoryIsOpenedAsync(window,
                                                                                                                _directoryFullPath);

            Assert.True(parentDirectoryWasReopened);
        }

        for (var i = 0; i < 10; i++)
        {
            GoToPreviousDirectoryStep.GoToPreviousDirectory(window);
            var isCurrentDirectoryStillOpened = await DirectoryOpenedCondition.CheckIfDirectoryIsOpenedAsync(window, _directoryFullPath);

            Assert.True(isCurrentDirectoryStillOpened);
        }
    }
Exemple #8
0
        public async Task GoToParentDirectoryAndBackTest()
        {
            var window = AvaloniaApp.GetMainWindow();
            await FocusFilePanelStep.FocusFilePanelAsync(window);

            CreateNewTabStep.CreateNewTab(window);
            FocusDirectorySelectorStep.FocusDirectorySelector(window);

            var filesPanelViewModel = ActiveFilePanelProvider.GetActiveFilePanelViewModel(window);
            var currentDirectory    = filesPanelViewModel.CurrentDirectory;
            var filesPanelView      = ActiveFilePanelProvider.GetActiveFilePanelView(window);
            var directoryTextBox    = filesPanelView
                                      .GetVisualDescendants()
                                      .OfType <TextBox>()
                                      .SingleOrDefault(t => t.Name == "DirectoryTextBox");

            Assert.NotNull(directoryTextBox);

            var separatorPosition = directoryTextBox.Text.LastIndexOf(Path.DirectorySeparatorChar);

            Assert.True(separatorPosition >= 0);

            directoryTextBox.CaretIndex = directoryTextBox.Text.Length;
            var symbolsToRemoveCount = directoryTextBox.Text.Length - separatorPosition;

            for (var i = 0; i < symbolsToRemoveCount; i++)
            {
                Keyboard.PressKey(window, Key.Back);
            }

            await Task.Delay(5000);

            var isParentDirectoryOpened = await DirectoryOpenedCondition.CheckIfParentDirectoryIsOpenedAsync(window, currentDirectory);

            Assert.True(isParentDirectoryOpened);

            var directoryName = Path.GetFileNameWithoutExtension(currentDirectory);

            directoryTextBox.SendText(Path.DirectorySeparatorChar + directoryName);

            var childDirectoryWasOpened =
                await DirectoryOpenedCondition.CheckIfDirectoryIsOpenedAsync(window, currentDirectory);

            Assert.True(childDirectoryWasOpened);
        }
Exemple #9
0
    public async Task CreateDirectoryTest()
    {
        var app    = AvaloniaApp.GetApp();
        var window = AvaloniaApp.GetMainWindow();

        await FocusFilePanelStep.FocusFilePanelAsync(window);

        OpenCreateDirectoryDialogStep.OpenCreateDirectoryDialog(window);
        var isDialogOpened = await DialogOpenedCondition.CheckIfDialogIsOpenedAsync <CreateDirectoryDialog>(app);

        Assert.True(isDialogOpened);

        var viewModel = ActiveFilePanelProvider.GetActiveFilePanelViewModel(window);

        _directoryFullPath = Path.Combine(viewModel.CurrentDirectory, DirectoryName);

        CreateDirectoryStep.CreateDirectory(app, window, DirectoryName);

        var isDialogClosed = await DialogClosedCondition.CheckIfDialogIsClosedAsync <CreateDirectoryDialog>(app);

        Assert.True(isDialogClosed);

        Assert.True(Directory.Exists(_directoryFullPath));
    }
Exemple #10
0
        public async Task CreateAndRemoveDirectoryTest()
        {
            var app    = AvaloniaApp.GetApp();
            var window = AvaloniaApp.GetMainWindow();

            await FocusFilePanelStep.FocusFilePanelAsync(window);

            OpenCreateDirectoryDialogStep.OpenCreateDirectoryDialog(window);
            var isDialogOpened = await DialogOpenedCondition.CheckIfDialogIsOpenedAsync <CreateDirectoryDialog>(app);

            Assert.True(isDialogOpened);

            CreateDirectoryStep.CreateDirectory(app, window, DirectoryName);

            var isDialogClosed = await DialogClosedCondition.CheckIfDialogIsClosedAsync <CreateDirectoryDialog>(app);

            Assert.True(isDialogClosed);

            var filesPanel = ActiveFilePanelProvider.GetActiveFilePanelView(window);

            Assert.NotNull(filesPanel);

            ToggleSearchPanelStep.ToggleSearchPanelVisibility(window);

            await Task.Delay(100);

            var searchPanel = filesPanel
                              .GetVisualDescendants()
                              .OfType <SearchView>()
                              .SingleOrDefault();

            Assert.NotNull(searchPanel);

            var searchTextBox = searchPanel
                                .GetVisualDescendants()
                                .OfType <TextBox>()
                                .SingleOrDefault();

            Assert.NotNull(searchTextBox);

            searchTextBox.SendText(DirectoryName);

            await Task.Delay(1000);

            Keyboard.PressKey(window, Key.Tab);
            Keyboard.PressKey(window, Key.Tab);
            Keyboard.PressKey(window, Key.Down);
            Keyboard.PressKey(window, Key.Down);

            await Task.Delay(100);

            var selectedItemText = GetSelectedItemText(filesPanel);

            Assert.Equal(DirectoryName, selectedItemText);

            OpenRemoveDialogStep.OpenRemoveDialog(window);
            var isRemoveDialogOpened =
                await DialogOpenedCondition.CheckIfDialogIsOpenedAsync <RemoveNodesConfirmationDialog>(app);

            Assert.True(isRemoveDialogOpened);

            Keyboard.PressKey(window, Key.Enter);
            await Task.Delay(100);

            var isRemoveDialogClosed =
                await DialogClosedCondition.CheckIfDialogIsClosedAsync <RemoveNodesConfirmationDialog>(app);

            Assert.True(isRemoveDialogClosed);

            Assert.False(Directory.Exists(_directoryFullPath));
        }
Exemple #11
0
    public async Task TestMoveDirectory()
    {
        var window = AvaloniaApp.GetMainWindow();

        await FocusFilePanelStep.FocusFilePanelAsync(window);

        CreateNewTabStep.CreateNewTab(window);

        var viewModel = ActiveFilePanelProvider.GetActiveFilePanelViewModel(window);

        _sourceDirectoryFullPath = Path.Combine(viewModel.CurrentDirectory, SourceDirectoryName);
        Directory.CreateDirectory(_sourceDirectoryFullPath);

        var fileFullPath = Path.Combine(_sourceDirectoryFullPath, FileName);
        await File.WriteAllTextAsync(fileFullPath, FileContent);

        var innerDirectoryPath = Path.Combine(_sourceDirectoryFullPath, InnerDirectoryName);

        Directory.CreateDirectory(innerDirectoryPath);
        var innerFileFullPath = Path.Combine(innerDirectoryPath, FileName);
        await File.WriteAllTextAsync(innerFileFullPath, FileContent);

        var emptyDirectoryPath = Path.Combine(innerDirectoryPath, EmptyDirectoryName);

        Directory.CreateDirectory(emptyDirectoryPath);

        _targetDirectoryFullPath = Path.Combine(viewModel.CurrentDirectory, TargetDirectoryName);
        Directory.CreateDirectory(_targetDirectoryFullPath);

        ChangeActiveFilePanelStep.ChangeActiveFilePanel(window);
        CreateNewTabStep.CreateNewTab(window);
        FocusDirectorySelectorStep.FocusDirectorySelector(window);
        var textSet = SetDirectoryTextStep.SetDirectoryText(window, _targetDirectoryFullPath);

        Assert.True(textSet);

        await Task.Delay(1000);

        ChangeActiveFilePanelStep.ChangeActiveFilePanel(window);
        await Task.Delay(100);

        ToggleSearchPanelStep.ToggleSearchPanelVisibility(window);
        await Task.Delay(100);

        SearchNodeStep.SearchNode(window, SourceDirectoryName);
        await Task.Delay(300);

        ChangeActiveFilePanelStep.ChangeActiveFilePanel(window);
        ChangeActiveFilePanelStep.ChangeActiveFilePanel(window);
        Keyboard.PressKey(window, Key.Down);
        Keyboard.PressKey(window, Key.Down);

        MoveSelectedNodesStep.MoveSelectedNodes(window);

        ToggleSearchPanelStep.ToggleSearchPanelVisibility(window);
        await Task.Delay(1000);

        var copiedFullPath = Path.Combine(_targetDirectoryFullPath, SourceDirectoryName, FileName);
        var fileExists     = await WaitService.WaitForConditionAsync(() => File.Exists(copiedFullPath));

        Assert.True(fileExists);
        var copiedInnerFullPath = Path.Combine(_targetDirectoryFullPath, SourceDirectoryName, InnerDirectoryName, FileName);
        var innerFileExists     = await WaitService.WaitForConditionAsync(() => File.Exists(copiedInnerFullPath));

        Assert.True(innerFileExists);
        var emptyDirPath   = Path.Combine(_targetDirectoryFullPath, SourceDirectoryName, InnerDirectoryName, EmptyDirectoryName);
        var emptyDirExists = await WaitService.WaitForConditionAsync(() => Directory.Exists(emptyDirPath));

        Assert.True(emptyDirExists);

        foreach (var filePath in new[] { copiedFullPath, copiedInnerFullPath })
        {
            var fileContent = await File.ReadAllTextAsync(filePath);

            Assert.Equal(FileContent, fileContent);
        }

        Assert.False(File.Exists(fileFullPath));
        Assert.False(File.Exists(innerFileFullPath));
        Assert.False(Directory.Exists(emptyDirectoryPath));
        Assert.False(Directory.Exists(_sourceDirectoryFullPath));
    }
    public static async Task <bool> CheckIfDirectoryIsOpenedAsync(MainWindow mainWindow, string directory)
    {
        var viewModel = ActiveFilePanelProvider.GetActiveFilePanelViewModel(mainWindow);

        return(await WaitService.WaitForConditionAsync(() => CheckIfDirectoryWasOpened(viewModel, directory), 100, 50));
    }