Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace calls to navigateToVersion and expandTimeline where not necessary for tests #2233

Merged
merged 6 commits into from
Dec 2, 2024
Merged
39 changes: 1 addition & 38 deletions tests/page-objects/epp-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,10 @@ export class EppPage {
await this.page.goto(`${config.client_url}/reviewed-preprints/${this.name}-msidv1/reviews`);
}

async navigateToVersion(version: number, wait: boolean = false): Promise<void> {
await this.page.getByText(`v${version}`).locator('xpath=ancestor::dd[1]/preceding-sibling::*[1]//a').click();
if (wait) {
await this.page.waitForURL(`${config.client_url}/reviewed-preprints/${this.name}-msidv${version}`);
}
}

async navigateToReviewsTab(): Promise<void> {
const peerReviewTab = this.page.locator('.tabbed-navigation__tabs').getByText('Peer review');
await peerReviewTab.click();
expect(this.page.locator('.tabbed-navigation__tab-label--active')).toHaveText('Peer review');
await expect(this.page.locator('.tabbed-navigation__tab-label--active')).toHaveText('Peer review');
}

async reload() {
Expand All @@ -89,13 +82,6 @@ export class EppPage {
}).toPass();
}

async reloadAndAssertTimelineEvent(status: number): Promise<void> {
await expect(async () => {
const response = await this.reload();
expect(response?.status()).toBe(status);
}).toPass();
}

async assertTitleText(title: string): Promise<void> {
await expect(this.title).toContainText(title);
}
Expand Down Expand Up @@ -147,24 +133,6 @@ export class EppPage {
await expect(this.articleStatus).toContainText(content);
}

async expandTimeline(): Promise<void> {
const countVisibleEvents = async () => {
const events = await this.page.locator('.review-timeline__event').elementHandles();
const visibleEvents = await Promise.all(events.map(async (event) => {
const display = await event.evaluate((node) => {
const el = node as Element;
return window.getComputedStyle(el).display;
});
return display !== 'none';
}));
return visibleEvents.filter((isVisible) => isVisible).length;
};

expect(await countVisibleEvents()).toBe(1);
await this.page.click('.review-timeline__expansion');
expect(await countVisibleEvents()).toBeGreaterThan(1);
}

async assertTimelineDetailText(index: number, content: string): Promise<void> {
await expect(this.page.locator(`.review-timeline__detail:nth-of-type(${index})`)).toContainText(content);
}
Expand All @@ -177,11 +145,6 @@ export class EppPage {
await expect(this.page.locator(`.review-timeline__event:nth-of-type(${index}) a`).getAttribute('href')).resolves.toEqual(url);
}

async assertTimelineEventThisVersion(index: number): Promise<void> {
const event = this.page.locator(`.review-timeline__detail:nth-of-type(${index})`);
await expect(event.locator('.review-timeline__link')).toContainText('revised', { ignoreCase: true });
}

async assertRelatedContent(index: number, type: string, title: string, url: string, content?: string): Promise<void> {
const relatedContentItem = this.page.locator(`.related-content>.related-content__item:nth-child(${index})`);
await expect(relatedContentItem.locator('.related-content__item-type')).toHaveText(type);
Expand Down
21 changes: 2 additions & 19 deletions tests/revised.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,17 @@ test.describe('revised preprint', () => {
await eppPage.assertDoi('https://doi.org/10.7554/000001.1');
await eppPage.assertTitleText('OpenApePose: a database of annotated ape photographs for pose estimation');

await eppPage.expandTimeline();

await eppPage.assertTimelineDetailText(2, 'v1');
await eppPage.assertTimelineEventThisVersion(2);

await eppPage.navigateToVersion(2, true);
await eppPage.gotoArticlePage({ version: 2 });
await eppPage.reloadAndAssertStatus(200);
await eppPage.assertTitleText('OpenApePose: a database of annotated ape photographs for pose estimation (revised)');
await eppPage.assertArticleStatusText('Revised by authors');
await eppPage.assertDoi('https://doi.org/10.7554/000001.2');

await eppPage.expandTimeline();

await eppPage.assertTimelineDetailText(1, 'v2');
await eppPage.assertTimelineEventThisVersion(1);

await eppPage.navigateToVersion(1, true);
await eppPage.assertDoi('https://doi.org/10.7554/000001.1');

await eppPage.gotoArticlePage({ status: 200 });
await eppPage.assertTitleText('OpenApePose: a database of annotated ape photographs for pose estimation (revised)');
await eppPage.assertArticleStatusText('Revised by authors');
await eppPage.assertDoi('https://doi.org/10.7554/000001.2');

await eppPage.expandTimeline();

await eppPage.assertTimelineDetailText(1, 'v2');
await eppPage.assertTimelineEventThisVersion(1);

await eppPage.navigateToReviewsTab();
await eppPage.assertPeerReviewProcess('revised');
});
Expand Down
47 changes: 11 additions & 36 deletions tests/versions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,60 +24,35 @@ test.describe('versions', () => {
// For the test to succeed, we need to wait for all versions to be imported
await eppPage.gotoArticlePage({ version: 4 });
await eppPage.reloadAndAssertStatus(200);
await eppPage.gotoArticlePage({ version: 3 });
await eppPage.reloadAndAssertStatus(200);
await eppPage.gotoArticlePage({ version: 2 });
await eppPage.reloadAndAssertStatus(200);
await eppPage.gotoArticlePage({ version: 1 });
await eppPage.reloadAndAssertStatus(200);

await eppPage.assertArticleStatusText('Not revised');
await eppPage.assertDoi('https://doi.org/10.7554/000001.1');
await eppPage.assertTitleText('OpenApePose: a database of annotated ape photographs for pose estimation');

await eppPage.expandTimeline();

await eppPage.assertTimelineDetailText(4, 'v1');
await eppPage.assertTimelineEventThisVersion(4);

await eppPage.navigateToVersion(2);
await eppPage.assertTitleText('OpenApePose: a database of annotated ape photographs for pose estimation (revised)');
await eppPage.assertArticleStatusText('Revised by authors');
await eppPage.assertDoi('https://doi.org/10.7554/000001.2');

await eppPage.expandTimeline();
await eppPage.assertDoi('https://doi.org/10.7554/000001.4');

await eppPage.assertTimelineDetailText(3, 'v2');
await eppPage.assertTimelineEventThisVersion(3);
await eppPage.gotoArticlePage({ version: 3 });
await eppPage.reloadAndAssertStatus(200);

await eppPage.navigateToVersion(3);
await eppPage.assertTitleText('OpenApePose: a database of annotated ape photographs for pose estimation (revised)');
await eppPage.assertArticleStatusText('Revised by authors');
await eppPage.assertDoi('https://doi.org/10.7554/000001.3');

await eppPage.expandTimeline();

await eppPage.assertTimelineDetailText(2, 'v3');
await eppPage.assertTimelineEventThisVersion(2);
await eppPage.gotoArticlePage({ version: 2 });

await eppPage.navigateToVersion(4);
await eppPage.reloadAndAssertStatus(200);
await eppPage.assertTitleText('OpenApePose: a database of annotated ape photographs for pose estimation (revised)');
await eppPage.assertArticleStatusText('Revised by authors');
await eppPage.assertDoi('https://doi.org/10.7554/000001.4');
await eppPage.assertDoi('https://doi.org/10.7554/000001.2');

await eppPage.expandTimeline();
await eppPage.gotoArticlePage({ version: 1 });
await eppPage.reloadAndAssertStatus(200);

await eppPage.assertTimelineDetailText(1, 'v4');
await eppPage.assertTimelineEventThisVersion(1);
await eppPage.assertArticleStatusText('Not revised');
await eppPage.assertDoi('https://doi.org/10.7554/000001.1');
await eppPage.assertTitleText('OpenApePose: a database of annotated ape photographs for pose estimation');

await eppPage.gotoArticlePage({ status: 200 });
await eppPage.assertTitleText('OpenApePose: a database of annotated ape photographs for pose estimation (revised)');
await eppPage.assertArticleStatusText('Revised by authors');
await eppPage.assertDoi('https://doi.org/10.7554/000001.4');

await eppPage.expandTimeline();

await eppPage.assertTimelineDetailText(1, 'v4');
await eppPage.assertTimelineEventThisVersion(1);
});
});