Skip to content

Commit

Permalink
e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
nirgur committed Sep 12, 2024
1 parent 9db7210 commit a7fd3f8
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { test, expect } from '@playwright/test';
import mockTheme from '../test/mocks/mockTheme';
import { apiPaths } from '../src/lib/widget/api/apiPaths';
import rootMock from '../test/mocks/rootMock';
import { mockSsoApps } from '../test/mocks/mockSsoApps';
import { SSOAppType } from '../src/lib/widget/api/types';

const configContent = {
flows: {
flow1: { version: 1 },
},
componentsVersion: '1.2.3',
};

const apiPath = (prop: 'ssoApps', path: string) =>
`**/*${apiPaths[prop][path]}`;

const samlApps = mockSsoApps
.filter((app) => app.appType === SSOAppType.saml)

test.describe('widget', () => {
test.beforeEach(async ({ page }) => {
await page.addInitScript(() =>
window.localStorage.setItem(
'base.ui.components.url',
'http://localhost:8769/umd/index.js',
),
);

await page.route('*/**/config.json', async (route) =>
route.fulfill({ json: configContent }),
);

await page.route('*/**/theme.json', async (route) =>
route.fulfill({ json: mockTheme }),
);

await page.route('*/**/root.html', async (route) =>
route.fulfill({ body: rootMock }),
);

await page.route(apiPath('ssoApps', 'load'), async (route) =>
route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ apps: mockSsoApps }),
}),
);

await page.route('**/auth/me', async (route) =>
route.fulfill({
json: {
userTenants: [
{
tenantId: 'tid',
roleNames: ['Tenant Admin'],
},
],
},
}),
);

await page.goto('http://localhost:5560');
});

test('saml apps are in the list', async ({ page }) => {
for (const app of samlApps) {
await expect(
page.locator(`text=${app.name}`).first(),
).toBeVisible();
}
});
test('click app opens a new tab', async ({ page }) => {
const newTabPromise = page.waitForEvent("popup");

const app = page.locator(`text=${samlApps[0].name}`).first()
await app.click()

const newTab = await newTabPromise;
await newTab.waitForLoadState();

await expect(newTab).toHaveURL(samlApps[0].samlSettings.idpInitiatedUrl);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default defineConfig({
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'http://localhost:5556',
baseURL: 'http://localhost:5560',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
Expand Down Expand Up @@ -89,11 +89,11 @@ export default defineConfig({
/* Run your local dev server before starting the tests */
webServer: [
{
command: 'npx serve node_modules/@descope/web-components-ui/dist -p 8766',
command: 'npx serve node_modules/@descope/web-components-ui/dist -p 8769',
},
{
command: 'npx serve build -l 5556',
url: 'http://localhost:5556',
command: 'npx serve build -l 5560',
url: 'http://localhost:5560',
reuseExistingServer: !process.env.CI,
timeout: 120 * 1000,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const mockSsoApps = [
appType: SSOAppType.saml,
logo: 'logo1',
samlSettings: {
idpInitiatedURL: 'http://idpInitiatedURL.com',
idpInitiatedUrl: 'http://www.testingmcafeesites.com/testcat_ac.html',
},
},
{
Expand All @@ -28,7 +28,7 @@ export const mockSsoApps = [
appType: SSOAppType.saml,
logo: 'logo3',
samlSettings: {
idpInitiatedURL: 'http://idpInitiatedURL2.com',
idpInitiatedUrl: 'http://www.testingmcafeesites.com/testcat_ac.html',
},
},
]
Loading

0 comments on commit a7fd3f8

Please sign in to comment.