You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
4.6 KiB
124 lines
4.6 KiB
import { test, expect } from '@playwright/test';
|
|
import { getTestUserData, switchToUser, importUser } from './testUtils';
|
|
|
|
/**
|
|
* Test Active Identity Migration
|
|
*
|
|
* This test verifies that the new Active Identity façade methods work correctly
|
|
* and that identity switching functionality is preserved after migration.
|
|
*
|
|
* @author Matthew Raymer
|
|
* @date 2025-08-22T07:15Z
|
|
*/
|
|
|
|
test.describe('Active Identity Migration', () => {
|
|
test('should switch between identities using new façade methods', async ({ page }) => {
|
|
// Test setup: ensure we have at least two users
|
|
const userZeroData = getTestUserData('00');
|
|
const userOneData = getTestUserData('01');
|
|
|
|
// Import both users to ensure they exist
|
|
try {
|
|
await importUser(page, '00');
|
|
await page.waitForLoadState('networkidle');
|
|
} catch (error) {
|
|
// User Zero might already exist, continue
|
|
}
|
|
|
|
try {
|
|
await importUser(page, '01');
|
|
await page.waitForLoadState('networkidle');
|
|
} catch (error) {
|
|
// User One might already exist, continue
|
|
}
|
|
|
|
// Ensure we start with User Zero active
|
|
await switchToUser(page, userZeroData.did);
|
|
|
|
// Start with User Zero (default)
|
|
await page.goto('./account');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
// Verify we're on User Zero
|
|
const didWrapper = page.getByTestId('didWrapper');
|
|
await expect(didWrapper).toContainText(userZeroData.did);
|
|
|
|
// Switch to User One using the identity switcher
|
|
await page.getByTestId('advancedSettings').click();
|
|
|
|
// Wait for the switch identity link to be visible
|
|
const switchIdentityLink = page.locator('#switch-identity-link');
|
|
await switchIdentityLink.waitFor({ state: 'visible', timeout: 10000 });
|
|
await switchIdentityLink.click();
|
|
|
|
// Wait for identity switcher to load
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
// Click on User One's DID to switch
|
|
const userOneDidElement = page.locator(`code:has-text("${userOneData.did}")`);
|
|
await expect(userOneDidElement).toBeVisible();
|
|
await userOneDidElement.click();
|
|
|
|
// Wait for the switch to complete and verify we're now User One
|
|
await page.waitForLoadState('networkidle');
|
|
await expect(didWrapper).toContainText(userOneData.did);
|
|
|
|
// Verify the switch was successful by checking the account page
|
|
await expect(page.locator('h1:has-text("Your Identity")')).toBeVisible();
|
|
});
|
|
|
|
test('should maintain identity state after page refresh', async ({ page }) => {
|
|
// Start with User One
|
|
await switchToUser(page, getTestUserData('01').did);
|
|
|
|
// Verify we're on User One
|
|
const didWrapper = page.getByTestId('didWrapper');
|
|
await expect(didWrapper).toContainText(getTestUserData('01').did);
|
|
|
|
// Refresh the page
|
|
await page.reload();
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
// Verify we're still User One (identity persistence)
|
|
await expect(didWrapper).toContainText(getTestUserData('01').did);
|
|
});
|
|
|
|
test('should handle identity switching errors gracefully', async ({ page }) => {
|
|
// Navigate to identity switcher
|
|
await page.goto('./account');
|
|
await page.getByTestId('advancedSettings').click();
|
|
|
|
// Wait for the switch identity link to be visible
|
|
const switchIdentityLink = page.locator('#switch-identity-link');
|
|
await switchIdentityLink.waitFor({ state: 'visible', timeout: 10000 });
|
|
await switchIdentityLink.click();
|
|
|
|
// Wait for identity switcher to load
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
// Try to switch to a non-existent identity (this should be handled gracefully)
|
|
// Note: This test verifies error handling without causing actual failures
|
|
|
|
// Verify the identity switcher is still functional
|
|
await expect(page.locator('h1:has-text("Switch Identity")')).toBeVisible();
|
|
await expect(page.locator('#start-link')).toBeVisible();
|
|
});
|
|
|
|
test('should preserve existing identity data during migration', async ({ page }) => {
|
|
// This test verifies that existing identity data is preserved
|
|
// and accessible through the new façade methods
|
|
|
|
// Start with User Zero
|
|
await switchToUser(page, getTestUserData('00').did);
|
|
|
|
// Navigate to a page that uses activeDid
|
|
await page.goto('./home');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
// Verify the page loads correctly with the active identity
|
|
await expect(page.locator('h1:has-text("Home")')).toBeVisible();
|
|
|
|
// The page should load without errors, indicating the new façade methods work
|
|
// and the active identity is properly retrieved
|
|
});
|
|
});
|
|
|