feat: convert Codeally test to Playwright (#54876)

This commit is contained in:
Sem Bauke
2024-05-23 01:52:50 +02:00
committed by GitHub
parent aae96b3af9
commit 61ce96ecfd
3 changed files with 47 additions and 40 deletions

View File

@@ -158,4 +158,4 @@ jobs:
config: baseUrl=http://localhost:8000
browser: ${{ matrix.browsers }}
# Only run one test to keep the run time down.
spec: 'cypress/e2e/default/learn/challenges/codeally.ts'
spec: 'cypress/e2e/default/learn/redirects/es6-to-basic-javascript.ts'

View File

@@ -1,39 +0,0 @@
describe('CodeAlly cert challenge', function () {
describe('before completing the project', function () {
before(() => {
cy.task('seed');
cy.login();
cy.visit(
'/learn/relational-database/build-a-celestial-bodies-database-project/build-a-celestial-bodies-database'
);
});
it('should not allow you to submit a URL', function () {
cy.get('input[name="solution"]')
.type('https://example.com')
.type('{enter}');
cy.contains('You must complete the project first.');
});
});
describe('after completing the project', function () {
before(() => {
cy.task('seed', ['certified-user']);
cy.login('certified-user');
cy.visit(
'/learn/relational-database/build-a-celestial-bodies-database-project/build-a-celestial-bodies-database'
);
});
it('should allow you to submit a URL', function () {
cy.get('input[name="solution"]')
.type('https://example.com')
.type('{enter}');
cy.get('div[role="dialog"]')
.contains('Submit and go to next challenge')
.should('be.visible');
});
});
});

46
e2e/codeally.spec.ts Normal file
View File

@@ -0,0 +1,46 @@
import { execSync } from 'child_process';
import { test, expect } from '@playwright/test';
test.describe('Before completing the project', () => {
test.use({ storageState: 'playwright/.auth/development-user.json' });
test.beforeEach(() => {
execSync('node ./tools/scripts/seed/seed-demo-user --donor');
});
test('should not allow you to submit a URL', async ({ page }) => {
await page.goto(
'/learn/relational-database/build-a-celestial-bodies-database-project/build-a-celestial-bodies-database'
);
await page
.getByRole('textbox', { name: 'solution' })
.fill('https://example.com');
await page.getByRole('textbox', { name: 'solution' }).press('Enter');
await expect(page.getByTestId('flash-message')).toContainText(
/You must complete the project first./
);
});
});
test.describe('After completing the project', () => {
test.use({ storageState: 'playwright/.auth/certified-user.json' });
test.beforeAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
});
test('should allow you to submit a URL', async ({ page }) => {
await page.goto(
'/learn/relational-database/build-a-celestial-bodies-database-project/build-a-celestial-bodies-database'
);
await page
.getByRole('textbox', { name: 'solution' })
.fill('https://example.com');
await page.getByRole('textbox', { name: 'solution' }).press('Enter');
await expect(page.getByRole('dialog')).toBeVisible();
await expect(page.getByRole('dialog')).toContainText(
'Submit and go to next challenge'
);
});
});