Skip to content

added currentDate matcher#41

Merged
sethii merged 4 commits intoTheSoftwareHouse:nextfrom
simonsipl:feature/currentDate-matcher
May 29, 2018
Merged

added currentDate matcher#41
sethii merged 4 commits intoTheSoftwareHouse:nextfrom
simonsipl:feature/currentDate-matcher

Conversation

@simonsipl
Copy link
Contributor

No description provided.


class CurrentDateMatcher {
isSatisfiedBy(prefix, name) {
return prefix === 'f' && name === 'currentDate';
Copy link
Contributor

Choose a reason for hiding this comment

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

We're using prefix f for functions like isVisible, isClickable and so on. Maybe, in this case, it would be better to use a prefix m? What do you think @sethii ?

Copy link
Contributor Author

@simonsipl simonsipl Mar 21, 2018

Choose a reason for hiding this comment

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

Yeah actually might be better, this way
@edit i decided to go back to f:

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, let's keep it with f:currentDate

}

match(element) {
let currentDate = Sugar.Date.create('now');
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. It's simple, so maybe you should use it like this:
    const currentDate = Sugar.Date.format(Sugar.Date.create('now'), '{yyyy}-{MM}-{dd}');

  2. Currently, you're supporting only {yyyy}-{MM}-{dd}, I think it should be working in the same way as date comparator. So a user can provide dates dd/mm/yyyy and so on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Yeah good point
  2. It supports all data formats, Sugar library can handle it, it's just changed to this format to compare by dates. https://sugarjs.com/dates/

let compareDate = Sugar.Date.create(text);
compareDate = Sugar.Date.format(compareDate, '{yyyy}-{MM}-{dd}');

if (compareDate === currentDate) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you could use ES6 if...else
(compareDate === currentDate) ? true : false;

import Sugar from 'sugar-date';
import { expect } from 'chai';

describe('Current Date matcher', () => {
Copy link
Contributor

@tgorskievo tgorskievo Mar 21, 2018

Choose a reason for hiding this comment

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

You're missing tests which cover:

  • dates with slash e.g. 2018/03/2018

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added test for incorrect date


class CurrentDateMatcher {
isSatisfiedBy(prefix, name) {
return prefix === 'f' && name === 'currentDate';
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, let's keep it with f:currentDate


return element.getText().then((text) => {
const compareDate = Sugar.Date.format(Sugar.Date.create(text), dateFormat);
return (compareDate === currentDate) ? true : false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you can use just return compareDate === currentDate?

Given I visit the "main" page
When I click the "matchersLink" element
Then the "matchers" page is displayed
And there is element "dateElement" with value "f:currentDate:{yyyy}-{MM}-{dd}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure that we should be using curly braces in the feature files?
currently: "f:currentDate:{yyyy}-{MM}-{dd}"
proposition: "f:currentDate:yyyy-MM-dd"

@sethii What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is library property to pass format LDML tokens https://sugarjs.com/dates/#/Formatting

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you have an established format od dates used in the project? I mean I guess there's a dictionary that says "here we use date with format: YY-mm-dd" or whatever else.

Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I know, sugar has something like global date format (in some cases we changed it into DD/MM/YYYY).

Maybe instead of providing format as a parameter, we could integrate it into global specified format ? This ways we will make sure that the date format is the same in every date related code.

@simonsipl
Copy link
Contributor Author

Library was changed from sugar to moments, to remove {} brackets, also I added new functional tests.

@sethii sethii merged commit f298dcb into TheSoftwareHouse:next May 29, 2018
@simonsipl simonsipl deleted the feature/currentDate-matcher branch June 17, 2019 08:16
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.

4 participants