Skip to content

Commit

Permalink
feat: Allow changing GeoKret birth date
Browse files Browse the repository at this point in the history
  • Loading branch information
kumy committed May 20, 2024
1 parent 13bd392 commit 7415819
Show file tree
Hide file tree
Showing 35 changed files with 501 additions and 58 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ phinx-rollback: ## DB rollback migration
${PTY_PREFIX} bash -c "cd website && ../vendor/bin/phinx rollback"
phinx-status: ## DB migration status
${PTY_PREFIX} bash -c "cd website && ../vendor/bin/phinx status"
phinx-chown: ## Change file owner to userid 1000
${PTY_PREFIX} chown -R 1000.1000 website/db/migrations/

compile-all-templates: ## compile all smarty templates
${PTY_PREFIX} bash -c "cd website/public && php geokrety.php /cli/smarty/compile-all-templates"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Test Setup Test Setup

Create A GeoKret
Go To Url ${PAGE_GEOKRETY_CREATE_URL}
Page Should Not Contain Birth date
Create GeoKret &{GEOKRETY_1}
Element Should Contain ${GEOKRET_DETAILS_NAME} ${GEOKRETY_1.name}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,22 @@ Cannot edit someone else GeoKret
Edit A GeoKret
Sign In ${USER_1.name} Fast
Go To Url ${PAGE_GEOKRETY_EDIT_URL}
Page Should Contain Birth date

${selected_template} = Get Selected List Value ${GEOKRET_CREATE_LABEL_TEMPLATE_SELECT}
Should Be Equal ${selected_template} default

Input Text ${GEOKRET_CREATE_NAME_INPUT} GKNewName
Execute Javascript $("#datetimepicker").data("DateTimePicker").date(moment.utc("2024-05-18").zone("UTC"));
Simulate Event ${GEOKRET_CREATE_BORN_ON_DATETIME_INPUT} blur
Select From List By Value ${GEOKRET_CREATE_TYPE_SELECT} 1
Input Inscrybmde \#inputMission New mission
Select From List By Value ${GEOKRET_CREATE_LABEL_TEMPLATE_SELECT} sansanchoz1

Click Button ${GEOKRET_CREATE_CREATE_BUTTON}
Location Should Be ${PAGE_GEOKRETY_1_DETAILS_URL}
Element Should Contain ${GEOKRET_DETAILS_NAME} GKNewName
Element Attribute Should Be ${GEOKRET_DETAILS_CREATED_ON_DATETIME}/span data-datetime 2024-05-18T00:00:00+00:00
Element Should Contain ${GEOKRET_DETAILS_TYPE} A book/CD/DVD…
Element Should Contain ${GEOKRET_DETAILS_MISSION} New mission

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
*** Settings ***
Library RequestsLibrary
Library ../../ressources/libraries/DateTimeTZ.py
Library DateTime
Library XML
Resource ../../ressources/Authentication.robot
Resource ../../ressources/Geokrety.robot
Resource ../../ressources/Moves.robot
Resource ../../ressources/vars/pages/Home.robot
Variables ../../ressources/vars/users.yml
Variables ../../ressources/vars/geokrety.yml
Test Setup Test Setup

*** Variables ***
${FIELD_RESULT_FORMAT} = %Y-%m-%dT%H:%M:%S+00:00

*** Test Cases ***

Not in the future
${date} = Get Current Date increment=3days result_format=${FIELD_RESULT_FORMAT}
Sign In ${USER_1.name} Fast
Go To Url ${PAGE_GEOKRETY_EDIT_URL}
Execute Javascript $("#datetimepicker").data("DateTimePicker").date(moment.utc().add(7, 'days').format('L'));
Simulate Event ${GEOKRET_CREATE_BORN_ON_DATETIME_INPUT} blur
Input validation has error ${GEOKRET_CREATE_BORN_ON_DATETIME_INPUT}
Input validation has error help ${GEOKRET_CREATE_BORN_ON_DATETIME_INPUT} The date cannot be in the future.


Not sooner than the oldest move
Post Move Fast &{MOVE_1}
${expected} = Change Born Date To Now
Flash message shown GeoKret birth date cannot be greater than its oldest move

Shown On GeoKret Page
${expected} = Change Born Date To Now With Validation
Go To GeoKrety ${1}
Element Attribute Should Be ${GEOKRET_DETAILS_CREATED_ON_DATETIME}/span data-datetime ${expected}


Shown On User Inventory Page
${expected} = Change Born Date To Now With Validation
Go To Url ${PAGE_USER_INVENTORY_URL} userid=${USER_1.id}
Wait Until Page Contains Element ${USER_INVENTORY_TABLE}/tbody/tr
Element Count Should Be ${USER_INVENTORY_TABLE}/tbody/tr 1
Element Attribute Should Be ${USER_INVENTORY_TABLE}//tr[1]/td[4]/span data-datetime ${expected}


Shown On User Owned Page
${expected} = Change Born Date To Now With Validation
Go To Url ${PAGE_USER_OWNED_GEOKRETY_URL} userid=${USER_1.id}
Wait Until Page Contains Element ${USER_OWNED_GEOKRETY_TABLE}/tbody/tr
Element Count Should Be ${USER_OWNED_GEOKRETY_TABLE}/tbody/tr 1
Element Attribute Should Be ${USER_OWNED_GEOKRETY_TABLE}//tr[1]/td[4]/span data-datetime ${expected}


Shown On User Watched Page
${expected} = Change Born Date To Now With Validation

Sign In ${USER_2.name} Fast
Go To GeoKrety ${GEOKRETY_1.id}
Click Element ${GEOKRET_DETAILS_WATCH_LINK}
Wait Until Modal Add this GeoKret to your watch list?
Click Button ${MODAL_DIALOG_SUBMIT_BUTTON}

Go To Url ${PAGE_USER_WATCHED_GEOKRETY_URL} userid=${USER_2.id}
Wait Until Page Contains Element ${USER_WATCHED_TABLE}/tbody/tr
Element Count Should Be ${USER_WATCHED_TABLE}/tbody/tr 1
Element Attribute Should Be ${USER_WATCHED_TABLE}//tr[1]/td[5]/span data-datetime ${expected}


Shown On Home Page
${expected} = Change Born Date To Now With Validation

Go To Home
Element Attribute Should Be ${HOME_RECENTLY_CREATED_GK_TABLE}//tr[1]/td[4]/span data-datetime ${expected}


Shown On Inventory Picker
[Tags] TODO
${expected} = Change Born Date To Now With Validation
Sign In ${USER_1.name} Fast
Go To Move
Open Inventory
Element Attribute Should Be ${MOVE_INVENTORY_TABLE}//tr[1]/td[3]/span data-datetime ${expected}


Shown In Export
${expected} = Change Born Date To Now With Validation result_format=%Y-%m-%d %H:%M:%S

${date_2_days_old} = Get Current Date increment=-2d result_format=%Y%m%d%H%M%d
Create Session geokrety ${GK_URL}
${xml} = GET On Session geokrety url=/export.php?modifiedsince=${date_2_days_old}
Status Should Be 200 ${xml}

${root} = Parse Xml ${xml.content}
Should Be Equal ${root.tag} gkxml

${first_gk} = Get Element ${root} geokret
${datecreated} = Get Element ${first_gk} datecreated
XML.Element Text Should Be ${datecreated} ${expected}


Shown In Export2
${expected} = Change Born Date To Now With Validation result_format=%Y-%m-%d

Create Session geokrety ${GK_URL}
${xml} = GET On Session geokrety url=/export2.php?gkid=${GEOKRETY_1.id}
Status Should Be 200 ${xml}

${root} = Parse XML ${xml.content}
Should Be Equal ${root.tag} gkxml

${first_gk} = Get Element ${root} geokrety/geokret
XML.Element Attribute Should Be ${first_gk} date ${expected}


Shown In Export2Details
${expected} = Change Born Date To Now With Validation result_format=%Y-%m-%d %H:%M:%S

Create Session geokrety ${GK_URL}
${xml} = GET On Session geokrety url=/export2.php?details=1&gkid=${GEOKRETY_1.id}
Status Should Be 200 ${xml}

${root} = Parse XML ${xml.content}
Should Be Equal ${root.tag} gkxml

${first_gk} = Get Element ${root} geokrety/geokret

${datecreated} = Get Element ${first_gk} datecreated
XML.Element Text Should Be ${datecreated} ${expected}


*** Keywords ***

Test Setup
Clear Database And Seed ${2} users
Seed ${1} geokrety owned by ${1} with birthdate 2020-08-12T00:00:00

Change Born Date To Now
[Arguments] ${result_format}=${FIELD_RESULT_FORMAT}
Sign In ${USER_1.name} Fast
Go To Url ${PAGE_GEOKRETY_EDIT_URL}
Execute Javascript $("#datetimepicker").data("DateTimePicker").date(moment.utc().format('L'));
Simulate Event ${GEOKRET_CREATE_BORN_ON_DATETIME_INPUT} blur
${date} = Browser.Get Element Attribute ${GEOKRET_CREATE_BORN_ON_DATETIME_HIDDEN_INPUT} value
Click Button ${GEOKRET_CREATE_CREATE_BUTTON}
RETURN ${date}


Change Born Date To Now With Validation
[Arguments] ${result_format}=${FIELD_RESULT_FORMAT}
${date} = Change Born Date To Now result_format=${result_format}
Location Should Be ${PAGE_GEOKRETY_1_DETAILS_URL}
${expected} = datetime_to_utc ${date} date_format=%Y-%m-%dT%H:%M:%S%z result_format=${result_format}

RETURN ${expected}
Sign Out Fast

Open Inventory
Click Button ${MOVE_TRACKING_CODE_INVENTORY_BUTTON}
Wait Until Modal Select GeoKrety from inventory
2 changes: 2 additions & 0 deletions tests-qa/acceptance/ressources/ComponentsLocator.robot
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ ${NAVBAR_ACTIONS_PHOTO_GALLERY_LINK} //*[@id="navbar-actions-gallery"]

${GEOKRET_CREATE_CREATE_BUTTON} //*[@id="createOrUpdateSubmitButton"]
${GEOKRET_CREATE_NAME_INPUT} //*[@id="inputName"]
${GEOKRET_CREATE_BORN_ON_DATETIME_INPUT} //*[@id="born_on_datetime_localized"]
${GEOKRET_CREATE_BORN_ON_DATETIME_HIDDEN_INPUT} //*[@id="born_on_datetime"]
${GEOKRET_CREATE_TYPE_SELECT} //*[@id="inputGeokretType"]
${GEOKRET_CREATE_MISSION_INPUT} //*[@id="inputMission"]
${GEOKRET_CREATE_OLD_MISSION_BUTTON} //*[@data-type="geokret-legacy-mission"]
Expand Down
2 changes: 1 addition & 1 deletion tests-qa/acceptance/ressources/CustomActions.robot
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Element Count Should Be

Element Attribute Should Be
[Arguments] ${element} ${attribute} ${expect}
${attr} = Get Element Attribute ${element} ${attribute}
${attr} = Browser.Get Element Attribute ${element} ${attribute}
Should Be Equal As Strings ${attr} ${expect}

Wait For Text To Not Appear
Expand Down
3 changes: 3 additions & 0 deletions tests-qa/acceptance/ressources/Devel.robot
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ Seed ${count} geokrety owned by ${userid}
Seed ${count} geokrety owned by ${userid} with mission ${mission}
Go To Url Fast url=${GK_URL}/devel/db/users/${userid}/geokrety/seed/${count}?mission=${mission}

Seed ${count} geokrety owned by ${userid} with birthdate ${birthdate}
Go To Url Fast url=${GK_URL}/devel/db/users/${userid}/geokrety/seed/${count}?birthdate=${birthdate}

Seed special geokrety with tracking code starting with GK owned by ${userid}
Go To Url Fast ${GK_URL}/devel/db/users/${userid}/geokrety/tc-starting-with-gk

Expand Down
2 changes: 0 additions & 2 deletions tests-qa/acceptance/ressources/FunctionsGlobal.robot
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ Library libraries/Browser.py timeout=10 implicit_wait=0

Page WithoutWarningOrFailure
Page Should Not Contain Warning:
Page Should Not Contain Failed
Page Should Not Contain Internal Server Error

Variable Without Warning Or Failure
[Arguments] ${body}
Should Not Contain ${body} Warning:
Should Not Contain ${body} Failed
Should Not Contain ${body} Internal Server Error
11 changes: 11 additions & 0 deletions tests-qa/acceptance/ressources/libraries/DateTimeTZ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
__version__ = '0.1'

import pytz
from robot.libraries.DateTime import Date


def datetime_to_utc(date, result_format='timestamp',
date_format=None, exclude_millis=False):
dt = Date(date, date_format)
dt.datetime = dt.datetime.astimezone(pytz.timezone('utc'))
return dt.convert(result_format, millis=not exclude_millis)
1 change: 1 addition & 0 deletions tests-qa/acceptance/ressources/vars/pages/Home.robot
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ${HOME_PICTURE_LIST_PICTURES} ${HOME_PICTURE_LIST_GALERY}//div[con
${HOME_MOVES_PANEL} //*[@id="recentMovesPanel"]
${HOME_LATEST_MOVES_TABLE} ${HOME_MOVES_PANEL}/table
${HOME_NEWS_PANELS} //*[@data-gk-type="news"]
${HOME_RECENTLY_CREATED_GK_TABLE} //*[@id="recentlyCreatedGeokrety"]

${FOOTER_HOME} //*[@id="footer-home"]
${FOOTER_HELP} //*[@id="footer-help"]
Expand Down
2 changes: 1 addition & 1 deletion website/app-templates/smarty/blocks/geokret/details.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<dt>{t}Places visited{/t}</dt>
<dd class="geokret-caches-count">{$geokret->caches_count}</dd>
<dt>{t}Born{/t}</dt>
<dd class="geokret-created-on-datetime">{$geokret->created_on_datetime|print_date nofilter}</dd>
<dd class="geokret-created-on-datetime">{$geokret->born_on_datetime|print_date nofilter}</dd>
{* TODO <dt>{t}Social share{/t}</dt>
<dd>
{fa icon="facebook" title="{t}Share on Facebook{/t}"}
Expand Down
2 changes: 1 addition & 1 deletion website/app-templates/smarty/chunks/geokrety_status.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{if !is_null($geokret->last_log)}
{$geokret->last_log->created_on_datetime|print_date nofilter}
{else}
{$geokret->created_on_datetime|print_date nofilter}
{$geokret->born_on_datetime|print_date nofilter}
{/if}
{/function}
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
{$geokret->last_move|logicon nofilter}
{$geokret->last_move->moved_on_datetime|print_date nofilter}
{else}
{$geokret->created_on_datetime|print_date nofilter}
{$geokret->born_on_datetime|print_date nofilter}
{/if}
</td>
<td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{$geokret->owner|userlink nofilter}
</td>
<td class="text-center" nowrap>
{$geokret->created_on_datetime|print_date nofilter}
{$geokret->born_on_datetime|print_date nofilter}
<br />
</td>
<td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<br />
<small>{$geokret->last_log->author|userlink:$geokret->last_log->username nofilter}</small>
{else}
{$geokret->created_on_datetime|print_date nofilter}
{$geokret->born_on_datetime|print_date nofilter}
{/if}
</td>
<td class="text-right">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<br />
<small>{$geokret->last_position->author|userlink:$geokret->last_position->username nofilter}</small>
{else}
{$geokret->created_on_datetime|print_date nofilter}
{$geokret->born_on_datetime|print_date nofilter}
{/if}
</td>
<td class="text-right">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<br />
<small>{$geokret->last_position->author|userlink:$geokret->last_position->username nofilter}</small>
{else}
{$geokret->created_on_datetime|print_date nofilter}
{$geokret->born_on_datetime|print_date nofilter}
{/if}
</td>
<td class="text-right">
Expand Down
13 changes: 13 additions & 0 deletions website/app-templates/smarty/forms/geokret.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@
</div>
</div>

{if isset($geokret) and $geokret->gkid()}
<div class="form-group">
<label for="born_on_datetime_localized" class="col-sm-2 control-label">{t}Birth date{/t}</label>
<div class="col-sm-6">
<div class="input-group date" id="datetimepicker">
<input type="text" class="form-control" name="born_on_datetime_localized" id="born_on_datetime_localized" required data-parsley-datebeforenow="" data-parsley-trigger="focusout" data-parsley-trigger-after-failure="focusout" />
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
<input type="hidden" name="born_on_datetime" id="born_on_datetime" />
</div>
</div>
{/if}

<div class="form-group">
<label for="inputGeokretType" class="col-sm-2 control-label">{t}GeoKret type{/t}</label>
<div class="col-sm-10">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,7 @@ window.Parsley.addAsyncValidator('checkCoordinates', function(xhr) {
return valid;
}, '{'validate_coordinates'|alias}')

window.Parsley.addValidator('datebeforenow', {
validateString: function(value, format) {
if (! value) {
return true;
}
var date = moment(value, format, true);
if (! date.isValid()) {
return false;
}
return date.isBefore(moment());
},
messages: {
en: 'The date cannot be in the future.',
fr: 'La date ne peut pas etre dans le futur.'
},
priority: 256,
});
{include 'js/parsley/datebeforenow.js'}

window.Parsley.addValidator('dateaftergkbirth', {
validateString: function(value, format) {
Expand Down
19 changes: 19 additions & 0 deletions website/app-templates/smarty/js/parsley/datebeforenow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*global moment*/

window.Parsley.addValidator("datebeforenow", {
validateString: (value, format) => {
if (! value) {
return true;
}
var date = moment(value, format, true);
if (! date.isValid()) {
return false;
}
return date.isBefore(moment());
},
messages: {
en: "The date cannot be in the future.",
fr: "La date ne peut pas etre dans le futur."
},
priority: 256,
});
Loading

0 comments on commit 7415819

Please sign in to comment.