Skip to content

Commit

Permalink
Merge pull request #937 from bounswe/FRONTEND-936
Browse files Browse the repository at this point in the history
fix(frontend): post compose tests are fixed
  • Loading branch information
alitariksahin authored Dec 16, 2024
2 parents d140b99 + 0e08b00 commit 3381cc3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/post/compose-post-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export default function ComposePostForm() {
data-testid="submit-post-button"
color="primary"
onPress={handleSubmit}
isDisabled={!title || !content || selectedTags.length === 0}
isDisabled={!title || !content}
>
Post
</Button>
Expand Down
34 changes: 22 additions & 12 deletions frontend/src/pages/forumCompose.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ describe("ComposePostForm", () => {
it("renders form elements", () => {
expect(screen.getByTestId("post-title-input")).toBeInTheDocument();
expect(screen.getByTestId("post-content-input")).toBeInTheDocument();
expect(screen.getByTestId("category-select")).toBeInTheDocument();
expect(screen.getByTestId("difficulty-select")).toBeInTheDocument();
expect(screen.getByTestId("submit-post-button")).toBeInTheDocument();
expect(screen.getByTestId("add-tag-button")).toBeInTheDocument();
});

it("handles input changes", () => {
Expand Down Expand Up @@ -76,12 +76,6 @@ describe("ComposePostForm", () => {
const contentInput = screen.getByTestId("post-content-input");
await user.type(contentInput, "Test Content");

const categorySelect = screen.getByTestId("category-select");
await user.click(categorySelect);

const grammarOption = await screen.findByTestId("category-option-Grammar");
await user.click(grammarOption);

await waitFor(() => {
const submitButton = screen.getByTestId("submit-post-button");
expect(submitButton).not.toBeDisabled();
Expand All @@ -94,10 +88,6 @@ describe("ComposePostForm", () => {
await user.type(screen.getByTestId("post-title-input"), "Test Title");
await user.type(screen.getByTestId("post-content-input"), "Test Content");

await user.click(screen.getByTestId("category-select"));
const grammarOption = await screen.findByTestId("category-option-Grammar");
await user.click(grammarOption);

const submitButton = screen.getByTestId("submit-post-button");
await waitFor(() => {
expect(submitButton).not.toBeDisabled();
Expand All @@ -110,10 +100,30 @@ describe("ComposePostForm", () => {
expect.objectContaining({
title: "Test Title",
description: "Test Content",
tags: expect.arrayContaining(["#Grammar"]),
tags: [],
}),
expect.any(Object)
);
});
});

it("opens and closes tag search modal", async () => {
const user = userEvent.setup();

const addTagButton = screen.getByTestId("add-tag-button");
await user.click(addTagButton);

await waitFor(() => {
const tagSearchModal = screen.getByRole("dialog");
expect(tagSearchModal).toBeInTheDocument();
});

// Close modal using Escape key since there's no explicit close button
await user.keyboard('{Escape}');

await waitFor(() => {
const tagSearchModal = screen.queryByRole("dialog");
expect(tagSearchModal).not.toBeInTheDocument();
});
});
});

0 comments on commit 3381cc3

Please sign in to comment.