Refactor logging and clean up unused console statements across multiple files

This commit is contained in:
mohamad 2025-06-07 17:02:19 +02:00
parent d6c7fde40c
commit 397cf28673
6 changed files with 33 additions and 54 deletions

View File

@ -34,7 +34,7 @@ test.beforeAll(async ({ browser }) => {
await page.locator('form button[type="submit"]:has-text("Login")').click();
await page.waitForURL(new RegExp(`${BASE_URL}/(chores|groups|dashboard)?/?$`));
await page.context().storageState({ path: `e2e/.auth/list-user-${process.env.PLAYWRIGHT_WORKER_INDEX || 0}.json` });
// After login, ensure the target group exists or create it.
// For simplicity, we'll assume groups.spec.ts created a group.
// We need its name. A robust way is to query the API or have a fixed test group.
@ -46,15 +46,14 @@ test.beforeAll(async ({ browser }) => {
await page.goto(`${BASE_URL}/groups`);
const firstGroupCard = page.locator('.neo-group-card h1.neo-group-header').first();
if (await firstGroupCard.isVisible()) {
const name = await firstGroupCard.textContent();
if (name) groupNameForListTests = name.trim();
else console.warn("Could not determine group name for list tests, using default or generated.");
const name = await firstGroupCard.textContent();
if (name) groupNameForListTests = name.trim();
else console.warn("Could not determine group name for list tests, using default or generated.");
} else {
console.warn("No groups found for list tests, creating a new one might be needed or tests will fail.");
// If no groups, these tests might not be able to proceed correctly.
// For now, we'll assume `groupNameForListTests` is somewhat valid or will be set.
console.warn("No groups found for list tests, creating a new one might be needed or tests will fail.");
// If no groups, these tests might not be able to proceed correctly.
// For now, we'll assume `groupNameForListTests` is somewhat valid or will be set.
}
console.log(`Using group: "${groupNameForListTests}" for list tests.`);
await page.close();
});
@ -124,7 +123,7 @@ test('2. View a List and its (empty) items', async ({ page }) => {
const groupCard = page.locator(`.neo-group-card:has-text("${groupNameForListTests}")`);
await groupCard.click();
await page.waitForURL(new RegExp(`${BASE_URL}/groups/\\d+`));
const listLink = page.locator(`.list-card-link:has-text("${createdListName}"), .list-group-item:has-text("${createdListName}")`).first();
await listLink.click();
await page.waitForURL(new RegExp(`${BASE_URL}/groups/\\d+/lists/${createdListId}`));
@ -168,7 +167,7 @@ test('3. Add an Item to a List', async ({ page }) => {
test('4. Mark an Item as Completed', async ({ page }) => {
expect(createdListId).toBeTruthy();
expect(createdListName).toBeTruthy();
// Navigate to the list detail page
await page.goto(`${BASE_URL}/groups`);
await page.locator(`.neo-group-card:has-text("${groupNameForListTests}")`).click();
@ -180,7 +179,7 @@ test('4. Mark an Item as Completed', async ({ page }) => {
const firstItem = page.locator('.neo-item').first();
const itemNameElement = firstItem.locator('.neo-item-name');
const itemName = await itemNameElement.textContent(); // Get name for confirmation dialog
const checkbox = firstItem.locator('input[type="checkbox"]');
await checkbox.check(); // This will trigger @change which calls confirmUpdateItem
@ -188,7 +187,7 @@ test('4. Mark an Item as Completed', async ({ page }) => {
await expect(page.locator('.modal-container.confirm-modal')).toBeVisible();
await expect(page.locator('.modal-body')).toContainText(`Mark "${itemName}" as complete?`);
await page.locator('.modal-footer button:has-text("Confirm")').click();
// Verify the item's appearance changes (e.g., strikethrough, class 'neo-item-complete')
await expect(firstItem).toHaveClass(/neo-item-complete/);
// Also check if checkbox is now checked (it should be due to optimistic update + confirmation)

View File

@ -308,16 +308,13 @@ const selectGroup = (group: Group) => {
};
const openCreateListDialog = (group: Group) => {
console.log('Opening create list dialog for group:', group);
// Ensure we have the latest groups data
fetchGroups().then(() => {
console.log('Setting up modal with group:', group);
availableGroupsForModal.value = [{
label: group.name,
value: group.id
}];
showCreateListModal.value = true;
console.log('Modal should be visible now:', showCreateListModal.value);
});
};

View File

@ -59,15 +59,6 @@ const authStore = useAuthStore();
const notificationStore = useNotificationStore();
const { t, locale, messages } = useI18n();
// Debug output
console.log('=== i18n Debug Info ===');
console.log('Current locale:', locale.value);
console.log('Available messages:', messages.value);
console.log('English messages:', messages.value.en);
console.log('LoginPage messages:', messages.value.en?.loginPage);
console.log('Test translation:', t('loginPage.emailLabel'));
console.log('Test fallback:', t('message.hello'));
const email = ref('');
const password = ref('');
const isPwdVisible = ref(false);

View File

@ -57,25 +57,20 @@ export const useAuthStore = defineStore('auth', () => {
const fetchCurrentUser = async () => {
if (!accessToken.value) {
console.log('No access token found, clearing tokens')
clearTokens()
return null
}
try {
console.log('Fetching current user profile...')
const response = await api.get(API_ENDPOINTS.USERS.PROFILE)
console.log('User profile fetched:', response.data)
setUser(response.data)
return response.data
} catch (error: any) {
console.error('AuthStore: Failed to fetch current user:', error)
clearTokens()
return null
}
}
const login = async (email: string, password: string) => {
console.log('Attempting login...')
const formData = new FormData()
formData.append('username', email)
formData.append('password', password)
@ -86,10 +81,8 @@ export const useAuthStore = defineStore('auth', () => {
},
})
console.log('Login successful, setting tokens...')
const { access_token, refresh_token } = response.data
setTokens({ access_token, refresh_token })
// Fetch profile data after login
await fetchCurrentUser()
return response.data
}

View File

@ -70,7 +70,6 @@ export const useListDetailStore = defineStore('listDetail', {
// Call the actual API endpoint using generic post method
const endpoint = `/financials/expense_splits/${payload.expense_split_id}/settle`
const response = await apiClient.post(endpoint, payload.activity_data)
console.log('Settlement activity created:', response.data)
// Refresh list data to show updated statuses
if (payload.list_id_for_refetch) {
@ -111,31 +110,31 @@ export const useListDetailStore = defineStore('listDetail', {
},
getPaidAmountForSplit:
(state: ListDetailState) =>
(splitId: number): number => {
let totalPaid = 0
if (state.currentList && state.currentList.expenses) {
for (const expense of state.currentList.expenses) {
const split = expense.splits.find((s) => s.id === splitId)
if (split && split.settlement_activities) {
totalPaid = split.settlement_activities.reduce((sum, activity) => {
return sum + parseFloat(activity.amount_paid)
}, 0)
break
(splitId: number): number => {
let totalPaid = 0
if (state.currentList && state.currentList.expenses) {
for (const expense of state.currentList.expenses) {
const split = expense.splits.find((s) => s.id === splitId)
if (split && split.settlement_activities) {
totalPaid = split.settlement_activities.reduce((sum, activity) => {
return sum + parseFloat(activity.amount_paid)
}, 0)
break
}
}
}
}
return totalPaid
},
return totalPaid
},
getExpenseSplitById:
(state: ListDetailState) =>
(splitId: number): ExpenseSplit | undefined => {
if (!state.currentList || !state.currentList.expenses) return undefined
for (const expense of state.currentList.expenses) {
const split = expense.splits.find((s) => s.id === splitId)
if (split) return split
}
return undefined
},
(splitId: number): ExpenseSplit | undefined => {
if (!state.currentList || !state.currentList.expenses) return undefined
for (const expense of state.currentList.expenses) {
const split = expense.splits.find((s) => s.id === splitId)
if (split) return split
}
return undefined
},
},
})

View File

@ -33,7 +33,7 @@ const initializeSW = async () => {
try {
await self.skipWaiting();
clientsClaim();
console.log('Service Worker initialized successfully');
// console.log('Service Worker initialized successfully');
} catch (error) {
console.error('Error during service worker initialization:', error);
}