|
| 1 | +// Copyright 2024 The Oppia Authors. All Rights Reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +/** |
| 16 | + * @fileoverview Utility functions for exploration creator page if exploration creator |
| 17 | + */ |
| 18 | + |
| 19 | +import {BaseUser} from '../puppeteer-testing-utilities/puppeteer-utils'; |
| 20 | +import testConstants from '../puppeteer-testing-utilities/test-constants'; |
| 21 | + |
| 22 | +const creatorDashboardPage = testConstants.URLs.CreatorDashboard; |
| 23 | + |
| 24 | +const createExplorationButton = 'button.e2e-test-create-new-exploration-button'; |
| 25 | +const dismissWelcomeModalSelector = 'button.e2e-test-dismiss-welcome-modal'; |
| 26 | +const textStateEditSelector = 'div.e2e-test-state-edit-content'; |
| 27 | +const richTextAreaField = 'div.e2e-test-rte'; |
| 28 | +const saveContentButton = 'button.e2e-test-save-state-content'; |
| 29 | +const addInteractionButton = 'button.e2e-test-open-add-interaction-modal'; |
| 30 | +const interactionEndExplorationInputButton = |
| 31 | + 'div.e2e-test-interaction-tile-EndExploration'; |
| 32 | +const saveInteractionButton = 'button.e2e-test-save-interaction'; |
| 33 | +const saveChangesButton = 'button.e2e-test-save-changes'; |
| 34 | +const saveDraftButton = 'button.e2e-test-save-draft-button'; |
| 35 | + |
| 36 | +const publishExplorationButton = 'button.e2e-test-publish-exploration'; |
| 37 | +const explorationTitleInput = 'input.e2e-test-exploration-title-input-modal'; |
| 38 | +const explorationGoalInput = 'input.e2e-test-exploration-objective-input-modal'; |
| 39 | +const explorationCategoryDropdown = |
| 40 | + 'mat-form-field.e2e-test-exploration-category-metadata-modal'; |
| 41 | +const saveExplorationChangesButton = 'button.e2e-test-confirm-pre-publication'; |
| 42 | +const explorationConfirmPublishButton = 'button.e2e-test-confirm-publish'; |
| 43 | +const explorationIdElement = 'span.oppia-unique-progress-id'; |
| 44 | +const closeShareModalButton = 'button.e2e-test-share-publish-close'; |
| 45 | + |
| 46 | +const mobileNavToggelbutton = '.e2e-test-mobile-options'; |
| 47 | +const mobileChangesDropdown = '.e2e-test-mobile-changes-dropdown'; |
| 48 | +const mobileSaveChangesButton = |
| 49 | + 'button.e2e-test-save-changes-for-small-screens'; |
| 50 | +const mobilePublishButton = 'button.e2e-test-mobile-publish-button'; |
| 51 | + |
| 52 | +export class ExplorationEditor extends BaseUser { |
| 53 | + /** |
| 54 | + * Function to navigate to creator dashboard page |
| 55 | + */ |
| 56 | + async navigateToCreatorDashboardPage(): Promise<void> { |
| 57 | + await this.page.goto(creatorDashboardPage); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Function to navigate to exploration editor |
| 62 | + */ |
| 63 | + async navigateToExplorationEditorPage(): Promise<void> { |
| 64 | + await this.clickOn(createExplorationButton); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Function to create exploration with title |
| 69 | + * @param explorationTitle - title of the exploration |
| 70 | + */ |
| 71 | + async createExplorationWithTitle(explorationTitle: string): Promise<void> { |
| 72 | + await this.page.waitForFunction('document.readyState === "complete"'); |
| 73 | + await this.page.waitForSelector(textStateEditSelector, { |
| 74 | + visible: true, |
| 75 | + }); |
| 76 | + await this.clickOn(textStateEditSelector); |
| 77 | + await this.page.waitForSelector(richTextAreaField, {visible: true}); |
| 78 | + await this.type(richTextAreaField, `${explorationTitle}`); |
| 79 | + await this.clickOn(saveContentButton); |
| 80 | + |
| 81 | + await this.clickOn(addInteractionButton); |
| 82 | + await this.clickOn(interactionEndExplorationInputButton); |
| 83 | + await this.clickOn(saveInteractionButton); |
| 84 | + await this.page.waitForSelector('.customize-interaction-body-container', { |
| 85 | + hidden: true, |
| 86 | + }); |
| 87 | + |
| 88 | + if (this.isViewportAtMobileWidth()) { |
| 89 | + await this.clickOn(mobileNavToggelbutton); |
| 90 | + await this.clickOn(mobileSaveChangesButton); |
| 91 | + } else { |
| 92 | + await this.page.waitForSelector(`${saveChangesButton}:not([disabled])`); |
| 93 | + await this.clickOn(saveChangesButton); |
| 94 | + } |
| 95 | + |
| 96 | + await this.page.waitForFunction('document.readyState === "complete"'); |
| 97 | + await this.page.waitForSelector(saveDraftButton, {visible: true}); |
| 98 | + await this.clickOn(saveDraftButton); |
| 99 | + await this.page.waitForSelector(saveDraftButton, {hidden: true}); |
| 100 | + await this.page.waitForFunction('document.readyState === "complete"'); |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Function to publish exploration |
| 105 | + */ |
| 106 | + async publishExplorationWithTitle( |
| 107 | + explorationTitle: string |
| 108 | + ): Promise<string | null> { |
| 109 | + if (this.isViewportAtMobileWidth()) { |
| 110 | + await this.page.waitForSelector('.e2e-test-toast-message', { |
| 111 | + visible: true, |
| 112 | + }); |
| 113 | + await this.page.waitForSelector('.e2e-test-toast-message', { |
| 114 | + hidden: true, |
| 115 | + }); |
| 116 | + await this.clickOn(mobileChangesDropdown); |
| 117 | + await this.clickOn(mobilePublishButton); |
| 118 | + } else { |
| 119 | + await this.page.waitForSelector( |
| 120 | + `${publishExplorationButton}:not([disabled])` |
| 121 | + ); |
| 122 | + await this.clickOn(publishExplorationButton); |
| 123 | + } |
| 124 | + await this.clickOn(explorationTitleInput); |
| 125 | + await this.type(explorationTitleInput, `${explorationTitle}`); |
| 126 | + await this.clickOn(explorationGoalInput); |
| 127 | + await this.type(explorationGoalInput, `${explorationTitle}`); |
| 128 | + await this.clickOn(explorationCategoryDropdown); |
| 129 | + await this.clickOn('Algebra'); |
| 130 | + await this.clickOn(saveExplorationChangesButton); |
| 131 | + await this.clickOn(explorationConfirmPublishButton); |
| 132 | + await this.page.waitForSelector(explorationIdElement); |
| 133 | + const explorationIdUrl = await this.page.$eval( |
| 134 | + explorationIdElement, |
| 135 | + element => (element as HTMLElement).innerText |
| 136 | + ); |
| 137 | + const explorationId = explorationIdUrl.replace(/^.*\/explore\//, ''); |
| 138 | + |
| 139 | + await this.clickOn(closeShareModalButton); |
| 140 | + return explorationId; |
| 141 | + } |
| 142 | + |
| 143 | + /** |
| 144 | + * Function to dismiss welcome modal |
| 145 | + */ |
| 146 | + async dismissWelcomeModal(): Promise<void> { |
| 147 | + await this.page.waitForSelector(dismissWelcomeModalSelector, { |
| 148 | + visible: true, |
| 149 | + }); |
| 150 | + await this.clickOn(dismissWelcomeModalSelector); |
| 151 | + await this.page.waitForSelector(dismissWelcomeModalSelector, { |
| 152 | + hidden: true, |
| 153 | + }); |
| 154 | + } |
| 155 | +} |
| 156 | + |
| 157 | +export let ExplorationEditorFactory = (): ExplorationEditor => |
| 158 | + new ExplorationEditor(); |
0 commit comments