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

write unit tests #277

Closed
wants to merge 1 commit into from
Closed

write unit tests #277

wants to merge 1 commit into from

Conversation

Moise1
Copy link
Contributor

@Moise1 Moise1 commented Oct 10, 2024

No description provided.

Copy link
Owner

@dubrox dubrox left a comment

Choose a reason for hiding this comment

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

Overall a great addition: from zero to about 90% coverage!
Thanks so much for this, as it will allow to maintain and evolve this plugin with more confidence :)

I will add my fixes to this branch but in a separate commit, so I can quickly approve and merge.

/*
* store original global keys
*/

Copy link
Owner

Choose a reason for hiding this comment

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

minor: there should be no empty line between the comments and the first line of code that the comment refers to. This way automated tools like IDEs can associate them.

Some examples:

Comment on lines +21 to +24
// Initialize multiDatesPicker if it's not already defined
if (!$.ui.multiDatesPicker) {
$.ui.multiDatesPicker = { version: '1.6.6' };
}
Copy link
Owner

Choose a reason for hiding this comment

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

Aren't the lines above (22-24) equivalent to the one below (27)?

I would just leave one, and the latter would take precedence for the sake of reducing the amount of changes when not needed.

Comment on lines +81 to +89
var mdp_settings = {
dateFormat: 'mm/dd/yy' // Set default format
}

if(options) {
$.extend(mdp_settings, options);
}

$this.datepicker(mdp_settings);
Copy link
Owner

Choose a reason for hiding this comment

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

I haven't tried it yet, but this default could override any default already present in the jQuery UI logic. It is a potentially breaking change, I would avoid adding this extra logic and just take whatever jQuery UI uses.

Comment on lines +384 to +388

if(end < begin) { // Swap if end is before begin
var temp = end;
end = begin;
begin = temp;
Copy link
Owner

Choose a reason for hiding this comment

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

This is actually more readable and thus maintainable, thanks.

end = begin;
begin = temp;
}
for(var i = begin; i <= end; i++)
Copy link
Owner

Choose a reason for hiding this comment

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

This small change in the code is a big difference in behaviour. While some may expect the end date to be included, and it is valid, the current logic is excluding it, so this would be a breaking change for anyone already adopting this solution.

Comment on lines +448 to 456
$(this).removeData('multiDatesPicker')
.off('.multiDatesPicker');

$(this).datepicker('destroy');

var index = $.inArray(this, $.ui.multiDatesPicker.instances);
if (index > -1) {
$.ui.multiDatesPicker.instances.splice(index, 1);
}
Copy link
Owner

Choose a reason for hiding this comment

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

I like the extra cleaning, thanks. I wouldn't be surprised to find out that this solves some of the open issues.

Comment on lines +448 to 456
$(this).removeData('multiDatesPicker')
.off('.multiDatesPicker');

$(this).datepicker('destroy');

var index = $.inArray(this, $.ui.multiDatesPicker.instances);
if (index > -1) {
$.ui.multiDatesPicker.instances.splice(index, 1);
}
Copy link
Owner

Choose a reason for hiding this comment

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

Interesting extra steps. Where did you find the docs that suggested them? Are they actually needed in this context?

Comment on lines +5 to +16
const $ = require('jquery');
require('jquery-ui/ui/widgets/datepicker');

if (!$.ui) {
$.ui = {};
}

if (!$.ui.multiDatesPicker) {
$.ui.multiDatesPicker = { version: '1.6.6' };
}

require('../jquery-ui.multidatespicker.js');
Copy link
Owner

Choose a reason for hiding this comment

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

This is not needed. Any needed initialization is already speficied in jest.setup.js

@@ -0,0 +1,5 @@
const $ = require('jquery');
global.$ = global.jQuery = $;

Copy link
Owner

Choose a reason for hiding this comment

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

This is missing jQuery UI.

dubrox pushed a commit that referenced this pull request Dec 15, 2024
This is a modified version of the original pull request:
#277

Pulled branch with fixes: https://github.com/dubrox/Multiple-Dates-Picker-for-jQuery-UI/tree/Moise1-unit-tests
Reviewer: dubrox
@dubrox
Copy link
Owner

dubrox commented Dec 15, 2024

I'm closing this pull request as I already added the needed fixes and merged with them to the main repo by keeping your authorship on the final commit:
87b7d36

@dubrox dubrox closed this Dec 15, 2024
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.

2 participants