#!/usr/local/cpanel/3rdparty/bin/perl -w
# cpanel - ./t/medium/Cpanel-Plugins-Components-whostmgr-home-360_homeapp.t
#                                                  Copyright 2024 cPanel, L.L.C.
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

package t::medium::Cpanel::Plugins::Components::whostmgr::home::360_homeapp;

use cPstrict;

use Cpanel::Plugins::Components::whostmgr::home::360_homeapp;
use Cpanel::Plugins::Components ();

use Test2::V0;
use Test2::Plugin::NoWarnings;
use Test2::Tools::Subtest;

use Test::MockModule qw/strict/;

my $mock_value = {};
subtest 'Test 360_homeapp' => sub {

    my $personalization_mock = Test::MockModule->new('Whostmgr::API::1::Personalization');
    $personalization_mock->redefine(
        personalization_get => sub ( $args, $metadata ) {
            return $mock_value;
        }
    );
    my $expected_template_file = 'monitoring/spa/index.html.mini.tt';
    my $expected_priority      = 5;
    mock_return(1);
    my $homeapp = Cpanel::Plugins::Components::whostmgr::home::360_homeapp->new();
    is( $homeapp->template_file(), $expected_template_file, 'we get the right template_file.' );
    is( $homeapp->slot(),          'menu-top',              'homeapp is in the correct slot' );

    is( $homeapp->is_enabled(), 1, 'homeapp is enabled' );

    mock_return(undef);
    $homeapp = Cpanel::Plugins::Components::whostmgr::home::360_homeapp->new();
    is( $homeapp->is_enabled(), '', 'homeapp is disabled when personalization is not set.' );
};

sub mock_return ($value) {
    $mock_value->{personalization} = {
        'homepage-app-enabled' => {
            value => $value,
        }
    };
}
done_testing;
