Skip to content

Commit

Permalink
e2e: campaign application admin and giver specs (#1951)
Browse files Browse the repository at this point in the history
* e2e: campaign application admin and giver specs

- add logic for admin or giver user login (see fixtures.ts)
- add logic to get a localized text for the e2e tests
- test edit a campaign application from admin UI
- test create a campaign application from general user UI

* fix: failing e2e test due to data differences

- locally and remotely the data of the current user (/me) and the types of campaigns (/campaign-types) causes the e2e tests to fail
- hence the need to mock the data for these 2 requests (like the the other e2e tests) to have a stable user experience tests
  • Loading branch information
gparlakov authored Oct 15, 2024
1 parent 3e2dc20 commit 2474556
Show file tree
Hide file tree
Showing 9 changed files with 462 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import {
CampaignApplicationResponse,
CampaignApplicationExisting,
CampaignApplicationAdminResponse,
} from '../../../../src/gql/campaign-applications'
import { Page } from 'playwright/test'
import { expect, adminTest as test } from '../../../utils/fixtures'
import { textLocalized } from '../../../utils/texts-localized'

test.describe('Campaign application admin', () => {
test('should see list of applications', async ({ page, baseURL }) => {
// arrange
const { paginationFooter } = await setup(page)
.withCampaignApplications([
{ id: '1', state: 'review' },
{ id: '2', state: 'approved' },
{ id: '3', state: 'denied' },
{ id: '4', state: 'forCommitteeReview' },
{ id: '5' },
])
.build()

// act
await page.goto(`${baseURL}/admin/campaign-applications`)

// assert
const t = await textLocalized().campaign.bg()
await expect(page.getByRole('heading')).toHaveText(t.admin.title)
await expect(page.getByRole('row')).toHaveCount(6) // title + 5 campaigns
await expect(page.getByRole('row').nth(1)).toContainText(t.status.review)
await expect(page.getByRole('row').nth(2)).toContainText(t.status.approved)
await expect(page.getByRole('row').nth(3)).toContainText(t.status.denied)
await expect(page.getByRole('row').nth(4)).toContainText(t.status.forCommitteeReview)
await expect(page.getByRole('row').nth(5)).toContainText(t.status.requestInfo)
await expect(paginationFooter(page)).toHaveText('Rows per page:1001–5 of 5')
})

test('should open a campaign application for edit', async ({ page, baseURL }) => {
// arrange
await setup(page).withEditCampaignApplication({}).build()

// act
await page.goto(`${baseURL}/admin/campaign-applications/edit/1234`)

// assert
const t = await textLocalized().campaign.bg()
await expect(page.getByRole('heading').first()).toHaveText(t.admin.title)
await expect(page.getByRole('heading').nth(1)).toHaveText(t.steps.admin.title)
})

test('should update status of campaign application to approved, archive it, and set the external link', async ({
page,
baseURL,
}) => {
// arrange
await setup(page).withEditCampaignApplication({ id: '1234', state: 'review' }).build()
await page.goto(`${baseURL}/admin/campaign-applications/edit/1234`)
const t = await textLocalized().campaign.bg()

// act
await page.getByLabel(t.steps.admin.status).click()
await page.getByText(t.status.approved).click()

const [req] = await Promise.all([
page.waitForRequest(/campaign-application\/1234/),
page.getByRole('button', { name: t.result.editButton }).click(),
])

// assert
const postData = req.postDataJSON()
expect(postData.state).toEqual('approved')
expect(page.getByText(t.result.edited)).toBeInViewport()
})
})

function setup(page: Page) {
const promises: Promise<unknown>[] = []

const builder = {
withCampaignApplications(cams: Array<Partial<CampaignApplicationResponse>>) {
promises.push(
page.route('*/**/api/v1/campaign-application/list', (route, req) => {
return route.fulfill({
json: cams.map((c) => ({ ...defaultCampaignApplication(), ...c })),
})
}),
)
return builder
},

withEditCampaignApplication(c: Partial<CampaignApplicationExisting>) {
promises.push(
page.route('*/**/api/v1/campaign-application/byId/*', (route, req) => {
return route.fulfill({
json: { ...camAppForEdit(), ...c },
})
}),
page.route(`*/**/api/v1/campaign-application/${c.id}`, (r) => {
return r.fulfill({ json: { ...camAppForEdit(), ...c } })
}),
)
return builder
},

async build() {
await promises

const selectors = {
paginationFooter: (p: Page) => p.locator('.MuiDataGrid-footerContainer'),
}

return selectors
},
}

return builder
}

function defaultCampaignApplication(): CampaignApplicationAdminResponse {
return {
id: 'eb4347a2-c8b4-47f1-83e5-67457b20909c',
createdAt: '2024-09-13T09:26:50.909Z',
updatedAt: '2024-09-28T20:56:13.728Z',
organizerName: 'Giver Dev',
organizerEmail: '[email protected]',
organizerPhone: '+35928700500',
beneficiary: 'Bene',
organizerBeneficiaryRel: 'бене',
campaignName: 'Camp name',
goal: 'Целта на кампанията',
history: '',
amount: '1455',
description: '',
state: 'requestInfo',
campaignTypeId: 'c6ef0a79-11cf-4175-9f66-3cec940c9259',
ticketURL: 'https://trello.com/linkforthiscamapp',
archived: false,
campaignEnd: 'date',
campaignEndDate: '2025-09-30T00:00:00.000Z',
acceptTermsAndConditions: true,
transparencyTermsAccepted: true,
personalInformationProcessingAccepted: true,
}
}

function camAppForEdit(): CampaignApplicationExisting {
return {
id: 'eb4347a2-c8b4-47f1-83e5-67457b20909c',
organizerName: 'Giver Dev',
organizerEmail: '[email protected]',
organizerPhone: '+35928700500',
beneficiary: 'Bene',
organizerBeneficiaryRel: 'бене',
campaignName: 'Camp name',
goal: 'Целта на кампанията',
history: '',
amount: '1455',
description: '',
state: 'requestInfo',
campaignTypeId: 'c6ef0a79-11cf-4175-9f66-3cec940c9259',
ticketURL: 'https://trello.com/linkforthiscamapp',
archived: false,
campaignEnd: 'date',
campaignEndDate: '2025-09-30T00:00:00.000Z',
acceptTermsAndConditions: true,
transparencyTermsAccepted: true,
personalInformationProcessingAccepted: true,
documents: [],
}
}

This file was deleted.

Loading

0 comments on commit 2474556

Please sign in to comment.