forked from trent_larson/crowd-funder-for-time-pwa
fix error setting the apiServer to "", plus some refactors while fixing test 40
This commit is contained in:
@@ -25,8 +25,9 @@ export default defineConfig({
|
||||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
||||
reporter: [
|
||||
['list'],
|
||||
['html', { open: 'never' }],
|
||||
['json', { outputFile: 'test-results/test-results.json' }]
|
||||
['html'],
|
||||
// ['html', { open: 'never' }], // don't automatically open report page after tests complete even with failures
|
||||
['json', { outputFile: 'test-playwright-results/test-results.json' }]
|
||||
],
|
||||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
||||
use: {
|
||||
|
||||
@@ -78,7 +78,7 @@ db.version(4)
|
||||
});
|
||||
});
|
||||
|
||||
const DEFAULT_SETTINGS = {
|
||||
const DEFAULT_SETTINGS: Settings = {
|
||||
id: MASTER_SETTINGS_KEY,
|
||||
activeDid: undefined,
|
||||
apiServer: DEFAULT_ENDORSER_API_SERVER,
|
||||
@@ -183,42 +183,34 @@ export async function retrieveSettingsForActiveAccount(): Promise<Settings> {
|
||||
}
|
||||
}
|
||||
|
||||
// Update settings for the given account, or in MASTER_SETTINGS_KEY if no accountDid is provided.
|
||||
// Don't expose this because we should be explicit on whether we're updating the default settings or account settings.
|
||||
async function updateSettings(settingsChanges: Settings): Promise<void> {
|
||||
await db.open();
|
||||
if (!settingsChanges.accountDid) {
|
||||
// ensure there is no "id" that would override the key
|
||||
delete settingsChanges.id;
|
||||
await db.settings.update(MASTER_SETTINGS_KEY, settingsChanges);
|
||||
} else {
|
||||
const result = await db.settings
|
||||
.where("accountDid")
|
||||
.equals(settingsChanges.accountDid)
|
||||
.modify(settingsChanges);
|
||||
if (result === 0) {
|
||||
if (!settingsChanges.id) {
|
||||
// It is unfortunate that we have to set this explicitly.
|
||||
// We didn't make id a "++id" at the beginning and Dexie won't let us change it,
|
||||
// plus we made our first settings objects MASTER_SETTINGS_KEY = 1 instead of 0
|
||||
settingsChanges.id = (await db.settings.count()) + 1;
|
||||
}
|
||||
await db.settings.add(settingsChanges);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateDefaultSettings(settings: Settings): Promise<void> {
|
||||
delete settings.accountDid; // just in case
|
||||
await updateSettings(settings);
|
||||
export async function updateDefaultSettings(
|
||||
settingsChanges: Settings,
|
||||
): Promise<void> {
|
||||
delete settingsChanges.accountDid; // just in case
|
||||
// ensure there is no "id" that would override the key
|
||||
delete settingsChanges.id;
|
||||
await db.settings.update(MASTER_SETTINGS_KEY, settingsChanges);
|
||||
}
|
||||
|
||||
export async function updateAccountSettings(
|
||||
accountDid: string,
|
||||
settings: Settings,
|
||||
settingsChanges: Settings,
|
||||
): Promise<void> {
|
||||
settings.accountDid = accountDid;
|
||||
await updateSettings(settings);
|
||||
settingsChanges.accountDid = accountDid;
|
||||
delete settingsChanges.id; // key off account, not ID
|
||||
const result = await db.settings
|
||||
.where("accountDid")
|
||||
.equals(settingsChanges.accountDid)
|
||||
.modify(settingsChanges);
|
||||
if (result === 0) {
|
||||
if (!settingsChanges.id) {
|
||||
// It is unfortunate that we have to set this explicitly.
|
||||
// We didn't make id a "++id" at the beginning and Dexie won't let us change it,
|
||||
// plus we made our first settings objects MASTER_SETTINGS_KEY = 1 instead of 0
|
||||
settingsChanges.id = (await db.settings.count()) + 1;
|
||||
}
|
||||
await db.settings.add(settingsChanges);
|
||||
}
|
||||
}
|
||||
|
||||
// similar method is in the sw_scripts/additional-scripts.js file
|
||||
|
||||
@@ -610,7 +610,7 @@ export default class Help extends Vue {
|
||||
async unsetFinishedOnboarding() {
|
||||
const settings = await retrieveSettingsForActiveAccount();
|
||||
if (settings.activeDid) {
|
||||
await updateAccountSettings(settings.activeDid || "", {
|
||||
await updateAccountSettings(settings.activeDid, {
|
||||
finishedOnboarding: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -539,7 +539,6 @@ export default class HomeView extends Vue {
|
||||
if (resp.status === 200) {
|
||||
await updateAccountSettings(this.activeDid, {
|
||||
isRegistered: true,
|
||||
apiServer: "",
|
||||
});
|
||||
this.isRegistered = true;
|
||||
}
|
||||
|
||||
@@ -92,8 +92,10 @@ test('Add contact, record gift, confirm gift', async ({ page }) => {
|
||||
await page.goto('./contacts');
|
||||
await page.getByPlaceholder('URL or DID, Name, Public Key').fill('did:ethr:0x0000694B58C2cC69658993A90D3840C560f2F51F, ' + userName);
|
||||
await page.locator('button > svg.fa-plus').click();
|
||||
// This should not be visible because user #1 is not registered, but firefox is getting the logic wrong somehow.
|
||||
// await expect(page.locator('div[role="alert"] span:has-text("No")')).toBeVisible();
|
||||
// await page.locator('div[role="alert"] button:has-text("No")').click();
|
||||
await expect(page.locator('div[role="alert"] span:has-text("Contact Added")')).toBeVisible();
|
||||
await page.locator('div[role="alert"] button:has-text("No")').click(); // don't register
|
||||
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert
|
||||
await expect(page.locator('div[role="alert"] button > svg.fa-xmark')).toBeHidden(); // ensure alert is gone
|
||||
|
||||
@@ -187,7 +189,9 @@ test('Add contact, copy details, delete, and import from paste & from file', asy
|
||||
await page.getByPlaceholder('URL or DID, Name, Public Key').fill('did:ethr:0x111d15564f824D56C7a07b913aA7aDd03382aA39, User #111');
|
||||
await page.locator('button > svg.fa-plus').click();
|
||||
await expect(page.locator('div[role="alert"]')).toBeVisible();
|
||||
await expect(page.locator('div[role="alert"] span:has-text("No")')).toBeVisible();
|
||||
await page.locator('div[role="alert"] button:has-text("No")').click(); // don't register
|
||||
await expect(page.locator('div[role="alert"] span:has-text("Contact Added")')).toBeVisible();
|
||||
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert
|
||||
// wait for the alert to disappear
|
||||
await expect(page.locator('div[role="alert"]')).toBeHidden();
|
||||
@@ -196,7 +200,9 @@ test('Add contact, copy details, delete, and import from paste & from file', asy
|
||||
await page.getByPlaceholder('URL or DID, Name, Public Key').fill('did:ethr:0x222BB77E6Ff3774d34c751f3c1260866357B677b, User #222, asdf1234');
|
||||
await page.locator('button > svg.fa-plus').click();
|
||||
await expect(page.locator('div[role="alert"]')).toBeVisible();
|
||||
await expect(page.locator('div[role="alert"] span:has-text("No")')).toBeVisible();
|
||||
await page.locator('div[role="alert"] button:has-text("No")').click(); // don't register
|
||||
await expect(page.locator('div[role="alert"] span:has-text("Contact Added")')).toBeVisible();
|
||||
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert
|
||||
await expect(page.locator('div[role="alert"]')).toBeHidden();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user