@@ -219,6 +219,10 @@ const stayAnonymousCheckbox = '.e2e-test-stay-anonymous-checkbox';
219219const responseTextareaSelector = '.e2e-test-feedback-response-textarea' ;
220220const sendButtonSelector = '.e2e-test-oppia-feedback-response-send-btn' ;
221221const errorSavingExplorationModal = '.e2e-test-discard-lost-changes-button' ;
222+ const totalPlaysSelector = '.e2e-test-oppia-total-plays' ;
223+ const numberOfOpenFeedbacksSelector = '.e2e-test-oppia-open-feedback' ;
224+ const avarageRatingSelector = '.e2e-test-oppia-average-rating' ;
225+ const usersCountInRatingSelector = '.e2e-test-oppia-total-users' ;
222226
223227const LABEL_FOR_SAVE_DESTINATION_BUTTON = ' Save Destination ' ;
224228export class ExplorationEditor extends BaseUser {
@@ -1706,14 +1710,18 @@ export class ExplorationEditor extends BaseUser {
17061710
17071711 /**
17081712 * Function for creating an exploration with only EndExploration interaction with given title.
1713+ * @param {boolean } flag - Determines whether to dismiss the welcome modal.
17091714 */
17101715 async createAndPublishAMinimalExplorationWithTitle (
17111716 title : string ,
1712- category : string = 'Algebra'
1717+ category : string = 'Algebra' ,
1718+ flag : boolean = true
17131719 ) : Promise < string | null > {
17141720 await this . navigateToCreatorDashboardPage ( ) ;
17151721 await this . navigateToExplorationEditorPage ( ) ;
1716- await this . dismissWelcomeModal ( ) ;
1722+ if ( flag ) {
1723+ await this . dismissWelcomeModal ( ) ;
1724+ }
17171725 await this . createMinimalExploration (
17181726 'Exploration intro text' ,
17191727 'End Exploration'
@@ -2058,6 +2066,145 @@ export class ExplorationEditor extends BaseUser {
20582066 await this . waitForNetworkIdle ( ) ;
20592067 }
20602068
2069+ /**
2070+ * Function to create and save a new untitled exploration containing only the EndExploration interaction.
2071+ */
2072+ async createAndSaveAMinimalExploration ( ) : Promise < void > {
2073+ await this . navigateToCreatorDashboardPage ( ) ;
2074+ await this . navigateToExplorationEditorPage ( ) ;
2075+ await this . createMinimalExploration (
2076+ 'Exploration intro text' ,
2077+ 'End Exploration'
2078+ ) ;
2079+ await this . saveExplorationDraft ( ) ;
2080+ }
2081+
2082+ /**
2083+ * Function to verify the average rating and the number of users who submitted ratings.
2084+ * @param {number } expectedRating - The expected average rating.
2085+ * @param {number } expectedUsers - The expected count of users who submitted ratings.
2086+ */
2087+ async expectAverageRatingAndUsersToBe (
2088+ expectedRating : number ,
2089+ expectedUsers : number
2090+ ) : Promise < void > {
2091+ await this . page . waitForSelector ( avarageRatingSelector , {
2092+ visible : true ,
2093+ } ) ;
2094+ const avarageRating = await this . page . $eval (
2095+ avarageRatingSelector ,
2096+ element => parseFloat ( ( element as HTMLElement ) . innerText . trim ( ) )
2097+ ) ;
2098+ if ( avarageRating !== expectedRating ) {
2099+ throw new Error (
2100+ `Expected average rating to be ${ expectedRating } , but found ${ avarageRating } .`
2101+ ) ;
2102+ }
2103+ const totalUsersText = await this . page . $eval (
2104+ usersCountInRatingSelector ,
2105+ el => ( el as HTMLElement ) . innerText . trim ( ) || ''
2106+ ) ;
2107+ // Extract number from text (e.g., "by 3 users" → 3).
2108+ const totalUsersMatch = totalUsersText . match ( / \d + / ) ;
2109+ const totalUsers = totalUsersMatch ? parseInt ( totalUsersMatch [ 0 ] , 10 ) : 0 ;
2110+ if ( totalUsers !== expectedUsers ) {
2111+ throw new Error (
2112+ `Expected ${ expectedUsers } users to have submitted ratings, but found only ${ totalUsers } instead.`
2113+ ) ;
2114+ }
2115+ }
2116+
2117+ /**
2118+ * Function to check the expected number of open feedback entries.
2119+ * @param {number } number - The expected count of open feedback entries.
2120+ */
2121+ async expectOpenFeedbacksToBe ( number : number ) : Promise < void > {
2122+ await this . page . waitForSelector ( numberOfOpenFeedbacksSelector , {
2123+ visible : true ,
2124+ } ) ;
2125+ const numberOfOpenFeedbacks = await this . page . $eval (
2126+ numberOfOpenFeedbacksSelector ,
2127+ el => parseInt ( ( el as HTMLElement ) . innerText . trim ( ) , 10 )
2128+ ) ;
2129+ if ( numberOfOpenFeedbacks !== number ) {
2130+ throw new Error (
2131+ `Expected open feedback count to be ${ number } , but found ${ numberOfOpenFeedbacks } .`
2132+ ) ;
2133+ }
2134+ }
2135+
2136+ /**
2137+ * Function to check the expected total number of plays."
2138+ * @param {number } number - The expected total play count.
2139+ */
2140+ async expectTotalPlaysToBe ( number : number ) : Promise < void > {
2141+ await this . page . waitForSelector ( totalPlaysSelector , {
2142+ visible : true ,
2143+ } ) ;
2144+ const numberOfTotalPlays = await this . page . $eval ( totalPlaysSelector , el =>
2145+ parseInt ( ( el as HTMLElement ) . innerText . trim ( ) , 10 )
2146+ ) ;
2147+ if ( numberOfTotalPlays !== number ) {
2148+ throw new Error (
2149+ `Expected total plays count to be ${ number } , but found ${ numberOfTotalPlays } .`
2150+ ) ;
2151+ }
2152+ }
2153+
2154+ /**
2155+ * Function to check the expected total number of explorations.
2156+ * @param {number } number - The expected count of total explorations.
2157+ */
2158+ async expectNumberOfExplorationsToBe ( number : number ) : Promise < void > {
2159+ await this . page . waitForSelector ( explorationSummaryTileTitleSelector , {
2160+ visible : true ,
2161+ } ) ;
2162+ const titlesOnPage = await this . page . $$eval (
2163+ explorationSummaryTileTitleSelector ,
2164+ elements => elements . map ( el => el . textContent ?. trim ( ) || '' )
2165+ ) ;
2166+ const count = titlesOnPage . length ;
2167+
2168+ if ( count !== number ) {
2169+ throw new Error (
2170+ `Expected ${ number } explorations, but found ${ count } instead.`
2171+ ) ;
2172+ }
2173+ }
2174+
2175+ /**
2176+ * Function to check the presence and expected number of occurrences of an exploration.
2177+ * @param {string } explorationName - The name of the exploration.
2178+ * @param {number } numberOfOccurrence - The expected occurrence count of the exploration.
2179+ */
2180+ async expectExplorationNameToAppearNTimes (
2181+ explorationName : string ,
2182+ numberOfOccurrence : number = 1
2183+ ) : Promise < void > {
2184+ await this . page . waitForSelector ( explorationSummaryTileTitleSelector , {
2185+ visible : true ,
2186+ } ) ;
2187+
2188+ // Extract all exploration titles.
2189+ const titlesOnPage = await this . page . $$eval (
2190+ explorationSummaryTileTitleSelector ,
2191+ elements => elements . map ( el => el . textContent ?. trim ( ) || '' )
2192+ ) ;
2193+
2194+ // Count occurrences of the target exploration.
2195+ const count = titlesOnPage . filter (
2196+ title => title === explorationName
2197+ ) . length ;
2198+
2199+ if ( numberOfOccurrence === 1 && count !== numberOfOccurrence ) {
2200+ throw new Error ( `Exploration "${ explorationName } " not found.` ) ;
2201+ } else if ( count !== numberOfOccurrence ) {
2202+ throw new Error (
2203+ `Exploration "${ explorationName } " found ${ count } times, but expected ${ numberOfOccurrence } times.`
2204+ ) ;
2205+ }
2206+ }
2207+
20612208 /**
20622209 * Opens an exploration in the editor.
20632210 * @param {string } explorationName - The name of the exploration.
0 commit comments