// Components
import damageReview from '@/layouts/payment-method/review-dropdown/review-sections/damage-review/damage-review.vue';

// Supporting Files
import { createTestingPinia } from '@pinia/testing';
import { useMainStore } from '@/store';
import { shallowMount } from '@vue/test-utils';
import { getMountOptions } from '@/helpers/unit-test-helper.js';
import { getDamageDisplayContent } from '@/helpers/damage-review-content-generator.js';
import baseMixin from '@/mixins/base-mixin';

jest.mock('@/helpers/damage-review-content-generator.js', () => ({
    getDamageDisplayContent: jest.fn(),
    getLocationAnswer: jest.fn()
}));

let cmsContent;
const mockMixin = {
    methods: {
        ...baseMixin.methods,
        getCmsContent: jest.fn((widgetName, cmsFieldName) => cmsContent?.[widgetName]?.[cmsFieldName] ?? '')
    }
};

function getShallowMountedComponent(mainInitialState = {}, initialData = {}, methodToRun = () => {}) {
    const mountOptions = getMountOptions({
        router: {
            navigate: jest.fn()
        }
    });

    const testingPinia = createTestingPinia({
        initialState: {
            main: mainInitialState
        }
    });
    useMainStore(testingPinia);
    methodToRun();

    mountOptions.global.plugins = [testingPinia];
    mountOptions.data = () => (
        initialData
    );

    mountOptions.mixins = [mockMixin];

    const wrapper = shallowMount(damageReview, mountOptions);
    return { wrapper };
}

beforeEach(() => {
    getDamageDisplayContent.mockClear();
});

describe('Damage Review Block', () => {
    test('computed displayContent calls getDamageDisplayContent with expected', () => {
        // Arrange
        const glassToReplace = ['front-window', 'side-window'];
        const isRepair = false;
        const initialStore = {
            order: {
                damage: {
                    glassToReplace,
                    isRepair
                }
            }
        };
        const expected = ['a', 'v', 'n'];
        getDamageDisplayContent.mockImplementationOnce(() => expected);
        const { wrapper } = getShallowMountedComponent(initialStore, {});

        // Act
        const result = wrapper.vm.displayContent;

        // Assert
        expect(result).toStrictEqual(expected);
        expect(getDamageDisplayContent).toBeCalledTimes(1);
        expect(getDamageDisplayContent).toBeCalledWith([], [], [], glassToReplace, isRepair);
    });
});
