-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
E2E Test: Sign in page check update (#140)
- Added test for Cody Free/Cody Enterprise sections - Introduced ThreadHelper.JoinableTaskContext to use single setup step for every test in the constructor CLOSE https://linear.app/sourcegraph/issue/CODY-4234/e2e-test-sign-in-page-check-update
- Loading branch information
1 parent
61f6ca7
commit 0f62067
Showing
2 changed files
with
70 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,84 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.Threading; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Microsoft.VisualStudio.Shell; | ||
|
||
namespace Cody.VisualStudio.Tests | ||
{ | ||
public class ChatNotLoggedStateTests : PlaywrightTestsBase, IDisposable | ||
{ | ||
private readonly JoinableTaskContext _context = ThreadHelper.JoinableTaskContext; | ||
|
||
private string _accessToken; | ||
|
||
public ChatNotLoggedStateTests(ITestOutputHelper output) : base(output) | ||
{ | ||
_context.Factory.Run(async () => | ||
{ | ||
await WaitForPlaywrightAsync(); | ||
_accessToken = await GetAccessToken(); | ||
|
||
if (_accessToken != null) | ||
await SetAccessToken("INVALID"); | ||
}); | ||
|
||
} | ||
|
||
[VsFact(Version = VsVersion.VS2022)] | ||
public async Task Loads_Properly_InNotLoggedState() | ||
public async Task Cody_Free_Cody_Pro_Section_Is_Present() | ||
{ | ||
// given | ||
var sectionText = "Cody Free or Cody Pro"; | ||
var buttonText = "Sign In with GitHub"; | ||
|
||
var text = "Cody Free or Cody Pro"; | ||
IReadOnlyList<string> textContents; | ||
string accessToken = null; | ||
try | ||
{ | ||
await WaitForPlaywrightAsync(); | ||
// then | ||
await AssertTextIsPresent(sectionText); | ||
await AssertTextIsPresent(buttonText); | ||
} | ||
|
||
accessToken = await GetAccessToken(); | ||
if (accessToken != null) | ||
await SetAccessToken("INVALID"); | ||
[VsFact(Version = VsVersion.VS2022)] | ||
public async Task Cody_Enterprise_Section_Is_Present() | ||
{ | ||
// given | ||
var sectionText = "Cody Enterprise"; | ||
var browserButtonText = " Sign In with Browser"; | ||
var tokenButtonText = " Sign In with Access Token"; | ||
|
||
// when | ||
var getStarted = Page.GetByText(text); | ||
textContents = await getStarted.AllTextContentsAsync(); | ||
} | ||
finally | ||
{ | ||
if (accessToken != null) | ||
await SetAccessToken(accessToken); // make it valid | ||
} | ||
// then | ||
await AssertTextIsPresent(sectionText); | ||
await AssertTextIsPresent(browserButtonText); | ||
await AssertTextIsPresent(tokenButtonText); | ||
} | ||
|
||
[VsFact(Version = VsVersion.VS2022)] | ||
public async Task Logins_With_GitLab_Google_Are_Present() | ||
{ | ||
// given | ||
var gitlabButtonText = "Sign In with GitLab"; | ||
var googleButtonText = "Sign In with Google"; | ||
|
||
// then | ||
Assert.Equal(text, textContents.First()); | ||
await AssertTextIsPresent(gitlabButtonText); | ||
await AssertTextIsPresent(googleButtonText); | ||
} | ||
|
||
public void Dispose() | ||
|
||
public async void Dispose() | ||
{ | ||
var testName = GetTestName(); | ||
TakeScreenshot(testName); | ||
try | ||
{ | ||
var testName = GetTestName(); | ||
TakeScreenshot(testName); | ||
|
||
if (_accessToken != null) | ||
await SetAccessToken(_accessToken); // make it valid | ||
} | ||
catch (Exception ex) | ||
{ | ||
WriteLog($"Dispose() for {GetTestName()} failed."); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters