Skip to content

Commit

Permalink
[GSoC'24] M2.5: Add multiple classrooms acceptance test (oppia#20857)
Browse files Browse the repository at this point in the history
* Add multiple classrooms acceptance test

* fix module mapping

* fix module mapping

* add await

* minor change

* fix comment

* fix title, description

* fix title and description

* fix test
  • Loading branch information
AFZL210 authored Aug 25, 2024
1 parent 2fd4a85 commit cc1e654
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,38 @@
import {UserFactory} from '../../utilities/common/user-factory';
import testConstants from '../../utilities/common/test-constants';
import {LoggedOutUser} from '../../utilities/user/logged-out-user';
import {CurriculumAdmin} from '../../utilities/user/curriculum-admin';
import {ConsoleReporter} from '../../utilities/common/console-reporter';
import {ReleaseCoordinator} from '../../utilities/user/release-coordinator';

const DEFAULT_SPEC_TIMEOUT_MSECS = testConstants.DEFAULT_SPEC_TIMEOUT_MSECS;
const ROLES = testConstants.Roles;

ConsoleReporter.setConsoleErrorsToIgnore([
/http:\/\/localhost:8181\/access_validation_handler\/can_access_classrooms_page Failed to load resource: the server responded with a status of 404 \(Not Found\)/,
]);

describe('Logged-out User', function () {
let loggedOutUser: LoggedOutUser;
let curriculumAdmin: CurriculumAdmin;
let releaseCoordinator: ReleaseCoordinator;

beforeAll(async function () {
loggedOutUser = await UserFactory.createLoggedOutUser();
curriculumAdmin = await UserFactory.createNewUser(
'curriculumAdm',
'[email protected]',
[ROLES.CURRICULUM_ADMIN]
);
releaseCoordinator = await UserFactory.createNewUser(
'releaseCoordinator',
'[email protected]',
[ROLES.RELEASE_COORDINATOR]
);

await releaseCoordinator.enableFeatureFlag('enable_multiple_classrooms');
await curriculumAdmin.createTopic('Test Topic 2', 'test-topic-two');
await curriculumAdmin.createTopic('Test Topic 1', 'test-topic-one');
}, DEFAULT_SPEC_TIMEOUT_MSECS);

it(
Expand All @@ -44,8 +63,45 @@ describe('Logged-out User', function () {
DEFAULT_SPEC_TIMEOUT_MSECS
);

// TODO (#20610): Add test for one and more than one classroom.
// Once issue with relase coordinator user is fixed.
it(
'should be redirected to a classroom page if we have 1 public classroom.',
async function () {
await curriculumAdmin.navigateToTopicAndSkillsDashboardPage();
await curriculumAdmin.createNewClassroom('Math', 'math');
await curriculumAdmin.updateClassroom(
'Math',
'Welcome to Math classroom!',
'This course covers basic algebra and trigonometry.',
'In this course, you will learn the following topics: algbera and trigonometry,'
);
await curriculumAdmin.addTopicToClassroom('Math', 'Test Topic 1');
await curriculumAdmin.publishClassroom('Math');

await loggedOutUser.navigateToClassroomsPage();
await loggedOutUser.expectToBeOnClassroomPage('Math');
},
DEFAULT_SPEC_TIMEOUT_MSECS
);

it(
'should show classrooms page with classroom cards.',
async function () {
await curriculumAdmin.navigateToTopicAndSkillsDashboardPage();
await curriculumAdmin.createNewClassroom('Science', 'science');
await curriculumAdmin.updateClassroom(
'Science',
'Welcome to Science classroom!',
'This course covers basic physics and chemistry.',
'In this course, you will learn the following topics: physics and chemistry,'
);
await curriculumAdmin.addTopicToClassroom('Science', 'Test Topic 2');
await curriculumAdmin.publishClassroom('Science');

await loggedOutUser.navigateToClassroomsPage();
await loggedOutUser.expectClassroomCountInClassroomsPageToBe(2);
},
DEFAULT_SPEC_TIMEOUT_MSECS
);

afterAll(async function () {
await UserFactory.closeAllBrowsers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,7 @@ export class CurriculumAdmin extends BaseUser {
if (classroomTiles.length === 0) {
throw new Error('No classrooms are present.');
}

let foundClassroom = false;

for (let i = 0; i < classroomTiles.length; i++) {
Expand All @@ -1322,7 +1323,7 @@ export class CurriculumAdmin extends BaseUser {
);

if (currentClassroomName === classroomName) {
await this.clickOn(classroomTileSelector);
await classroomTiles[i].click();
await this.page.waitForSelector(editClassroomConfigButton);
await this.clickOn(editClassroomConfigButton);
await this.page.waitForSelector(closeClassroomConfigButton);
Expand All @@ -1333,7 +1334,7 @@ export class CurriculumAdmin extends BaseUser {
}

if (!foundClassroom) {
throw new Error(`${classroomName} classroom do not exists.`);
throw new Error(`${classroomName} classroom does not exist.`);
}
}

Expand All @@ -1360,8 +1361,8 @@ export class CurriculumAdmin extends BaseUser {
async updateClassroom(
classroomName: string,
teaserText: string,
courseDetails: string,
topicListIntro: string
topicListIntro: string,
courseDetails: string
): Promise<void> {
await this.navigateToClassroomAdminPage();
await this.editClassroom(classroomName);
Expand All @@ -1370,13 +1371,11 @@ export class CurriculumAdmin extends BaseUser {
await this.page.type(editClassroomTopicListIntroInputField, topicListIntro);
await this.page.type(editClassroomCourseDetailsInputField, courseDetails);
await this.clickOn(classroomThumbnailContainer);
await this.page.waitForSelector(imageUploaderModal, {visible: true});
await this.uploadFile(curriculumAdminThumbnailImage);
await this.page.waitForSelector(`${uploadPhotoButton}:not([disabled])`);
await this.clickOn(uploadPhotoButton);
await this.clickOn(uploadClassroomImageButton);
await this.page.waitForSelector(imageUploaderModal, {visible: false});

await this.page.waitForTimeout(2000);
await this.page.waitForSelector(photoUploadModal, {hidden: true});

await this.clickOn(classroomBannerContainer);
await this.page.waitForSelector(imageUploaderModal, {visible: true});
Expand Down Expand Up @@ -1560,9 +1559,9 @@ export class CurriculumAdmin extends BaseUser {
await this.createNewClassroom(classroomName, urlFragment);
await this.updateClassroom(
classroomName,
'Teaser text',
'Course details',
'Topic list intro'
'Welcome to Math classroom!',
'This course covers basic algebra and trigonometry.',
'In this course, you will learn the following topics: algbera and trigonometry,'
);
await this.addTopicToClassroom(classroomName, topicToBeAssigned);
await this.publishClassroom(classroomName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2298,6 +2298,27 @@ export class LoggedOutUser extends BaseUser {
);
}

/**
* This function verifies that the classroom cards are present in the classrooms page.
* @param {number} classroomsCount - The expected number of classrooms.
*/
async expectClassroomCountInClassroomsPageToBe(
classroomsCount: number
): Promise<void> {
await this.page.waitForSelector(classroomTileContainer);
const classroomTiles = await this.page.$$(classroomTileContainer);

if (classroomTiles.length === classroomsCount) {
showMessage(
`${classroomsCount} classrooms are present in classrooms page.`
);
} else {
throw new Error(
`Expect ${classroomsCount} classrooms to be present in classrooms page, found: ${classroomTiles.length} classrooms.`
);
}
}

/**
* This function changes the site language based on the provided parameter,
* then clicks the 'Partner With Us' button on the About page, and
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
core/templates/pages/classroom-admin-page/classroom-admin-page.module.ts
core/templates/pages/classroom-page/classroom-page.module.ts
core/templates/pages/classrooms-page/classrooms-page.module.ts
core/templates/pages/release-coordinator-page/release-coordinator-page.module.ts
core/templates/pages/topic-editor-page/topic-editor-page.import.ts
core/templates/pages/topics-and-skills-dashboard-page/topics-and-skills-dashboard-page.import.ts

0 comments on commit cc1e654

Please sign in to comment.