Skip to content

Commit d04040c

Browse files
authored
Fix scenario tests (#265)
### Motivation and Context <!-- Thank you for your contribution to the copilot-chat repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> The scenario tests have been failing for a long time, due to rapid changes coming into the repo. It's time to fix them. ### Contribution Checklist 1. Skip Jira plugin test since we don't have a managed account. 2. Fix all other tests. Will create an item to track the GitHub and Jira plugin tests. <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [Contribution Guidelines](https://github.com/microsoft/copilot-chat/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/copilot-chat/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄
1 parent 679bd07 commit d04040c

File tree

12 files changed

+74
-36
lines changed

12 files changed

+74
-36
lines changed

.github/workflows/copilot-test-e2e.yml

+10-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,15 @@ jobs:
3939
env:
4040
AzureOpenAI__ApiKey: ${{ secrets.AZUREOPENAI__APIKEY }}
4141
AzureOpenAI__Endpoint: ${{ secrets.AZUREOPENAI__ENDPOINT }}
42+
TenantId: ${{ secrets.COPILOT_CHAT_TEST_APP_AAD_TENANT_ID }}
43+
WebApi_ClientId: ${{ secrets.COPILOT_CHAT_TEST_APP_AAD_WEBAPI_CLIENT_ID }}
4244
run: |
4345
dotnet dev-certs https
4446
dotnet user-secrets set "AIService:Key" "$AzureOpenAI__ApiKey"
4547
dotnet user-secrets set "AIService:Endpoint" "$AzureOpenAI__Endpoint"
48+
dotnet user-secrets set "Authentication:Type" "AzureAd"
49+
dotnet user-secrets set "Authentication:AzureAd:TenantId" "$TenantId"
50+
dotnet user-secrets set "Authentication:AzureAd:ClientId" "$WebApi_ClientId"
4651
4752
- name: Start service in background
4853
working-directory: webapi
@@ -63,8 +68,11 @@ jobs:
6368
- name: Run Playwright tests
6469
env:
6570
REACT_APP_BACKEND_URI: https://localhost:40443/
66-
REACT_APP_AAD_CLIENT_ID: ${{ secrets.COPILOT_CHAT_REACT_APP_AAD_CLIENT_ID }}
67-
REACT_APP_AAD_AUTHORITY: https://login.microsoftonline.com/common
71+
72+
REACT_APP_AUTH_TYPE: AzureAd
73+
REACT_APP_AAD_AUTHORITY: https://login.microsoftonline.com/${{ secrets.COPILOT_CHAT_TEST_APP_AAD_TENANT_ID }}
74+
REACT_APP_AAD_CLIENT_ID: ${{ secrets.COPILOT_CHAT_TEST_APP_AAD_CLIENT_ID }}
75+
REACT_APP_AAD_API_SCOPE: api://${{ secrets.COPILOT_CHAT_TEST_APP_AAD_WEBAPI_CLIENT_ID }}/access_as_user
6876

6977
REACT_APP_TEST_USER_ACCOUNT1: ${{ secrets.COPILOT_CHAT_TEST_USER_ACCOUNT1 }}
7078
REACT_APP_TEST_USER_ACCOUNT1_INITIALS: ${{ secrets.COPILOT_CHAT_TEST_USER_ACCOUNT1_INITIALS }}

webapp/src/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ const Chat = ({
171171
<Subtitle1 as="h1">Chat Copilot</Subtitle1>
172172
{appState > AppState.SettingUserInfo && (
173173
<div className={classes.cornerItems}>
174-
<div data-testid="logOutMenuList" className={classes.cornerItems}>
174+
<div className={classes.cornerItems}>
175175
<PluginGallery />
176176
<UserSettingsMenu
177177
setLoadingState={() => {

webapp/src/components/chat/chat-list/ListItemActions.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export const ListItemActions: React.FC<IListItemActionsProps> = ({ chatId, onEdi
6565
appearance="transparent"
6666
aria-label="Edit chat name"
6767
onClick={onEditTitleClick}
68+
data-testid="editChatTitleButtonSimplified"
6869
/>
6970
</Tooltip>
7071
<Tooltip content={'Download chat session'} relationship="label">

webapp/src/components/chat/invitation-dialog/InvitationCreateDialog.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ export const InvitationCreateDialog: React.FC<InvitationCreateDialogProps> = ({
5050
<DialogTitle>Invite others to your Bot</DialogTitle>
5151
<DialogContent className={classes.content}>
5252
<Label>Please provide the following Chat ID to your friends so they can join the chat.</Label>
53-
<Label data-testid="chatIDLabel" weight="semibold">
53+
<Label data-testid="invitationDialogChatIDLabel" weight="semibold">
5454
{chatId}
5555
</Label>
5656
</DialogContent>
5757
<DialogActions>
58-
<Button data-testid="chatIDCloseButton" appearance="secondary" onClick={onCancel}>
58+
<Button data-testid="invitationDialogCloseButton" appearance="secondary" onClick={onCancel}>
5959
Close
6060
</Button>
6161
<Button
62-
data-testid="chatIDCopyButton"
62+
data-testid="invitationDialogChatIDCopyButton"
6363
appearance="primary"
6464
onClick={copyId}
6565
icon={isIdCopied ? <Checkmark20Filled /> : null}

webapp/src/components/header/UserSettingsMenu.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export const UserSettingsMenu: FC<IUserSettingsProps> = ({ setLoadingState }) =>
6868
? { status: 'available' }
6969
: undefined
7070
}
71+
data-testid="userSettingsButton"
7172
/>
7273
}
7374
</MenuTrigger>
@@ -101,7 +102,7 @@ export const UserSettingsMenu: FC<IUserSettingsProps> = ({ setLoadingState }) =>
101102
</Menu>
102103
) : (
103104
<Button
104-
data-testid="settingsButton"
105+
data-testid="settingsButtonWithoutAuth"
105106
style={{ color: 'white' }}
106107
appearance="transparent"
107108
icon={<Settings24Regular color="white" />}

webapp/src/components/header/settings-dialog/SettingSection.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const SettingSection: React.FC<ISettingsSectionProps> = ({ setting, conte
5656
onChange={() => {
5757
onFeatureChange(key);
5858
}}
59+
data-testid={feature.label}
5960
/>
6061
<Text
6162
className={classes.featureDescription}

webapp/src/components/header/settings-dialog/SettingsDialog.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export const SettingsDialog: React.FC<ISettingsDialogProps> = ({ open, closeDial
8181
</AccordionItem>
8282
<Divider />
8383
<AccordionItem value="advanced">
84-
<AccordionHeader expandIconPosition="end">
84+
<AccordionHeader expandIconPosition="end" data-testid="advancedSettingsFoldup">
8585
<h3>Advanced</h3>
8686
</AccordionHeader>
8787
<AccordionPanel>
@@ -120,7 +120,9 @@ export const SettingsDialog: React.FC<ISettingsDialogProps> = ({ open, closeDial
120120
</a>
121121
</Label>
122122
<DialogTrigger disableButtonEnhancement>
123-
<Button appearance="secondary">Close</Button>
123+
<Button appearance="secondary" data-testid="userSettingsCloseButton">
124+
Close
125+
</Button>
124126
</DialogTrigger>
125127
</DialogActions>
126128
</DialogSurface>

webapp/src/components/views/Login.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const Login: React.FC = () => {
2626
onClick={() => {
2727
instance.loginRedirect().catch(() => {});
2828
}}
29+
data-testid="signinButton"
2930
>
3031
<Image src={signInLogo} />
3132
</Button>

webapp/tests/chat.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ test.describe('Copilot Chat App Test Suite', () => {
4444
await plannertests.klarnaTest(page);
4545
});
4646

47-
test('Jira', async ({ page }) => {
47+
test.skip('Jira', async ({ page }) => {
4848
test.setTimeout(util.TestTimeout);
4949
await plannertests.jiraTest(page);
5050
});

webapp/tests/testsBasic.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { expect } from '@playwright/test';
2-
import * as util from './utils'
2+
import * as util from './utils';
33

44
/*
55
Summary: Checks if the server is running and healthy
66
*/
7-
export async function serverHealth( page ) {
7+
export async function serverHealth(page) {
88
// Make sure the server is running.
99
await page.goto('https://localhost:40443/healthz');
1010
await expect(page.getByText('Healthy')).toBeDefined();
@@ -19,13 +19,13 @@ Summary: Tests for the following behaviour from the WebApp:
1919
- Chat History has the correct number of messages and that the last message is from Copilot
2020
- SK core skill testing for jokes and fun facts
2121
*/
22-
export async function basicBotResponses( page ) {
22+
export async function basicBotResponses(page) {
2323
await util.loginAndCreateNewChat(page);
24-
25-
const joke = "Can you tell me a funny joke about penguins?";
24+
25+
const joke = 'Can you tell me a funny joke about penguins?';
2626
await util.sendChatMessageAndWaitForResponse(page, joke);
2727

28-
const funfact = "Tell me a fun fact about the cosmos!";
28+
const funfact = 'Tell me a fun fact about the cosmos!';
2929
await util.sendChatMessageAndWaitForResponse(page, funfact);
3030

3131
// Expect the chat history to contain 7 messages (both user messages and bot responses).
@@ -43,8 +43,8 @@ Summary: Tests if the title for the current chat can be changed
4343
*/
4444
export async function chatTitleChange(page) {
4545
await util.loginAndCreateNewChat(page);
46-
47-
await page.getByTestId('editChatTitleButton').click();
46+
47+
await page.getByTestId('editChatTitleButtonSimplified').click();
4848
await page.locator('input[type="text"]').fill('Copilot Unit Tests');
4949
await page.locator('input[type="text"]').press('Enter');
5050

@@ -54,17 +54,17 @@ export async function chatTitleChange(page) {
5454
/*
5555
Summary: Tests if a single document can be uploaded and then found in the 'Files' tab
5656
*/
57-
export async function documentUpload(page) {
57+
export async function documentUpload(page) {
5858
await util.loginAndCreateNewChat(page);
59-
59+
6060
const testFilename = 'Lorem_ipsum.pdf';
61-
const testFilepath = './../importdocument/sample-docs/' + testFilename;
62-
await page.setInputFiles("input[type='file']", testFilepath)
63-
64-
await page.getByTestId('filesTab').click();// Go to the file page
61+
const testFilepath = './../tools/importdocument/sample-docs/' + testFilename;
62+
await page.setInputFiles("input[type='file']", testFilepath);
63+
64+
await page.getByTestId('documentsTab').click(); // Go to the documents tab
6565
// Check if corresponding cell for the file exists after upload
6666
await page.getByRole('cell', { name: testFilename }).locator('path');
6767
await page.getByTestId('chatTab').click(); // Go back to the chat page
6868

6969
await util.postUnitTest(page);
70-
}
70+
}

webapp/tests/testsMultiuser.ts

+25-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@playwright/test';
2-
import * as util from './utils'
2+
import * as util from './utils';
33

44
/*
55
Summary: Tests the Multiuser feature of Copilot Chat. Specifically if a user can
@@ -14,32 +14,49 @@ export async function shareAndJoinChatSessionTest(page) {
1414
await util.loginHelper(page, userAccount1, password1);
1515
await util.createNewChat(page);
1616

17+
// Need to enable live chat session sharing to access the share button
18+
await page.getByTestId('userSettingsButton').click();
19+
await page.getByTestId('settingsMenuItem').click();
20+
await page.getByTestId('advancedSettingsFoldup').click();
21+
await page.getByTestId('Live Chat Session Sharing').click();
22+
await page.getByTestId('userSettingsCloseButton').click();
23+
1724
await page.getByTestId('shareButton').click();
1825
await page.getByTestId('inviteOthersMenuItem').click();
1926

20-
const labelByID = await page.getByTestId('chatIDLabel');
27+
const labelByID = await page.getByTestId('invitationDialogChatIDLabel');
2128
const chatId = await labelByID.textContent();
22-
await page.getByTestId('chatIDCloseButton').click();
29+
await page.getByTestId('invitationDialogCloseButton').click();
2330

24-
await page.getByTestId('logOutMenuList').click();
31+
await page.getByTestId('userSettingsButton').click();
2532
await page.getByTestId('logOutMenuButton').click();
2633

2734
const usernameToLowerCase = userAccount1.toLowerCase();
2835
const locatorVal = ('[data-test-id="' + usernameToLowerCase + '"]') as string;
2936
await page.locator(locatorVal).click();
3037

38+
// Login with the second user account
3139
await util.loginHelperAnotherUser(page, userAccount2, password2);
40+
41+
// Need to enable live chat session sharing to access the join button
42+
await page.getByTestId('userSettingsButton').click();
43+
await page.getByTestId('settingsMenuItem').click();
44+
await page.getByTestId('advancedSettingsFoldup').click();
45+
await page.getByTestId('Simplified Chat Experience').click();
46+
await page.getByTestId('Live Chat Session Sharing').click();
47+
await page.getByTestId('userSettingsCloseButton').click();
48+
3249
await page.getByTestId('createNewConversationButton').click();
3350
await page.getByTestId('joinABotMenuItem').click();
3451
await page.getByTestId('enterChatIDLabel').fill(chatId as string);
3552

3653
await page.getByTestId('joinChatButton').click();
3754

3855
await page.waitForTimeout(util.ChatStateChangeWait);
39-
40-
await page.getByTestId('chatParticipantsView').click();
56+
57+
await page.getByTestId('chatParticipantsView').click();
4158
const numPeople = await page.getByTestId('chatParticipantsView').textContent();
42-
await expect(numPeople).toEqual("+2");
59+
await expect(numPeople).toEqual('+2');
4360

4461
await util.postUnitTest(page);
45-
}
62+
}

webapp/tests/utils.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const EvaluatePrompt =
1111
export async function loginHelper(page, useraccount, password) {
1212
await page.goto('/');
1313
// Expect the page to contain a "Login" button.
14-
await page.getByRole('button').click();
14+
await page.getByTestId('signinButton').click();
1515
// Clicking the login button should redirect to the login page.
16-
await expect(page).toHaveURL(process.env.REACT_APP_AAD_AUTHORITY);
16+
await expect(page).toHaveURL(new RegExp(`${process.env.REACT_APP_AAD_AUTHORITY}.*`));
1717
// Login with the test user.
1818
await page.getByPlaceholder('Email, phone, or Skype').click();
1919
await page.getByPlaceholder('Email, phone, or Skype').fill(useraccount as string);
@@ -36,7 +36,7 @@ export async function loginHelperAnotherUser(page, useraccount, password) {
3636
// Expect the page to contain a "Login" button.
3737
await page.getByRole('button').click();
3838
// Clicking the login button should redirect to the login page.
39-
await expect(page).toHaveURL(process.env.REACT_APP_AAD_AUTHORITY);
39+
await expect(page).toHaveURL(new RegExp(`${process.env.REACT_APP_AAD_AUTHORITY}.*`));
4040
// Login with the another user account.
4141
await page.getByRole('button', { name: 'Use another account' }).click();
4242
await page.getByPlaceholder('Email, phone, or Skype').click();
@@ -48,6 +48,13 @@ export async function loginHelperAnotherUser(page, useraccount, password) {
4848

4949
// After login, the page should redirect back to the app.
5050
await expect(page).toHaveTitle('Copilot Chat');
51+
52+
// Get the permission popup if they open
53+
page.on('popup', async (popup) => {
54+
await popup.waitForLoadState();
55+
await popup.getByRole('button', { name: 'Next' }).click();
56+
await popup.getByRole('button', { name: 'Accept' }).click();
57+
});
5158
}
5259
export async function createNewChat(page) {
5360
await page.getByTestId('createNewConversationButton').click();

0 commit comments

Comments
 (0)