namespace content_creation {

class TemplateStoreTest : public testing::Test {
  void SetUp() override {
    scoped_feature_list_.InitAndEnableFeature(kWebNotesStylizeEnabled);
    template_store_ = std::make_unique<TemplateStore>(&testing_pref_service_);
  }

 protected:
  void ValidateTemplates(const std::vector<NoteTemplate>& note_templates) {
    std::unordered_set<NoteTemplateIds> ids_set;
    for (const NoteTemplate& note_template : note_templates) {
      EXPECT_LT(NoteTemplateIds::kUnknown, note_template.id());
      EXPECT_GE(NoteTemplateIds::kMaxValue, note_template.id());
      EXPECT_FALSE(note_template.localized_name().empty());
      EXPECT_FALSE(note_template.text_style().font_name().empty());

      // There should be no duplicated IDs.
      EXPECT_TRUE(ids_set.find(note_template.id()) == ids_set.end());
      ids_set.insert(note_template.id());
    }
  }

  // Have to use TaskEnvironment since the TemplateStore posts tasks to the
  // thread pool.
  base::test::TaskEnvironment task_environment_{
      base::test::TaskEnvironment::TimeSource::MOCK_TIME};

  base::test::ScopedFeatureList scoped_feature_list_;
  TestingPrefServiceSimple testing_pref_service_;
  std::unique_ptr<TemplateStore> template_store_;
};

// Tests that the store does return templates, and also validates the templates'
// information.
TEST_F(TemplateStoreTest, GetTemplatesSuccess) {
  base::RunLoop run_loop;

  template_store_->GetTemplates(base::BindLambdaForTesting(
      [&run_loop, this](std::vector<NoteTemplate> templates) {
        EXPECT_EQ(10U, templates.size());

        ValidateTemplates(templates);

        run_loop.Quit();
      }));

  run_loop.Run();
}

}  // namespace content_creation
