fix(client) downloaded daily code challenge solution with filename (#64385)

This commit is contained in:
leputz
2026-03-10 16:15:37 +02:00
committed by GitHub
parent 8c3a89113a
commit d4161819cc
4 changed files with 50 additions and 2 deletions
+41 -1
View File
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { test, expect, type Page } from '@playwright/test';
import * as fs from 'fs';
import {
getTodayUsCentral,
formatDate,
@@ -65,6 +66,15 @@ const mockApiAllChallenges = [
const mockDaysInMonth = new Date(year, month, 0).getDate();
const runChallengeTest = async (page: Page, isMobile: boolean) => {
if (isMobile) {
await page.getByRole('tab', { name: 'Console' }).click();
await page.getByText('Run').click();
} else {
await page.getByText('Run the Tests (Ctrl + Enter)').click();
}
};
test.describe('Daily Coding Challenges', () => {
test('should redirect to archive for invalid date', async ({ page }) => {
await page.goto('/learn/daily-coding-challenge/invalid-date');
@@ -257,3 +267,33 @@ test.describe('Daily Coding Challenge Archive', () => {
);
});
});
test.describe('Daily code challenge solution can be downloaded', () => {
test('Downloaded solution files are named by challenge number', async ({
page,
isMobile
}) => {
await page.route(/.*\/daily-coding-challenge\/date\/.*/, async route => {
await route.fulfill({
status: 200,
headers: { 'Content-Type': 'application/json' },
json: mockApiChallenge
});
});
await page.goto(`/learn/daily-coding-challenge/${todayUsCentral}`);
await runChallengeTest(page, isMobile);
await expect(page.getByRole('dialog')).toBeVisible({ timeout: 15000 });
await expect(
page.getByRole('link', { name: 'Download my solution' })
).toBeVisible({ timeout: 15000 });
const [download] = await Promise.all([
page.waitForEvent('download'),
page.getByRole('link', { name: 'Download my solution' }).click()
]);
const suggestedFileName = download.suggestedFilename();
await download.saveAs(suggestedFileName);
expect(fs.existsSync(suggestedFileName)).toBeTruthy();
expect(suggestedFileName).toBe('challenge-1.txt');
});
});