Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(filter): added filter common component #1027

Merged
merged 9 commits into from
Dec 10, 2024

Conversation

Hasteerp
Copy link
Contributor

@Hasteerp Hasteerp commented Nov 30, 2024

Contributor checklist


Description

I added a common reusable Filter component.
ScreenRecording2024-11-30at12 56 16PM-ezgif com-video-to-gif-converter

The Filter component is a reusable component.
It takes the following props:

  • HandleFilterChange
  • tabs (id, name)[]
  • sections (title, tags[])
    • tags: (id: number, name: string, selected: boolean)

This way you have full control over the tag title and tag buttons you want to populate. Additionally, decision can be made to check tab values and name based on each page requirement. It also takes handleFilterChange from the parent component that allows different filteration logic based on parent component requirement.

Related issue

Copy link

netlify bot commented Nov 30, 2024

Deploy Preview for activist-org ready!

Name Link
🔨 Latest commit de568a2
🔍 Latest deploy log https://app.netlify.com/sites/activist-org/deploys/6757b959d0cdc00008a37551
😎 Deploy Preview https://deploy-preview-1027--activist-org.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Nov 30, 2024

Thank you for the pull request!

The activist team will do our best to address your contribution as soon as we can. The following is a checklist for maintainers to make sure this process goes as well as possible. Feel free to address the points below yourself in further commits if you realize that actions are needed :)

If you're not already a member of our public Matrix community, please consider joining! We'd suggest using Element as your Matrix client, and definitely join the General and Development rooms once you're in. Also consider joining our bi-weekly Saturday dev syncs. It'd be great to have you!

Maintainer checklist

  • The TypeScript and formatting workflows within the PR checks do not indicate new errors in the files changed

  • The Playwright end to end and Zap penetration tests have been ran and are passing (if necessary)

  • The changelog has been updated with a description of the changes for the upcoming release and the corresponding issue (if necessary)

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First PR Commit Check

  • The commit messages for the remote branch of a new contributor should be checked to make sure their email is set up correctly so that they receive credit for their contribution
    • The contributor's name and icon in remote commits should be the same as what appears in the PR
    • If there's a mismatch, the contributor needs to make sure that the email they use for GitHub matches what they have for git config user.email in their local activist repo

@Hasteerp
Copy link
Contributor Author

Hasteerp commented Nov 30, 2024

I'll be removing the filter component usage from organizations before merging. It is currently there for reviewer to visualize how the filter component looks. @andrewtavis please feel free to check it out and leave any necessary comments. Thanks!

@andrewtavis andrewtavis self-requested a review November 30, 2024 18:20
@andrewtavis
Copy link
Member

Looking forward to the review here, @Hasteerp! I'll try to get to this tomorrow or early next week 😊

@cquinn540
Copy link
Collaborator

@Hasteerp We just added component testing to this project. Could you try adding some tests for your new filter component?

There's some new documentation on writing component tests in the contributing guide you can find here. This is new so let us know if the documentation is clear enough or if it needs improvements.

@Hasteerp
Copy link
Contributor Author

Hasteerp commented Dec 4, 2024

@cquinn540 I was having a difficult time getting the test to run. Would you have any suggestions?

@cquinn540
Copy link
Collaborator

@cquinn540 I was having a difficult time getting the test to run. Would you have any suggestions?

I would need to know more about what issue you are facing. I'll be a bit busy today, but I should have more free time to help over the next few days.

@Hasteerp
Copy link
Contributor Author

Hasteerp commented Dec 5, 2024

@cquinn540 I was facing some issues trying to get my component to render I think the custom render function needs to change but I am not exactly sure. This is the error message that I got. Please feel free to check it out thanks!

`This error originated in "test/components/filter/pageFilter.spec.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.
The latest test that might've caused the error is "test/components/filter/pageFilter.spec.ts". It might mean one of the following:

  • The error was thrown, while Vitest was running this test.
  • If the error occurred after the test had been completed, this was the last documented test before it was thrown.
    `

@cquinn540
Copy link
Collaborator

@Hasteerp Would you have time today or sooon to get on a call in Matrix chat so I can see what you are seeing? That's the top level error message which is generic and doesn't give much information. There's usually another stack trace somewhere in the output with more details.

@Hasteerp
Copy link
Contributor Author

Hasteerp commented Dec 6, 2024

I can get on a call tomorrow @cquinn540 if that works for you.

@cquinn540
Copy link
Collaborator

Sorry @Hasteerp I got into the zone working on another issue and didn't see this until now. Let me know on the Matrix chat when you are available today.

@Hasteerp
Copy link
Contributor Author

Hasteerp commented Dec 9, 2024

@andrewtavis @cquinn540 Please check it out whenever you can. I added the test case.

import { describe, it, expect } from "vitest";
import { render, screen } from "@testing-library/vue";
import PageFilter from "@/components/page/filter/PageFilter.vue";

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I need to go back on what I said originally a little. There is an appropriate case for a mock function here. You should create a mock function like:

const mockHandleFilterChange = vi.fn();

and you'll want to reset it after each test

afterEach(() => {
  mockHandleFilterChange.mockClear();
});

tabs: [
{ id: "tab1", name: "Tab 1" },
{ id: "tab2", name: "Tab 2" },
{ id: "tab3", name: "Tab 3" },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you should use mockHandleFilterChange as the @filter-change prop

],
};

it("should render", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you want a test where you click the different options and confirm that mockHandleFilterChange was called with the right arguments in the right order.

And another test where you tab through the options and hit enter and again confirm the mock was called correctly.

You can see the call list with calls array on your mock function.

Ideally you would also have a test checking that the focusing works correctly, but given your time limit I can be flexible on that.

Comment on lines 41 to 44
expect(screen.getByText("Popular Tags")).toBeTruthy();
expect(screen.getByRole("heading", { name: "Filter" })).toBeTruthy();
expect(screen.getByLabelText("Search to filter")).toBeTruthy();
expect(screen.getByRole("textbox", { id: "input-search" })).toBeTruthy();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the other behavior tests testing for truthyness shouldn't be needed anymore

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in my commit ✅

@andrewtavis
Copy link
Member

I've made #1051 to do the follow up work to finalize the tests. We are on a bit of a deadline here for @Hasteerp, which I hope that we haven't missed, and the contributions till now are enough that we should bring them in and then continue when we have a bit more time.

@Hasteerp
Copy link
Contributor Author

@andrewtavis thanks for the pull request and allowing me to merge this one. We are currently seeing an error in linting due to unused vars (this is coming from index.vue on organizations page). This is because we commented the code out but the parameters were defined. We can either remove them completely or comment out the code for now. Please let me know what you would suggest I do and I can make a commit accordingly. Thank you for taking into consideration my deadline. Appreciate it! I'll work on the test cases in the new PR in the coming week.

Copy link
Member

@andrewtavis andrewtavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving these with the assumption that the most recent commit fixes all the frontend linting issues, but I'll get to them if there are any other changes.

Really appreciate this as a first contribution, @Hasteerp, and hope that we can work with you again :) Let's definitely keep #1051 in mind in the coming weeks, but this is a great start on a relatively complex component 🚀

@cquinn540: Don't mean to disregard your review, and really appreciate the support you're providing to @Hasteerp! This component isn't MVP, so under the circumstances I'd like to bring it in and iterate 😊

@andrewtavis andrewtavis merged commit a56ef26 into activist-org:main Dec 10, 2024
7 checks passed
@cquinn540
Copy link
Collaborator

No problem this seems like a reasonable compromise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants