Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions QuickShell.Core.Tests/JetBrainsInstallDiscoveryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using QuickShell.Services;

namespace QuickShell.Core.Tests;

public sealed class JetBrainsInstallDiscoveryTests : IDisposable
{
private readonly string _channelRoot;
private readonly string _executable;

public JetBrainsInstallDiscoveryTests()
{
var channelName = "ch-test-" + Guid.NewGuid().ToString("N");
_channelRoot = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"JetBrains",
"Toolbox",
"apps",
"Rider",
channelName);
_executable = Path.Combine(_channelRoot, "241.12345.67", "bin", "rider64.exe");
Directory.CreateDirectory(Path.GetDirectoryName(_executable)!);
File.WriteAllText(_executable, string.Empty);
File.SetLastWriteTimeUtc(_executable, DateTime.UtcNow);
}

[Fact]
public void TryResolveRider_FindsToolboxBuildDirectoryExecutable()
{
var resolved = JetBrainsInstallDiscovery.TryResolveRider();

Assert.NotNull(resolved);
Assert.Equal(_executable, resolved, ignoreCase: true);
}

public void Dispose()
{
try
{
Directory.Delete(_channelRoot, recursive: true);
}
catch
{
}
}
}
7 changes: 7 additions & 0 deletions QuickShell.Core.Tests/ShortcutDisplayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,11 @@ public void GetLaunchContextMenuTitle_UsesOpenFolderWhenCommandAndLabelBlank()

Assert.Equal("Open folder", ShortcutDisplay.GetLaunchContextMenuTitle(entry));
}

[Fact]
public void CopyPath_UsesCopyToGlyph_NotIncomingCall()
{
Assert.Equal("\uF413", ShortcutGlyphs.CopyPath);
Assert.NotEqual("\uE77E", ShortcutGlyphs.CopyPath);
}
}
143 changes: 143 additions & 0 deletions QuickShell.Core.Tests/WorkspaceUtilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,103 @@ public void TryDetectDevServerUrl_ReturnsNullWhenNoPackageJson()
Assert.Null(DevServerUrlDetection.TryDetectDevServerUrl(_root));
}

[Fact]
public void TryDetectDevLaunchCommand_ReturnsPackageManagerCommand()
{
WritePackageJson("""
{
"scripts": {
"dev": "vite"
}
}
""");
File.WriteAllText(Path.Combine(_root, "pnpm-lock.yaml"), string.Empty);

Assert.Equal("pnpm dev", DevServerUrlDetection.TryDetectDevLaunchCommand(_root));
Assert.Equal("pnpm dev", DevServerUrlDetection.FormatPackageScriptCommand(_root, "dev"));
}

[Fact]
public void FormatPackageScriptCommand_UsesYarnWhenYarnLockExists()
{
File.WriteAllText(Path.Combine(_root, "yarn.lock"), string.Empty);

Assert.Equal("yarn dev", DevServerUrlDetection.FormatPackageScriptCommand(_root, "dev"));
}

[Fact]
public void TryDetectDevLaunchCommand_FallsBackToStartScript()
{
WritePackageJson("""
{
"scripts": {
"start": "react-scripts start"
},
"dependencies": {
"react-scripts": "5.0.1"
}
}
""");

Assert.Equal("npm start", DevServerUrlDetection.TryDetectDevLaunchCommand(_root));
Assert.Equal("http://localhost:3000", DevServerUrlDetection.TryDetectDevServerUrl(_root));
}

[Fact]
public void ApplyDirectoryHints_SyncsDetectedDevCommandToLaunchEntry()
{
WritePackageJson("""
{
"scripts": {
"dev": "vite"
}
}
""");

var seed = WorkspaceSeedFactory.ApplyDirectoryHints(new TerminalShortcut
{
Name = "sample",
Directory = _root,
Launches = [],
});

Assert.Equal("npm run dev", seed.Command);
Assert.Single(seed.Launches);
Assert.Equal("npm run dev", seed.Launches[0].Command);
}

[Fact]
public void ApplyDirectoryHints_UpdatesExistingBlankLaunchEntry()
{
WritePackageJson("""
{
"scripts": {
"dev": "vite"
}
}
""");

var seed = WorkspaceSeedFactory.ApplyDirectoryHints(new TerminalShortcut
{
Name = "sample",
Directory = _root,
Launches =
[
new WorkspaceEntry
{
Id = "launch-1",
Label = "Main",
Terminal = "default",
IsEnabled = true,
Order = 0,
},
],
});

Assert.Equal("npm run dev", seed.Command);
Assert.Equal("npm run dev", seed.Launches[0].Command);
}

private void WritePackageJson(string contents) =>
File.WriteAllText(Path.Combine(_root, "package.json"), contents);

Expand Down Expand Up @@ -268,6 +365,36 @@ public void TrySuggestFromDirectory_PrefersVsCodeWhenDotVscodeExists()
Assert.True(suggestion.EnableOnLaunch);
}

[Fact]
public void TrySuggestFromDirectory_FallsThroughWhenHigherPriorityCompanionMissing()
{
Directory.CreateDirectory(Path.Combine(_root, ".cursor"));
Directory.CreateDirectory(Path.Combine(_root, ".vscode"));

var cursorInstalled = CompanionAppCatalog.TryResolveExecutable(CompanionAppCatalog.PresetCursor) is not null;
var vsCodeInstalled = CompanionAppCatalog.TryResolveExecutable(CompanionAppCatalog.PresetVsCode) is not null;
var suggestion = CompanionAppDetection.TrySuggestFromDirectory(_root);

if (!cursorInstalled && vsCodeInstalled)
{
Assert.NotNull(suggestion);
Assert.Equal(CompanionAppCatalog.PresetVsCode, suggestion!.PresetId);
return;
}

if (cursorInstalled)
{
Assert.NotNull(suggestion);
Assert.Equal(CompanionAppCatalog.PresetCursor, suggestion!.PresetId);
return;
}

if (!vsCodeInstalled)
{
Assert.Null(suggestion);
}
}

[Fact]
public void ExpandArguments_ReplacesFolderTokenAndDot()
{
Expand All @@ -280,6 +407,22 @@ public void ExpandArguments_ReplacesFolderTokenAndDot()
Assert.Equal("C:\\Projects\\sample", CompanionAppLauncher.ExpandArguments(".", @"C:\Projects\sample"));
}

[Fact]
public void ExpandArguments_ReplacesSolutionToken()
{
var directory = Path.Combine(_root, "sample app");
Directory.CreateDirectory(directory);
var solutionPath = Path.Combine(directory, "Sample App.sln");
File.WriteAllText(solutionPath, string.Empty);

Assert.Equal(
$"\"{solutionPath}\"",
CompanionAppLauncher.ExpandArguments("{solution}", directory));
Assert.Equal(
Path.Combine(_root, "no-solution"),
CompanionAppLauncher.ExpandArguments("{solution}", Path.Combine(_root, "no-solution")));
}

[Fact]
public void TryValidateCompanionApp_RequiresPathWhenLaunchEnabled()
{
Expand Down
3 changes: 1 addition & 2 deletions QuickShell.Core/Models/TerminalShortcut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ internal sealed class TerminalShortcut



/// <summary>Optional dev server URL opened from the workspace action menu.</summary>

/// <summary>Optional dev server URL opened in the browser when the workspace runs.</summary>
public string? DevServerUrl { get; set; }


Expand Down
Loading
Loading