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

Run-2321-Added unit test for date filter #9098

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

jayas006
Copy link
Contributor

@jayas006 jayas006 commented May 3, 2024

Is this a bugfix, or an enhancement? Please describe.
This is an enhancement

Describe the solution you've implemented

In the dateFilter.spec.ts file, I implemented tests to verify various aspects of the DateFilter component. These tests are designed to catch potential issues early in the development process and ensure that modifications to other parts of the project do not unintentionally impact the functionality of the DateFilter component.

Describe alternatives you've considered

Additional context

@jayas006 jayas006 changed the title added unit test for date filter Run-2321-Added unit test for date filter May 15, 2024
@jayas006 jayas006 marked this pull request as ready for review June 4, 2024 19:23
Copy link
Contributor

@smartinellibenedetti smartinellibenedetti left a comment

Choose a reason for hiding this comment

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

left some pointers, overall looking good. The component dateFilter could be refactored, once the tests are merged if you'd like to give it a shot, it would be a good practice with vue (the modelValue doesn't need to be destructed into data properties and could be used directly in the template)

Comment on lines 43 to 46
modelValue: {
type: Object,
required: true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please create a type for modelValue, describing that it has the properties enabled and datetime?

import DateTimePicker from "../dateTimePicker.vue";
import _ from "lodash";
let idCounter = 0;
jest.spyOn(_, "uniqueId").mockImplementation(() => `uniqueId_${idCounter++}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

you have this spy later in the code, safe to remove this line

Comment on lines 52 to 57
it("initializes with correct data", () => {
const wrapper = mountDateFilter();
expect(wrapper.vm.uid).toBeTruthy();
expect(wrapper.vm.enabled).toBe(false);
expect(wrapper.vm.datetime).toBe("");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

please remove this test

Comment on lines 58 to 61
it("sets uid correctly", () => {
const wrapper = mountDateFilter();
expect(wrapper.vm.uid).toBe(`uniqueId_${idCounter - 1}`);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

better to check that the input has the right id (which is the uid) instead of checking wrapper.vm.uid

Comment on lines 84 to 90
it("renders provided slot content in label", async () => {
const slotContent = "Provided slot content";
const wrapper = mountDateFilter({ slots: { default: slotContent } });
await wrapper.vm.$nextTick();
const label = wrapper.find("label");
expect(label.text()).toBe(slotContent);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

this test isn't relevant - dateFilter doesn't have logic that would affect the label content (it's always enabled). Suggest to remove it.

it("toggles enabled state when checkbox is clicked", async () => {
const wrapper = mountDateFilter();
const checkbox = wrapper.find('input[type="checkbox"]');
await checkbox.setValue(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

it's always preferable to click then to setValue if possible

await wrapper.vm.$nextTick();
const emitted = wrapper.emitted("update:modelValue");
expect(emitted).toBeTruthy();
if (emitted) {
Copy link
Contributor

Choose a reason for hiding this comment

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

please remove this if and just leave the line expect(emitted[0]).toEqual([{ enabled: true, datetime: "" }]);

await wrapper.vm.$nextTick();
const emitted = wrapper.emitted("update:modelValue");
expect(emitted).toBeTruthy();
if (emitted) {
Copy link
Contributor

Choose a reason for hiding this comment

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

please remove if

@jayas006
Copy link
Contributor Author

jayas006 commented Jun 7, 2024

left some pointers, overall looking good. The component dateFilter could be refactored, once the tests are merged if you'd like to give it a shot, it would be a good practice with vue (the modelValue doesn't need to be destructed into data properties and could be used directly in the template)

Yes will do that. Thanks

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.

None yet

2 participants