Skip to content

Commit

Permalink
added tests for printable list and the event participants list
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Ruf committed Jan 24, 2024
1 parent a3b8106 commit e79c1a4
Show file tree
Hide file tree
Showing 10 changed files with 364 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ tests/e2e/cypress/videos/
tests/e2e/cypress/screenshots/
test_ci_cypress.sh
tests/e2e/cypress/e2e/FillDBWithStuff.cy.ts
tests/e2e/cypress/downloads/result.pdf
34 changes: 34 additions & 0 deletions src/Mealz/MealBundle/Tests/Controller/EventControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,38 @@ public function testLeave(): void
$part = $partRepo->findOneBy(['event' => $eventPart->getId()]);
$this->assertNull($part);
}

public function testGetEventParticipants(): void
{
// Create an event and join it
$newEvent = $this->createEvent();
$this->persistAndFlushAll([$newEvent]);

$dayRepo = self::$container->get(DayRepository::class);

$criteria = new \Doctrine\Common\Collections\Criteria();
$criteria->where(\Doctrine\Common\Collections\Criteria::expr()->gt('lockParticipationDateTime', new DateTime()));

/** @var Day $day */
$day = $dayRepo->matching($criteria)->get(0);
$this->assertNotNull($day);

$eventParticipation = $this->createEventParticipation($day, $newEvent);

$date = $day->getDateTime()->format('Y-m-d') . '%20' . $day->getDateTime()->format('H:i:s');

// Verify no participants in new event
$this->client->request('GET', '/api/participations/event/' . $date);
$participants = json_decode($this->client->getResponse()->getContent());
$this->assertEquals(0, count($participants));

$this->client->request('POST', '/api/events/participation/' . $date);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());

$this->client->request('GET', '/api/participations/event/' . $date);
$participants = json_decode($this->client->getResponse()->getContent());

$this->assertEquals(1, count($participants));
$this->assertEquals('Meals, Kochomi', $participants[0]);
}
}
5 changes: 4 additions & 1 deletion src/Resources/src/views/PrintableList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
{{ t('printList.title') + dateString }}
</h1>
</div>
<div class="mb-20 px-4 sm:px-6 lg:px-8">
<div
class="mb-20 px-4 sm:px-6 lg:px-8"
data-cy="printTable"
>
<div class="mt-8 flex flex-col">
<div class="-mx-4 -my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="inline-block min-w-full py-2 align-middle md:px-6 lg:px-8">
Expand Down
26 changes: 26 additions & 0 deletions src/Resources/tests/unit/fixtures/combiDishes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"id": 5425,
"slug": "fish-so-juicy-sweat",
"titleDe": "Fish (so juicy sweat) DE",
"titleEn": "Fish (so juicy sweat)",
"descriptionDe": "Beschreibung - Fish (so juicy sweat) DE",
"descriptionEn": "Description - Fish (so juicy sweat)",
"categoryId": 1357,
"oneServingSize": false,
"parentId": null,
"variations": []
},
{
"id": 5430,
"slug": "innards-v2",
"titleDe": "Innards DE #v2",
"titleEn": "Innards #v2",
"descriptionDe": null,
"descriptionEn": null,
"categoryId": null,
"oneServingSize": false,
"parentId": 5424,
"variations": []
}
]
16 changes: 15 additions & 1 deletion src/Resources/tests/unit/stores/dishesStore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { beforeAll, beforeEach, describe, expect, it } from "@jest/globals";
import Dishes from "../fixtures/getDishes.json";
import Categories from "../fixtures/getCategories.json";
import { CreateDishDTO } from "@/api/postCreateDish";
import combiDishes from '../fixtures/combiDishes.json';

const dish1: Dish = {
id: 17,
Expand Down Expand Up @@ -53,6 +54,12 @@ const getMockedResponses = (method: string, url: string) => {
request: asyncFunc,
error: ref(false)
}
} else if (url.includes('api/participations/combi/') && /\S*api\/participations\/combi\/\d*$/.test(url) && method === 'GET') {
return {
response: ref<Dish[]>(combiDishes),
request: asyncFunc,
error: ref(false)
}
}
}

Expand All @@ -61,7 +68,7 @@ const getMockedResponses = (method: string, url: string) => {
useApi = jest.fn().mockImplementation((method: string, url: string) => getMockedResponses(method, url));

describe('Test dishesStore', () => {
const { resetState, filterState, DishesState, fetchDishes, setFilter, filteredDishes, updateDish, getDishBySlug, getDishArrayBySlugs } = useDishes();
const { resetState, filterState, DishesState, fetchDishes, setFilter, filteredDishes, updateDish, getDishBySlug, getDishArrayBySlugs, getCombiDishes } = useDishes();
const { fetchCategories } = useCategories();

beforeAll(async () => {
Expand Down Expand Up @@ -153,4 +160,11 @@ describe('Test dishesStore', () => {

expect(dishArrThree).toEqual(['testen']);
});

it('should return an array of dishes containing the dishes from the fixtures', async () => {
const dishes = await getCombiDishes(1234);

expect(dishes).toHaveLength(2);
expect(dishes).toEqual(combiDishes);
})
});
19 changes: 18 additions & 1 deletion src/Resources/tests/unit/stores/eventsStore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const testEvent: Event = {
public: false
}

const userStrings = ['Test, User', 'Another, Testuser', 'abcxyz, User123'];

const asyncFunc: () => Promise<void> = async () => {
new Promise(resolve => resolve(undefined));
};
Expand Down Expand Up @@ -40,6 +42,12 @@ const getMockedResponses = (method: string, url: string) => {
request: asyncFunc,
error: ref(false)
}
} else if (url.includes('api/participations/event/') && method === 'GET') {
return {
response: ref(userStrings),
request: asyncFunc,
error: ref(false)
}
}
}

Expand All @@ -48,7 +56,7 @@ const getMockedResponses = (method: string, url: string) => {
useApi = jest.fn().mockImplementation((method: string, url: string) => getMockedResponses(method, url));

describe('Test EventsStore', () => {
const { EventsState, fetchEvents, setFilter, filteredEvents, updateEvent, deleteEventWithSlug, getEventBySlug, resetState } = useEvents();
const { EventsState, fetchEvents, setFilter, filteredEvents, updateEvent, deleteEventWithSlug, getEventBySlug, resetState, getParticipantsForEvent } = useEvents();

beforeEach(() => {
resetState();
Expand Down Expand Up @@ -133,4 +141,13 @@ describe('Test EventsStore', () => {
expect(event).toBeUndefined();
expect(EventsState.events).toHaveLength(1);
});

it('should fetch all the users that participate in an event and return a list of their names', async () => {
const users = await getParticipantsForEvent('2024-01-24 12:00:00.000000');

expect(users).toHaveLength(3);
for (const user of userStrings) {
expect(users).toContain(user);
}
});
});
1 change: 1 addition & 0 deletions tests/e2e/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export default defineConfig({
viewportHeight: 800,
screenshotOnRunFailure: false,
video: false,
trashAssetsBeforeRuns: true
})
141 changes: 141 additions & 0 deletions tests/e2e/cypress/e2e/Dashboard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,145 @@ describe('Test Dashboard View', () => {
.children()
.should('have.length', 0);
});

it('should join an event and be in the participants list', () => {
cy.intercept('GET', '**/api/weeks').as('getWeeks');
cy.intercept('GET', '**/api/meals/count').as('getDishesCount');
cy.intercept('GET', '**/api/categories').as('getCategories');
cy.intercept('GET', '**/api/dishes').as('getDishes');
cy.intercept('GET', '**/api/events').as('getEvents');
cy.intercept('GET', '**/api/dashboard').as('getDashboard');
cy.intercept('GET', '**/api/participations/event/**').as('getParticipants');


cy.visitMeals();
cy.get('span > a').contains('Mahlzeiten').click();
cy.wait(['@getWeeks']);

// Go to the next week
cy.get('h4').eq(1).contains('Woche').click();
cy.wait(['@getDishesCount', '@getCategories', '@getDishes']);

// add an event on monday
cy.get('input')
.eq(2)
.click()
.parent().parent()
.find('li').contains('Afterwork')
.click();

cy.get('h2').should('contain', 'Woche').click();

// Save
cy.contains('input', 'Speichern').click();

cy.get('[data-cy="msgClose"]').click();

// find the saved event
cy.get('input')
.eq(2)
.should('have.value', 'Afterwork');

// go to dashboard
cy.get('header > nav > div > a > svg').click();
cy.wait(['@getDashboard', '@getEvents']);

// join afterwork
cy.get('h2')
.contains('Nächste Woche')
.parent()
.parent()
.find('span')
.contains('Montag')
.parent()
.parent()
.find('span')
.contains('Afterwork')
.parent()
.find('div')
.eq(3)
.click();

// click on the info-icon
cy.get('h2')
.contains('Nächste Woche')
.parent()
.parent()
.contains('Montag')
.parent()
.parent()
.find('span')
.contains('Afterwork')
.parent()
.find('svg')
.eq(0)
.click();

cy.wait('@getParticipants');

// verify participants on popup
cy.get('span')
.contains('Teilnahmen "Afterwork"')
.parent()
.parent()
.find('li')
.contains('Meals, Kochomi')
.parent()
.parent()
.find('span')
.contains('Es gibt 1 Teilnehmer')
.parent()
.parent()
.find('svg')
.click()

// leave afterwork
cy.get('h2')
.contains('Nächste Woche')
.parent()
.parent()
.find('span')
.contains('Montag')
.parent()
.parent()
.find('span')
.contains('Afterwork')
.parent()
.find('div')
.eq(3)
.click();

// click on the info-icon
cy.get('h2')
.contains('Nächste Woche')
.parent()
.parent()
.contains('Montag')
.parent()
.parent()
.find('span')
.contains('Afterwork')
.parent()
.find('svg')
.eq(0)
.click();

cy.wait('@getParticipants');

// verify no participants on popup
cy.get('span')
.contains('Teilnahmen "Afterwork"')
.parent()
.parent()
.find('span')
.contains('Noch keine Teilnehmer für dieses Event')
.parent()
.parent()
.find('span')
.contains('Es gibt 0 Teilnehmer')
.parent()
.parent()
.find('svg')
.click()
});
});
47 changes: 46 additions & 1 deletion tests/e2e/cypress/e2e/ParticipationList.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
describe('Test ParticipationsList view', () => {
import { find } from "cypress/types/lodash";

describe.skip('Test TV ParticipationsList view', () => {
beforeEach(() => {
cy.resetDB();
cy.setCookie('locale', 'de');
Expand All @@ -8,4 +10,47 @@ describe('Test ParticipationsList view', () => {
cy.viewport(1080, 1920);
cy.visit(Cypress.env('baseUrl') + 'show/participations');
});
});

describe('Test Print ParticipationList View', () => {
beforeEach(() => {
cy.resetDB();
cy.loginAs('kochomi');
cy.visitMeals();

cy.intercept('GET', '**/api/print/participations', { fixture: 'printParticipations.json', statusCode: 200 }).as('getParticipations');
});

it('should contain all the infos it received via the fixture', () => {
cy.contains('span', 'Heutige Teilnehmer').click();

cy.contains('h1', 'Teilnahmen am Mittwoch, 24.1.');

cy.get('[data-cy="printTable"]').find('tbody').find('tr').should('have.length', 10);
cy.contains('th', 'Active w/o limit');
cy.contains('th', 'Active w/ limit');
cy.get('[data-cy="printTable"]').find('tbody').find('tr').eq(1).contains('td', 'Meals, Admin');
cy.get('[data-cy="printTable"]').find('tbody').find('tr').eq(2).contains('td', 'Meals, Alice');
cy.get('[data-cy="printTable"]').find('tbody').find('tr').eq(3).contains('td', 'Meals, Bob');
cy.get('[data-cy="printTable"]').find('tbody').find('tr').eq(4).contains('td', 'Meals, Finance');
cy.get('[data-cy="printTable"]').find('tbody').find('tr').eq(5).contains('td', 'Meals, Jane');
cy.get('[data-cy="printTable"]').find('tbody').find('tr').eq(6).contains('td', 'Meals, Kochomi');
cy.get('[data-cy="printTable"]').find('tbody').find('tr').eq(8).contains('td', 'Meals, John');
cy.get('[data-cy="printTable"]').find('tbody').find('tr').eq(9).find('th').eq(0).contains('Teilnahmen');
cy.get('[data-cy="printTable"]').find('tbody').find('tr').eq(9).find('th').eq(1).contains('7');
cy.get('[data-cy="printTable"]').find('tbody').find('tr').eq(9).find('th').eq(2).contains('4');
cy.get('[data-cy="printTable"]').find('tbody').find('tr').eq(9).find('th').eq(3).contains('0');

cy.get('p').contains('Pdf downloaden');
});

it('should verify that a file is downloaded when clicking pdf download', () => {
cy.contains('span', 'Heutige Teilnehmer').click();

cy.contains('h1', 'Teilnahmen am Mittwoch, 24.1.');

cy.get('p').contains('Pdf downloaden').click();

cy.readFile('cypress/downloads/result.pdf', { timeout: 5000 });
});
});
Loading

0 comments on commit e79c1a4

Please sign in to comment.