import { shallowMount } from '@vue/test-utils';
import ReviewBlock from '@/layouts/tpa-submit/review-block/review-block.vue';

describe('ReviewBlock.vue', () => {
    let wrapper;
    const lines = ['Line 1', 'Line 2', 'Line 3'];

    beforeEach(() => {
        wrapper = shallowMount(ReviewBlock, {
            propsData: {
                customHeaderText: 'Test Header',
                lines
            }
        });
    });

    it('renders the correct header text', () => {
        const headerElement = wrapper.find('.review-block__header');
        expect(headerElement.text()).toBe('Test Header');
    });

    it('renders the correct number of lines', () => {
        const lineElements = wrapper.findAll('.review-body p');
        expect(lineElements.length).toBe(lines.length);
    });

    it('renders the correct line text', () => {
        const lineElements = wrapper.findAll('.review-body p');
        lines.forEach((line, index) => {
            expect(lineElements.at(index).text()).toBe(line);
        });
    });

    it('updates the header text when prop changes', async () => {
        await wrapper.setProps({ customHeaderText: 'New Header' });
        const headerElement = wrapper.find('.review-block__header');
        expect(headerElement.text()).toBe('New Header');
    });

    it('emits an event when the edit link is clicked', async () => {
        const linkElement = wrapper.findComponent({ name: 'textLink' });
        await linkElement.vm.$emit('clickEvent');
        expect(wrapper.emitted('click-edit')).toBeTruthy();
    });

    it('renders correctly with no lines', () => {
        wrapper = shallowMount(ReviewBlock, {
            propsData: {
                customHeaderText: 'Test Header',
                lines: []
            }
        });
        const lineElements = wrapper.findAll('.review-block__body--line');
        expect(lineElements.length).toBe(0);
    });
});
