Skip to content

Commit

Permalink
Don't use Promise.all unnecessarily
Browse files Browse the repository at this point in the history
  • Loading branch information
henrycatalinismith committed Feb 27, 2024
1 parent 8dc2578 commit aba1c20
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 68 deletions.
7 changes: 3 additions & 4 deletions integrationTesting/tests/organize/campaigns/list/list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ test.describe('Campaigns list page ', () => {
]);

const campaignCards = page.locator('data-testid=campaign-card');
await Promise.all([
page.goto(appUri + '/organize/1/projects'),
campaignCards.first().waitFor({ state: 'visible' }),
]);

await page.goto(appUri + '/organize/1/projects');
await campaignCards.first().waitFor({ state: 'visible' });

const numCampaignCards = await campaignCards.count();
expect(numCampaignCards).toEqual(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ test.describe('Journey instance detail page', () => {
`[aria-label=breadcrumb]:has-text("${ClarasOnboarding.title}")`
);

await Promise.all([
page.goto(appUri + '/organize/1/journeys/1/1'),
title.waitFor({ state: 'visible' }),
breadcrumbTitle.waitFor({ state: 'visible' }),
]);
await page.goto(appUri + '/organize/1/journeys/1/1');
await title.waitFor({ state: 'visible' });
await breadcrumbTitle.waitFor({ state: 'visible' });

const numTitles = await title.count();
const numBreadcrumbTitles = await breadcrumbTitle.count();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ test.describe('Journey instance details page', () => {
),
// Click close instance button
reopenButton.click(),
openStatus.waitFor({ state: 'visible' }),
]);

await openStatus.waitFor({ state: 'visible' });

// Check patch request has correct data
expect(
patchInstanceMock.log<ZetkinJourneyInstance>()[0].data?.closed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ test.describe('Journey instance detail page sidebar', () => {
const assignees = page.locator(
`[data-testid=ZetkinSection-assignees] [data-testid=JourneyPerson-${ClarasOnboarding.assignees[0].id}]`
);
await Promise.all([
page.goto(appUri + '/organize/1/journeys/1/1'),
assignees.first().waitFor({ state: 'visible' }),
]);

await page.goto(appUri + '/organize/1/journeys/1/1');
await assignees.first().waitFor({ state: 'visible' });

const numAssignees = await assignees.count();
expect(numAssignees).toEqual(1);
Expand Down Expand Up @@ -200,10 +199,9 @@ test.describe('Journey instance detail page sidebar', () => {
const subjects = page.locator(
`[data-testid=ZetkinSection-subjects] [data-testid=JourneyPerson-${ClarasOnboarding.subjects[0].id}]`
);
await Promise.all([
page.goto(appUri + '/organize/1/journeys/1/1'),
subjects.first().waitFor({ state: 'visible' }),
]);

await page.goto(appUri + '/organize/1/journeys/1/1');
await subjects.first().waitFor({ state: 'visible' });

const numSubjects = await subjects.count();
expect(numSubjects).toEqual(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ test.describe('Journey instance page Milestones tab', () => {
const journeyMilestoneCards = page.locator(
'data-testid=JourneyMilestoneCard'
);
await Promise.all([
page.goto(appUri + '/organize/1/journeys/1/1/milestones'),
journeyMilestoneCards.first().waitFor({ state: 'visible' }),
]);

await page.goto(appUri + '/organize/1/journeys/1/1/milestones');
await journeyMilestoneCards.first().waitFor({ state: 'visible' });

const numCards = await journeyMilestoneCards.count();
expect(numCards).toEqual(3);
Expand Down Expand Up @@ -97,16 +96,12 @@ test.describe('Journey instance page Milestones tab', () => {
);
const june24 = page.locator('button:has-text("24")');

await Promise.all([
page.goto(appUri + '/organize/1/journeys/1/1/milestones'),
datePicker.first().waitFor({ state: 'visible' }),
]);
await page.goto(appUri + '/organize/1/journeys/1/1/milestones');
await datePicker.first().waitFor({ state: 'visible' });

//Click datepicker in first JourneyMilestoneCard
await Promise.all([
datePicker.first().click(),
june24.waitFor({ state: 'visible' }),
]);
await datePicker.first().click();
await june24.waitFor({ state: 'visible' });

await Promise.all([
page.waitForResponse(
Expand Down
7 changes: 3 additions & 4 deletions integrationTesting/tests/organize/journeys/list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ test.describe('Journeys list page', () => {
]);

const journeyCards = page.locator('data-testid=journey-card');
await Promise.all([
page.goto(appUri + '/organize/1/journeys'),
journeyCards.first().waitFor({ state: 'visible' }),
]);

await page.goto(appUri + '/organize/1/journeys');
await journeyCards.first().waitFor({ state: 'visible' });

const numJourneysCards = await journeyCards.count();
expect(numJourneysCards).toEqual(2);
Expand Down
12 changes: 4 additions & 8 deletions integrationTesting/tests/organize/search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,11 @@ test.describe('Search', async () => {
const searchButton = page.locator('data-testid=SearchDialog-activator');
const searchField = page.locator('#SearchDialog-inputField');

await Promise.all([
page.goto(appUri + '/organize/1/projects/1'),
searchButton.waitFor({ state: 'visible' }),
]);
await page.goto(appUri + '/organize/1/projects/1');
await searchButton.waitFor({ state: 'visible' });

await Promise.all([
page.keyboard.press('/'),
searchField.waitFor({ state: 'visible' }),
]);
await page.keyboard.press('/');
await searchField.waitFor({ state: 'visible' });

const isVisible = await searchField.isVisible();
expect(isVisible).toBeTruthy();
Expand Down
6 changes: 2 additions & 4 deletions integrationTesting/tests/organize/tags/add.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ test.describe('Tag manager', () => {
const addTagButton = page.locator('text=Add tag');
const activist = page.locator('text=Activist');

await Promise.all([
page.goto(appUri + `/organize/1/people/${ClaraZetkin.id}`),
addTagButton.first().waitFor({ state: 'visible' }),
]);
page.goto(appUri + `/organize/1/people/${ClaraZetkin.id}`);
addTagButton.first().waitFor({ state: 'visible' });

await page.locator('text=Add tag').click();

Expand Down
12 changes: 4 additions & 8 deletions integrationTesting/tests/organize/tags/remove.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,11 @@ test.describe('Tags manager', () => {
const tagToDelete = page.locator(`text="${ActivistTag.title}"`);
const deleteButton = page.locator('[data-testid=TagChip-deleteButton]');

await Promise.all([
page.goto(appUri + `/organize/1/people/${ClaraZetkin.id}`),
tagToDelete.waitFor({ state: 'visible' }),
]);
await page.goto(appUri + `/organize/1/people/${ClaraZetkin.id}`);
await tagToDelete.waitFor({ state: 'visible' });

await Promise.all([
tagToDelete.hover(),
deleteButton.waitFor({ state: 'visible' }),
]);
await tagToDelete.hover();
await deleteButton.waitFor({ state: 'visible' });

await Promise.all([
page.waitForRequest((req) => req.method() == 'DELETE'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,9 @@ test.describe('Task detail page', () => {
);

const image = page.locator('data-testid=TaskPreviewSection-section >> img');
await Promise.all([
page.goto(appUri + '/organize/1/projects/1/calendar/tasks/1'),
image.waitFor({ state: 'visible' }),
]);

await page.goto(appUri + '/organize/1/projects/1/calendar/tasks/1');
await image.waitFor({ state: 'visible' });

await Promise.all([
page.waitForResponse((res) => res.request().method() == 'PATCH'),
Expand Down
10 changes: 4 additions & 6 deletions integrationTesting/tests/organize/views/detail/display.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ test.describe('View detail page', () => {
const clara = page.locator('main >> text=Clara');
const rosa = page.locator('main >> text=Rosa');

await Promise.all([
page.goto(appUri + '/organize/1/people/lists/1'),
members.first().waitFor({ state: 'visible' }),
clara.first().waitFor({ state: 'visible' }),
rosa.first().waitFor({ state: 'visible' }),
]);
await page.goto(appUri + '/organize/1/people/lists/1');
await members.first().waitFor({ state: 'visible' });
await clara.first().waitFor({ state: 'visible' });
await rosa.first().waitFor({ state: 'visible' });

const numMembers = await members.count();
const numClara = await clara.count();
Expand Down
6 changes: 2 additions & 4 deletions integrationTesting/tests/organize/views/list/display.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ test.describe('Views list page', () => {

const rows = page.locator('.MuiDataGrid-row');

await Promise.all([
page.goto(appUri + '/organize/1/people'),
rows.first().waitFor({ state: 'visible' }),
]);
await page.goto(appUri + '/organize/1/people');
await rows.first().waitFor({ state: 'visible' });

const numRows = await rows.count();
expect(numRows).toEqual(2);
Expand Down

0 comments on commit aba1c20

Please sign in to comment.