/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.gestures;

import static com.google.common.truth.Truth.assertThat;

import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.SearchIndexableResource;
import android.service.quickaccesswallet.Flags;

import com.android.settings.R;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

import java.util.List;

@RunWith(RobolectricTestRunner.class)
public class DoubleTapPowerSettingsTest {

    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
    private DoubleTapPowerSettings mSettings;

    @Before
    public void setUp() {
        mSettings = new DoubleTapPowerSettings();
    }

    @Test
    @EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
    public void getPreferenceScreenResId_flagEnabled_returnsFlagEnabledResId() {
        assertThat(mSettings.getPreferenceScreenResId()).isEqualTo(R.xml.double_tap_power_settings);
    }

    @Test
    @DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
    public void getPreferenceScreenResId_flagDisabled_returnsFlagDisabledResId() {
        assertThat(mSettings.getPreferenceScreenResId())
                .isEqualTo(R.xml.double_tap_power_to_open_camera_settings);
    }

    @Test
    @EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
    public void testSearchIndexProvider_flagEnabled_shouldIndexFlagEnabledResource() {
        final List<SearchIndexableResource> indexRes =
                DoubleTapPowerSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
                        RuntimeEnvironment.getApplication(), true /* enabled */);

        assertThat(indexRes).isNotNull();
        assertThat(indexRes.get(0).xmlResId).isEqualTo(R.xml.double_tap_power_settings);
    }

    @Test
    @DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
    public void testSearchIndexProvider_flagDisabled_shouldIndexFlagDisabledResource() {
        final List<SearchIndexableResource> indexRes =
                DoubleTapPowerSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
                        RuntimeEnvironment.getApplication(), true /* enabled */);

        assertThat(indexRes).isNotNull();
        assertThat(indexRes.get(0).xmlResId)
                .isEqualTo(R.xml.double_tap_power_to_open_camera_settings);
    }
}
