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

Feature/3849 historical numbers new #2421

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8287489
reinstate weekly PDD schedule
Steven-Eardley Sep 25, 2024
f43bd51
Merge branch 'hotfix/2024-09-25_iss3970_reinstate_pdd_schedule'
Steven-Eardley Sep 25, 2024
bcb1089
implementation for historical numbers
RK206 Jun 25, 2024
0e7b3c2
add banners text
amdomanska Jun 25, 2024
218884e
add top banner
amdomanska Jun 25, 2024
f73ff70
tiny scss adjustment
amdomanska Jun 25, 2024
3e2fbdf
generate banner text randomly
amdomanska Jun 25, 2024
c8517bd
read cms data from the template rather than directly
amdomanska Jun 25, 2024
a1703f8
refactor the renderGroupInfo function in dashboard
amdomanska Jun 26, 2024
ec85d0f
move activities to includes file
amdomanska Jun 28, 2024
44d84fb
add historical statistics
amdomanska Jun 28, 2024
5436de9
remove js-yaml
amdomanska Jun 28, 2024
ad23cfe
remove commented out code
amdomanska Jun 28, 2024
06fb3b3
start testdrive implementation
amdomanska Jun 28, 2024
c8d0ddb
add helpers class
amdomanska Jul 1, 2024
47dc49b
Add testdrive
amdomanska Jul 3, 2024
8910628
add functional tests
amdomanska Jul 3, 2024
0498269
small change to functional tests
amdomanska Jul 3, 2024
94134c1
fixes to testdrive
amdomanska Jul 3, 2024
0307794
change name of variable
amdomanska Jul 3, 2024
45a5953
fix tab behaviour
amdomanska Jul 9, 2024
898ac77
remove accidental csv files
amdomanska Jul 9, 2024
36d39cf
remove accidental file
amdomanska Jul 9, 2024
398524d
add unassigned fragment to 'by editor' list
amdomanska Jul 29, 2024
7adf2f2
a bit of code tidy up
richard-jones Sep 5, 2024
bdabd30
minor wording change to motivational banner
richard-jones Sep 5, 2024
1c66a71
display 0 for groups with no apps
amdomanska Sep 12, 2024
2ef0d53
remove package json files
amdomanska Sep 12, 2024
4fa5415
rm unnecessary file
amdomanska Sep 12, 2024
6543693
rm unnecessary file
amdomanska Sep 12, 2024
1a51957
correct historical statistics functional test for admin
amdomanska Sep 12, 2024
73b32a0
ensure index consistency in statistics testdrive
amdomanska Sep 12, 2024
9e051dc
Refactor methods names
amdomanska Sep 12, 2024
f8b920e
check for hs being none
amdomanska Sep 12, 2024
5c6a9a5
dont display the header of a by status graph if no applications and a…
amdomanska Oct 1, 2024
45ac7a2
fix the name vs id bug
amdomanska Oct 1, 2024
a8c00d0
move file
amdomanska Oct 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cms/data/motivational_banners.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
banners:
zero_count:
- "You haven't completed any applications this year yet. Start by choosing one from
the list below."
positive_count:
- "Whoa! {{ COUNT }} applications already? You’re crushing it!"
- "{{ COUNT }} applications down already? You’re on fire! Keep it up, superstar!"
- "{{ COUNT }} applications down, many more to go! Keep rocking!"
- "{{ COUNT }} applications completed? You’re making it look easy!"
- "{{ COUNT }} applications down and still going strong!"
- "Wait, you’ve completed {{ COUNT }} applications this year already? You’re on fire!"
- "Impressive! You’ve already completed {{ COUNT }} applications this year!"
- "{{ COUNT }} applications in the bag this year! You’re smashing it!"
- "Congratulations, you have completed {{ COUNT }} applications this year so far! Keep it up!"
8 changes: 8 additions & 0 deletions cms/sass/components/_alert.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
border: 2px solid $grapefruit;
}

&--success {
border: 2px solid $dark-green;
}

&--info {
border: 2px solid $dark-grey;
}

code {
background-color: rgba($dark-grey, 0.1);
}
Expand Down
13 changes: 13 additions & 0 deletions cms/sass/components/_motivational-banner.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.motivational-banner {
width: 100%;

h3 {
text-align: center;
margin-bottom: 0;

.tag {
margin: 0 $spacing-02;
}
}

}
1 change: 1 addition & 0 deletions cms/sass/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"components/loading",
"components/logo",
"components/modal",
"components/motivational-banner",
"components/notifications",
"components/numbered-table",
"components/pager-buttons",
Expand Down
94 changes: 94 additions & 0 deletions doajtest/testbook/dashboard/historical_stats.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
suite: Dashboard
testset: Historical Statistics
tests:
- title: Historical Statistics Display - Managing Editor with 3 groups
context:
role: admin
testdrive: statistics
steps:
- step: Navigate to "/testdrive/statistics" and wait for the page to load slowly. This should be done once at the beginning of the test session and not refreshed between individual tests.
- step: Log in with provided managing_editor credentials.
results:
- User dashboard is displayed.
- step: Verify historical statistics in the Activity section at the bottom.
results:
- Three groups are displayed.
- Only associate editors are shown in the Activity section for each group.
- Each group has the correct statistics for the current year.
- The number of READY/COMPLETED applications matches the "additional information" table.
- step: Log out.
- step: (Optional) Click the link at the bottom of the testdrive page to free resources after finishing this test session.
- title: Historical Statistics Display - Editor with 2 groups
context:
role: editor
testdrive: statistics
steps:
- step: Navigate to "/testdrive/statistics" and wait for the page to load slowly. This should be done once at the beginning of the test session and not refreshed between individual tests.
- step: Log in with provided editor_1 credentials.
results:
- User dashboard is displayed.
- step: Verify the motivational banner at the top of the dashboard (green) and check number of finished applications.
results:
- The motivational banner is GREEN and shows the correct sum of applications finished in both groups.
- step: Verify historical statistics in the Activity section at the bottom.
results:
- Two groups are displayed.
- Only associate editors are shown in the Activity section for each group.
- Each group has the correct statistics for the current year.
- The number of READY/COMPLETED applications matches the "additional information" table.
- step: Log out.
- step: (Optional) Click the link at the bottom of the testdrive page to free resources after finishing this test session.
- title: Historical Statistics Display - Editor with 1 group
context:
role: editor
testdrive: statistics
steps:
- step: Navigate to "/testdrive/statistics" and wait for the page to load slowly. This should be done once at the beginning of the test session and not refreshed between individual tests.
- step: Log in with provided editor_2 credentials.
results:
- User dashboard is displayed.
- step: Verify the motivational banner at the top of the dashboard (green) and check number of finished applications.
results:
- The motivational banner is GREEN and shows the correct sum of applications finished in the group.
- step: Verify historical statistics in the Activity section at the bottom.
results:
- One group is displayed.
- Only associate editors are shown in the Activity section for the group.
- The group has the correct statistics for the current year.
- The number of READY/COMPLETED applications matches the "additional information" table.
- step: Log out.
- step: (Optional) Click the link at the bottom of the testdrive page to free resources after finishing this test session.
- title: Historical Statistics Display - Associate Editors with 0 finished applications
context:
role: associate editor
testdrive: statistics
steps:
- step: Navigate to "/testdrive/statistics" and wait for the page to load slowly. This should be done once at the beginning of the test session and not refreshed between individual tests.
- step: Log in with provided associate_editor_1 credentials.
results:
- User dashboard is displayed.
- step: Verify the motivational banner at the top of the dashboard (grey).
results:
- The motivational banner is GREY with appropriate information about no finished applications.
- step: Verify no statistics are displayed at the bottom of the page.
results:
- No statistics are displayed in the Activity section.
- step: Log out.
- step:
- title: Historical Statistics Display - Associate Editor 2
context:
role: associate editor
testdrive: statistics
steps:
- step: Navigate to "/testdrive/statistics" and wait for the page to load slowly. This should be done once at the beginning of the test session and not refreshed between individual tests.
- step: Log in with provided associate_editor_2 credentials.
results:
- User dashboard is displayed.
- step: Verify the motivational banner at the top of the dashboard (green).
results:
- The motivational banner is GREEN.
- step: Verify no statistics are displayed at the bottom of the page.
results:
- No statistics are displayed in the Activity section.
- step: Log out.
- step: (Optional) Click the link at the bottom of the testdrive page to free resources after finishing this test session.
201 changes: 201 additions & 0 deletions doajtest/testdrive/statistics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
from doajtest.testdrive.factory import TestDrive
from portality import constants
from portality import models
from doajtest.fixtures import EditorGroupFixtureFactory
import string
import random
import json

class Statistics(TestDrive):
"""
Creates a group structure for statistics testdrive:
3 groups, each with the same Man Ed, 2 groups with the same editor, each with different number of AssEds
"""

NUMBER_OF_GROUPS = 3
NUMBER_OF_EDITORS = 2
NUMBER_OF_ASSEDITORS = 8

FINISHED_APPLICATIONS = [
{'role': 'editor', 'group': 0, 'index': 0, 'count': 2},
{'role': 'editor', 'group': 1, 'index': 0, 'count': 3},
{'role': 'editor', 'group': 2, 'index': 1, 'count': 3},
{'role': 'assed', 'group': 0, 'index': 0, 'count': 0},
{'role': 'assed', 'group': 0, 'index': 1, 'count': 4},
{'role': 'assed', 'group': 1, 'index': 2, 'count': 0},
{'role': 'assed', 'group': 1, 'index': 3, 'count': 5},
{'role': 'assed', 'group': 1, 'index': 4, 'count': 3},
{'role': 'assed', 'group': 2, 'index': 5, 'count': 7},
{'role': 'assed', 'group': 2, 'index': 6, 'count': 4},
{'role': 'assed', 'group': 2, 'index': 7, 'count': 2},
]

# Define editor groups and associate editors' associations
EDITOR_GROUPS = {
'eg0': {'editor_index': 0, 'start_assed_index': 0, 'end_assed_index': 2},
'eg1': {'editor_index': 0, 'start_assed_index': 2, 'end_assed_index': 5},
'eg2': {'editor_index': 1, 'start_assed_index': 5, 'end_assed_index': 8},
}

def setup(self) -> dict:
self.createAccounts()
self.createGroups()
self.createProvenanceData()
return {
"admin": {
"username": self.admin,
"password": self.admin_pass
},
"editor_1": {
"username": self.editors[0]["id"],
"password": self.editors[0]["pass"]
},
"editor_2": {
"username": self.editors[1]["id"],
"password": self.editors[1]["pass"]
},
"associate_editor_1": {
"username": self.asseds[0]["id"],
"password": self.asseds[0]["pass"]
},
"associate_editor_2": {
"username": self.asseds[1]["id"],
"password": self.asseds[1]["pass"]
},
"finished_applications": self.finished_by_user,
"non_renderable": {
"asseds": [assed['id'] for assed in
self.asseds[2:]],
"groups": self.groups,
"provenance": self.provenance_data
}
}

def create_random_str(self, n_char=10):
s = string.ascii_letters + string.digits
return ''.join(random.choices(s, k=n_char))

def createAccounts(self):
un = self.create_random_str()
pw1 = self.create_random_str()
admin = models.Account.make_account(un + "@example.com", un, "Admin " + un, [constants.ROLE_ADMIN])
admin.set_password(pw1)
admin.save()
self.admin = admin.id
self.admin_pass = pw1

# Create editors accounts
self.editors = []
for i in range(self.NUMBER_OF_EDITORS):
us = self.create_random_str()
pw = self.create_random_str()
editor = models.Account.make_account(us + "@example.com", us, "Editor" + str(i+1) + " " + us,
[constants.ROLE_EDITOR])
editor.set_password(pw)
editor.save()
self.editors.append({"id": editor.id, "pass": pw})

# Create associate editors accounts
self.asseds = []
for i in range(self.NUMBER_OF_ASSEDITORS):
us = self.create_random_str()
pw = self.create_random_str()
assed = models.Account.make_account(us + "@example.com", us, "AssEd" + str(i+1) + " " + us,
[constants.ROLE_ASSOCIATE_EDITOR])
assed.set_password(pw)
assed.save()
self.asseds.append({"id": assed.id, "pass": pw})

def createGroups(self):

self.groups = []
for group_key, group_info in self.EDITOR_GROUPS.items():
eg_source = EditorGroupFixtureFactory.make_editor_group_source(group_name=group_key, maned=self.admin,
editor=
self.editors[group_info['editor_index']][
"id"])
del eg_source["associates"] # these will be added in a moment
editor_group = models.EditorGroup(**eg_source)
editor_group.set_id(group_key)
ids_to_set = [assed['id'] for assed in
self.asseds[group_info['start_assed_index']:group_info['end_assed_index']]]
editor_group.set_associates(ids_to_set)
editor_group.save()
self.groups.append(editor_group.id)

def createProvenanceData(self):

self.finished_by_user = {}
self.provenance_data = []
role_mapping = {
"editor": {
"array": self.editors,
"status": constants.APPLICATION_STATUS_READY
},
"assed": {
"array": self.asseds,
"status": constants.APPLICATION_STATUS_COMPLETED
}
}

for entry in self.FINISHED_APPLICATIONS:
role = entry["role"]
idx = entry['index']
count = entry['count']
group_key = "eg" + str(entry['group'])

users = role_mapping[role]["array"]
app_status = role_mapping[role]["status"]

status = "status:" + app_status
user_id = users[idx]["id"]
user_name_with_eg = user_id + " (" + role + " in " + group_key + ")"

self.finished_by_user[user_name_with_eg] = str(count)

for i in range(count):
p = self.add_provenance_record(status, role, user_id, group_key)
self.provenance_data.append(p.id)

def add_provenance_record(self, status, role, user, editor_group):
data = {
"user": user,
"roles": [role],
"type": "suggestion",
"action": status,
"editor_group": [editor_group]
}
p = models.Provenance(**data)
p.save()
print(p.id)
return p

def teardown(self, params):
for key, obj in params.items():
print(key)
if key != "non_renderable" and key != "finished_applications":
models.Account.remove_by_id(obj["username"])

non_renderable = params.get("non_renderable", {})

for assed in non_renderable.get("asseds", []):
models.Account.remove_by_id(assed)

for provenance_id in non_renderable.get("provenance", []):
models.Provenance.remove_by_id(provenance_id)

for group in non_renderable.get("groups", []):
models.Provenance.remove_by_id(group)

return {"success": True}


if __name__ == "__main__":
structure = Statistics()
params = structure.setup()
print(structure.admin)
print(structure.editors)
print(structure.asseds)
print(structure.groups)
print(structure.provenance_data)
structure.teardown(params)
Loading
Loading