Skip to content

Commit

Permalink
[Glanceables] Add student classroom browsertests
Browse files Browse the repository at this point in the history
Add classroom student browsertests to cover the following cases:
- Clicking on a course work item and navigating to its url
- Switch to another assignment list and view updated items.
- Clicking the "see all" footer button

Also make sure that we scroll to the tasks glanceable for the task
tests, now that classroom glanceable pushes it off screen by default.

Low-Coverage-Reason: fake_glanceables_classroom_client.* is only used for unittesting.
Bug: b/294601121
Change-Id: I87338d0c0dbedc2bcab6546fe5a21191c8331517
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4803082
Reviewed-by: Artsiom Mitrokhin <amitrokhin@chromium.org>
Commit-Queue: Matthew Mourgos <mmourgos@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1187566}
  • Loading branch information
Matthew Mourgos authored and Chromium LUCI CQ committed Aug 23, 2023
1 parent 3795a70 commit d1eca94
Show file tree
Hide file tree
Showing 4 changed files with 313 additions and 6 deletions.
2 changes: 2 additions & 0 deletions ash/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4173,6 +4173,8 @@ static_library("test_support") {
"game_dashboard/game_dashboard_context_test_api.h",
"game_dashboard/test_game_dashboard_delegate.cc",
"game_dashboard/test_game_dashboard_delegate.h",
"glanceables/classroom/fake_glanceables_classroom_client.cc",
"glanceables/classroom/fake_glanceables_classroom_client.h",
"glanceables/tasks/fake_glanceables_tasks_client.cc",
"glanceables/tasks/fake_glanceables_tasks_client.h",
"glanceables/test_glanceables_delegate.cc",
Expand Down
100 changes: 100 additions & 0 deletions ash/glanceables/classroom/fake_glanceables_classroom_client.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/glanceables/classroom/fake_glanceables_classroom_client.h"

#include <string>

#include "ash/glanceables/classroom/glanceables_classroom_types.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_forward.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "url/gurl.h"

namespace ash {
namespace {

std::vector<std::unique_ptr<GlanceablesClassroomAssignment>>
CreateAssignmentsWithStringForStudents(
const std::string& course_work_name_prefix,
int count) {
std::vector<std::unique_ptr<GlanceablesClassroomAssignment>> assignments;
for (int i = 0; i < count; ++i) {
assignments.push_back(std::make_unique<GlanceablesClassroomAssignment>(
base::StringPrintf("Course %d", i),
base::StringPrintf("%s Course Work %d", course_work_name_prefix.c_str(),
i),
GURL(base::StringPrintf(
"https://classroom.google.com/c/test/a/test_course_id_%d/details",
i)),
absl::nullopt, base::Time(), absl::nullopt));
}
return assignments;
}

} // namespace

FakeGlanceablesClassroomClient::FakeGlanceablesClassroomClient(
GlanceablesClassroomClient* client)
: original_client_(client) {}

FakeGlanceablesClassroomClient::~FakeGlanceablesClassroomClient() = default;

void FakeGlanceablesClassroomClient::IsStudentRoleActive(
IsRoleEnabledCallback callback) {
std::move(callback).Run(true);
}

void FakeGlanceablesClassroomClient::GetCompletedStudentAssignments(
GetAssignmentsCallback callback) {
std::move(callback).Run(
true, CreateAssignmentsWithStringForStudents("Completed", 3));
}

void FakeGlanceablesClassroomClient::
GetStudentAssignmentsWithApproachingDueDate(
GetAssignmentsCallback callback) {
std::move(callback).Run(
true, CreateAssignmentsWithStringForStudents("Approaching", 3));
}

void FakeGlanceablesClassroomClient::GetStudentAssignmentsWithMissedDueDate(
GetAssignmentsCallback callback) {
std::move(callback).Run(true,
CreateAssignmentsWithStringForStudents("Missing", 3));
}

void FakeGlanceablesClassroomClient::GetStudentAssignmentsWithoutDueDate(
GetAssignmentsCallback callback) {
std::move(callback).Run(
true, CreateAssignmentsWithStringForStudents("No Due Date", 3));
}

void FakeGlanceablesClassroomClient::IsTeacherRoleActive(
IsRoleEnabledCallback callback) {
std::move(callback).Run(false);
}

void FakeGlanceablesClassroomClient::
GetTeacherAssignmentsWithApproachingDueDate(
GetAssignmentsCallback callback) {}

void FakeGlanceablesClassroomClient::GetTeacherAssignmentsRecentlyDue(
GetAssignmentsCallback callback) {}

void FakeGlanceablesClassroomClient::GetTeacherAssignmentsWithoutDueDate(
GetAssignmentsCallback callback) {}

void FakeGlanceablesClassroomClient::GetGradedTeacherAssignments(
GetAssignmentsCallback callback) {}

void FakeGlanceablesClassroomClient::OpenUrl(const GURL& url) const {
original_client_->OpenUrl(url);
}

void FakeGlanceablesClassroomClient::OnGlanceablesBubbleClosed() {}

} // namespace ash
50 changes: 50 additions & 0 deletions ash/glanceables/classroom/fake_glanceables_classroom_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_GLANCEABLES_CLASSROOM_FAKE_GLANCEABLES_CLASSROOM_CLIENT_H_
#define ASH_GLANCEABLES_CLASSROOM_FAKE_GLANCEABLES_CLASSROOM_CLIENT_H_

#include "ash/glanceables/classroom/glanceables_classroom_client.h"
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "testing/gmock/include/gmock/gmock.h"

namespace ash {

class FakeGlanceablesClassroomClient : public GlanceablesClassroomClient {
public:
explicit FakeGlanceablesClassroomClient(GlanceablesClassroomClient* client);
FakeGlanceablesClassroomClient(const FakeGlanceablesClassroomClient&) =
delete;
FakeGlanceablesClassroomClient& operator=(
const FakeGlanceablesClassroomClient&) = delete;
~FakeGlanceablesClassroomClient() override;

// GlanceablesClassroomClient:
void IsStudentRoleActive(IsRoleEnabledCallback callback) override;
void GetCompletedStudentAssignments(GetAssignmentsCallback callback) override;
void GetStudentAssignmentsWithApproachingDueDate(
GetAssignmentsCallback callback) override;
void GetStudentAssignmentsWithMissedDueDate(
GetAssignmentsCallback callback) override;
void GetStudentAssignmentsWithoutDueDate(
GetAssignmentsCallback callback) override;
void IsTeacherRoleActive(IsRoleEnabledCallback callback) override;
void GetTeacherAssignmentsWithApproachingDueDate(
GetAssignmentsCallback callback) override;
void GetTeacherAssignmentsRecentlyDue(
GetAssignmentsCallback callback) override;
void GetTeacherAssignmentsWithoutDueDate(
GetAssignmentsCallback callback) override;
void GetGradedTeacherAssignments(GetAssignmentsCallback callback) override;
void OpenUrl(const GURL& url) const override;
void OnGlanceablesBubbleClosed() override;

private:
const raw_ptr<GlanceablesClassroomClient, ExperimentalAsh> original_client_;
};

} // namespace ash

#endif // ASH_GLANCEABLES_CLASSROOM_FAKE_GLANCEABLES_CLASSROOM_CLIENT_H_

0 comments on commit d1eca94

Please sign in to comment.