< Summary

Class:FavoriteButtonComponentView
Assembly:UIComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/Favorites/FavoriteButtonComponentView.cs
Covered lines:14
Uncovered lines:7
Coverable lines:21
Total lines:62
Line coverage:66.6% (14 of 21)
Covered branches:0
Total branches:0
Covered methods:6
Total methods:8
Method coverage:75% (6 of 8)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
RefreshControl()0%2.062075%
IsFavorite()0%220100%
SetFavoriteFromButton()0%6200%
SetFavorite(...)0%110100%
SetButtonVisuals(...)0%330100%
SetInteractable(...)0%2100%
Configure(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/Favorites/FavoriteButtonComponentView.cs

#LineLine coverage
 1using System;
 2using UnityEngine;
 3using UnityEngine.UI;
 4
 5public class FavoriteButtonComponentView : BaseComponentView, IComponentModelConfig<FavoriteButtonComponentModel>
 6{
 7    [Header("Prefab References")]
 8    [SerializeField] private ButtonComponentView button;
 9    [SerializeField] private Image buttonFill;
 10    [SerializeField] private Color noFavoriteFillColor;
 11    [SerializeField] private Color favoriteFillColor;
 12
 13    [Header("Configuration")]
 14    [SerializeField] internal FavoriteButtonComponentModel model;
 15
 16    public event Action<string, bool> OnFavoriteChange;
 17
 18    public override void Awake()
 19    {
 110620        base.Awake();
 21
 110622        button.onClick.RemoveAllListeners();
 110623        button.onClick.AddListener(SetFavoriteFromButton);
 110624    }
 25
 26    public override void RefreshControl()
 27    {
 5928        if (model == null)
 029            return;
 30
 5931        SetFavorite(model.isFavorite);
 5932    }
 33
 34    public bool IsFavorite() =>
 136135        model?.isFavorite ?? false;
 36
 37    private void SetFavoriteFromButton()
 38    {
 039        model.isFavorite = !model.isFavorite;
 040        OnFavoriteChange?.Invoke(model.placeUUID, model.isFavorite);
 041        RefreshControl();
 042    }
 43
 44    private void SetFavorite(bool isFavorite)
 45    {
 5946        SetButtonVisuals(isFavorite);
 5947    }
 48
 49    private void SetButtonVisuals(bool isFavorite) =>
 5950        buttonFill.color = isFavorite ? favoriteFillColor : noFavoriteFillColor;
 51
 52    public void SetInteractable(bool isInteractable)
 53    {
 054        button.button.interactable = isInteractable;
 055    }
 56
 57    public void Configure(FavoriteButtonComponentModel newModel)
 58    {
 5959        model = newModel;
 5960        RefreshControl();
 5961    }
 62}