Compare commits

...

3 Commits

Author SHA1 Message Date
kolaente 4172da6911
fix(cypress): intercept and rewrite wrong api requests 2025-06-17 15:23:46 +02:00
kolaente fae70abd29
refactor 2025-06-16 16:40:36 +02:00
kolaente 8d026821e5
test: check avatar loading for all providers 2025-06-16 16:23:30 +02:00
2 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,46 @@
import { UserFactory, type UserAttributes } from '../../factories/user'
import { login } from '../../support/authenticateUser'
const avatarProviders = [
'initials',
'gravatar',
'marble',
'upload',
'ldap',
] as const
function createFakeUserWithAvatar(provider: string) {
const overrides: Partial<UserAttributes & {
avatar_provider?: string;
avatar_file_id?: number;
email?: string
}> = {
username: `user_${provider}`,
avatar_provider: provider,
}
if (provider === 'gravatar') {
overrides.email = `user_${provider}@example.com`
}
if (provider === 'upload' || provider === 'ldap') {
overrides.avatar_file_id = 1
}
return UserFactory.create(1, overrides)[0] as UserAttributes
}
describe('User avatars', () => {
avatarProviders.forEach(provider => {
it(`Shows the avatar image for ${provider}`, () => {
login(createFakeUserWithAvatar(provider))
cy.visit('/')
cy.get('.username-dropdown-trigger img.avatar')
.should('be.visible')
.and(($img) => {
expect($img[0].naturalWidth).to.be.greaterThan(0)
})
})
})
})

View File

@ -2,6 +2,18 @@
import './commands'
import '@4tw/cypress-drag-drop'
beforeEach(() => {
// More comprehensive intercept for all API requests to dev server
cy.intercept('GET', '**/api/v1/**', (req) => {
// If the request is going to the dev server, redirect to API server
if (req.url.includes('127.0.0.1:4173') || req.url.includes('localhost:4173')) {
const newUrl = req.url.replace(/https?:\/\/(127\.0\.0\.1|localhost):4173\/api\/v1/, Cypress.env('API_URL'))
console.log('Redirecting request from', req.url, 'to', newUrl)
req.url = newUrl
}
}).as('apiRequest')
})
// see https://github.com/cypress-io/cypress/issues/702#issuecomment-587127275
Cypress.on('window:before:load', (win) => {
// disable service workers