import { composeStories } from "@storybook/react";
import { render, screen } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import * as surveyBuilderStories from "./SurveyBuilder.stories";

const {
	Default,
	WithQuestions,
	CustomerFeedback,
	EmployeeEngagement,
	ReadOnly,
} = composeStories(surveyBuilderStories);

describe("SurveyBuilder stories", () => {
	describe("Default story", () => {
		it("should render survey builder interface", () => {
			render(<Default />);
			// Should have basic survey building interface
			const addButtons = screen.queryAllByText(/Add/i);
			expect(addButtons.length).toBeGreaterThanOrEqual(0);
		});
	});

	describe("WithQuestions story", () => {
		it("should render survey questions", () => {
			render(<WithQuestions />);
			expect(screen.getByText("What is your name?")).toBeInTheDocument();
			expect(
				screen.getByText("How satisfied are you with our service?"),
			).toBeInTheDocument();
		});

		it("should render different question types", () => {
			render(<WithQuestions />);
			// Check for various question elements
			const questionElements = screen.queryAllByText(/name|email|satisfied/i);
			expect(questionElements.length).toBeGreaterThan(0);
		});
	});

	describe("CustomerFeedback story", () => {
		it("should render customer feedback survey", () => {
			render(<CustomerFeedback />);
			expect(screen.getByText("Customer Feedback Survey")).toBeInTheDocument();
		});

		it("should render feedback questions", () => {
			render(<CustomerFeedback />);
			// Check for typical feedback questions
			const feedbackElements = screen.queryAllByText(
				/product|service|recommend/i,
			);
			expect(feedbackElements.length).toBeGreaterThan(0);
		});
	});

	describe("EmployeeEngagement story", () => {
		it("should render employee engagement survey", () => {
			render(<EmployeeEngagement />);
			expect(
				screen.getByText("Employee Engagement Survey"),
			).toBeInTheDocument();
		});

		it("should render engagement questions", () => {
			render(<EmployeeEngagement />);
			// Check for employee-related questions
			const engagementElements = screen.queryAllByText(
				/job|team|management|work/i,
			);
			expect(engagementElements.length).toBeGreaterThan(0);
		});
	});

	describe("ReadOnly story", () => {
		it("should render in read-only mode", () => {
			render(<ReadOnly />);
			// Should render but without edit capabilities
			expect(screen.getByText("What is your name?")).toBeInTheDocument();
		});
	});
});
