Skip to content

Commit

Permalink
UI tests improvements (#153)
Browse files Browse the repository at this point in the history
CLOSE https://linear.app/sourcegraph/issue/CODY-4322/make-entered-prompt-show-up-in-today-history-working-in-the-ci

- Entered_Prompt_Show_Up_In_Today_History() is finally working
- New test  Active_File_Match_Current_Chat_Context()
- Added NewChat() method
- Added delay to ShowChatTab() method
- DismissStartWindow() method called at the of EnterChatTextAndSend() because VS modal dialog for selecting project is showing up in the foreground for some reason
  • Loading branch information
PiotrKarczmarz authored Nov 27, 2024
1 parent 72af86b commit 5fb499c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 11 deletions.
29 changes: 25 additions & 4 deletions src/Cody.VisualStudio.Tests/ChatLoggedBasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public async Task Active_File_Name_And_Line_Selection_Is_Showing_In_Chat_Input()
{
// given
await WaitForPlaywrightAsync();
await NewChat();

await OpenSolution(SolutionsPaths.GetConsoleApp1File("ConsoleApp1.sln"));

// when
Expand All @@ -46,6 +48,28 @@ public async Task Active_File_Name_And_Line_Selection_Is_Showing_In_Chat_Input()
Assert.Equal(endLine, secondTag.EndLine);
}

[VsFact(Version = VsVersion.VS2022)]
public async Task Active_File_Match_Current_Chat_Context()
{
// given
await WaitForPlaywrightAsync();
await NewChat();

await OpenSolution(SolutionsPaths.GetConsoleApp1File("ConsoleApp1.sln"));

// when
const int startLine = 2; const int endLine = 3;
await OpenDocument(SolutionsPaths.GetConsoleApp1File(@"ConsoleApp1\Program.cs"), startLine, endLine);
var tags = await GetChatContextTags();

// then
var firstTagName = tags.First().Name;
var secondTag = tags.ElementAt(1);
Assert.Equal("Program.cs", firstTagName);
Assert.Equal(startLine, secondTag.StartLine);
Assert.Equal(endLine, secondTag.EndLine);
}

[VsFact(Version = VsVersion.VS2022)]
public async Task Can_Chat_Tool_Window_Be_Closed_And_Opened_Again()
{
Expand All @@ -60,7 +84,7 @@ public async Task Can_Chat_Tool_Window_Be_Closed_And_Opened_Again()
Assert.True(isOpen);
}

//[VsFact(Version = VsVersion.VS2022)]
[VsFact(Version = VsVersion.VS2022)]
public async Task Entered_Prompt_Show_Up_In_Today_History()
{
var num = new Random().Next();
Expand All @@ -69,14 +93,11 @@ public async Task Entered_Prompt_Show_Up_In_Today_History()
await WaitForPlaywrightAsync();

await EnterChatTextAndSend(prompt);
await CloseCodyChatToolWindow();

await OpenCodyChatToolWindow();
await ShowHistoryTab();
var chatHistoryEntries = await GetTodayChatHistory();

Assert.Contains(chatHistoryEntries, x => x.Contains(prompt));

}

public void Dispose()
Expand Down
32 changes: 25 additions & 7 deletions src/Cody.VisualStudio.Tests/PlaywrightTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,18 @@ protected async Task AssertTextIsPresent(string text)
Assert.Equal(text, textContents.First());
}

protected async Task ShowChatTab() => await Page.GetByTestId("tab-chat").ClickAsync();
protected async Task ShowChatTab()
{
await Page.GetByTestId("tab-chat").ClickAsync();
await Task.Delay(500);
}

protected async Task NewChat()
{
await Page.GetByRole(AriaRole.Button, new PageGetByRoleOptions {Name = "New Chat"}).ClickAsync();

await Task.Delay(500);
}

protected async Task ShowHistoryTab()
{
Expand All @@ -158,15 +169,21 @@ protected async Task ShowHistoryTab()

protected async Task EnterChatTextAndSend(string prompt)
{
var entryArea = Page.Locator("[data-keep-toolbar-open=true]").Last;

await entryArea.PressSequentiallyAsync(prompt);
await entryArea.PressAsync("Enter");
var entryArea = Page.Locator("span[data-lexical-text='true']");
var enterArea = Page.Locator("[data-keep-toolbar-open=true]").Last;

var button = await Page.WaitForSelectorAsync("menu button[type=submit][title=Stop]");
await entryArea.FillAsync(prompt);
await enterArea.PressAsync("Enter");

while (await button.GetAttributeAsync("title") == "Stop") await Task.Delay(500);
var isStopVisible = false;
while (!isStopVisible)
{
isStopVisible = await Page.Locator("vscode-button").First.IsVisibleAsync();
await Task.Delay(500);
}
await Task.Delay(500);

await DismissStartWindow();
}

protected async Task<string[]> GetTodayChatHistory()
Expand All @@ -182,6 +199,7 @@ protected async Task<string[]> GetTodayChatHistory()
protected async Task<IReadOnlyCollection<ContextTag>> GetChatContextTags()
{
var tagsList = new List<ContextTag>();
await ShowChatTab();

WriteLog("Searching for Chat ...");
var chatBox = await Page.QuerySelectorAsync("[aria-label='Chat message']");
Expand Down
4 changes: 4 additions & 0 deletions src/Cody.VisualStudio/Services/ThemeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,14 @@ public string GetThemingScript()

// Generate the CSS variables for the fonts.
var editorFont = GetEditorFont();
_logger.Debug($"Detected editor font:{editorFont.FontName} size:{editorFont.Size}");

sb.AppendLine($"rootStyle.setProperty('--visualstudio-editor-font-family', '{editorFont.FontName}');");
sb.AppendLine($"rootStyle.setProperty('--visualstudio-editor-font-size', '{editorFont.Size}pt');");

var uiFont = GetUIFont();
_logger.Debug($"Detected UI font:{uiFont.FontName} size:{uiFont.Size}");

sb.AppendLine($"rootStyle.setProperty('--visualstudio-ui-font-family', '{uiFont.FontName}');");
sb.AppendLine($"rootStyle.setProperty('--visualstudio-ui-font-size', '{uiFont.Size}pt');");

Expand Down

0 comments on commit 5fb499c

Please sign in to comment.