Repository: oppia/oppia
File: core/tests/puppeteer-acceptance-tests/utilities/user/logged-in-user.ts (TypeScript)

Code before:
      if (!lessonTitleText || lessonTitleText !== lessonTitle) {
        continue;
      }

      const resumeLessonButton = await lessonCard.$(resumeLessonButtonSelector);
      await resumeLessonButton?.click();

      await this.page.waitForSelector(resumeLessonButtonSelector, {
        hidden: true,
      });
      return;
    }
    throw new Error(`Lesson not found: ${lessonTitle}`);
  }

  /**
   * Checks if Learner is on the learner dashboard page.
   */
  async expectToBeOnLearnerDashboardPage(): Promise<void> {
    await this.page.waitForFunction(
      (url: string) => {
        return window.location.href.includes(url);
      },
      {},
      '/learner-dashboard'
    );
  }

  /**
   * Checks if greeting has name of the user.
   */
  async expectGreetingToHaveNameOfUser(userName: string): Promise<void> {
    // Check for redesigned dashboard greeting first.
    const redesignedGreetingElement = await this.page.$(
      learnerGreetingsSelector
    );
    if (redesignedGreetingElement) {
      await this.page.waitForSelector(learnerGreetingsSelector, {
        visible: true,
      });
      const greetingText = await this.page.$eval(learnerGreetingsSelector, el =>
        el.textContent?.trim()
      );
      expect(greetingText).toContain(userName);
    } else {
      // Fall back to old dashboard greeting selector.
      await this.page.waitForSelector(greetingSelector, {
        visible: true,
      });
      const greetingElement = await this.page.$(greetingSelector);
      const greetingText = await this.page.evaluate(

Review comment (suggestion):
In `expect` functions we don't perform any actions, but very a specific thing. To verify being on LearnerDashboard you can use `expectElementToBeVisible` and check for some guranteed element on Learner Dashboard.

Code after:
      if (!lessonTitleText || lessonTitleText !== lessonTitle) {
        continue;
      }

      const resumeLessonButton = await lessonCard.$(resumeLessonButtonSelector);
      await resumeLessonButton?.click();

      await this.page.waitForSelector(resumeLessonButtonSelector, {
        hidden: true,
      });
      return;
    }
    throw new Error(`Lesson not found: ${lessonTitle}`);
  }

  /**
   * Checks if Learner is on the learner dashboard page.
   */
  async expectToBeOnLearnerDashboardPage(): Promise<void> {
    await this.expectElementToBeVisible(learnerDashboardContainerSelector);
  }

  /**
   * Checks if greeting has name of the user.
   */
  async expectGreetingToHaveNameOfUser(userName: string): Promise<void> {
    // Check for redesigned dashboard greeting first.
    const isRedesignedGreetingVisible = await this.isElementVisible(
      learnerGreetingsSelector,
      true
    );
    if (isRedesignedGreetingVisible) {
      const greetingText = await this.page.$eval(learnerGreetingsSelector, el =>
        el.textContent?.trim()
      );
      expect(greetingText).toContain(userName);
    } else {
      // Fall back to old dashboard greeting selector.
      await this.expectElementToBeVisible(greetingSelector);
      const greetingElement = await this.page.$(greetingSelector);
      const greetingText = await this.page.evaluate(
        el => el.textContent,
        greetingElement
      );
      expect(greetingText).toContain(userName);
    }
  }

  /**
   * Checks if the suggestion container in Learner Dashboard is empty.
   */