Skip to content

Commit e3125d9

Browse files
committed
Time Tag Now Shows Year For Events With Details Not Within The Current Year
The time tag now displays the year when an event will occur. This is only for events that have been scheduled to start or end in at a future year. The accompanying functional tests have also been included.
1 parent ff1ad8b commit e3125d9

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from django.test import LiveServerTestCase, TestCase
2+
from django.utils import timezone
3+
from selenium.common.exceptions import WebDriverException
4+
from selenium.webdriver import Chrome
5+
6+
from .test_views import EventsViewsTests
7+
from ..models import Event
8+
9+
10+
class EventsPageFunctionalTests(LiveServerTestCase, TestCase):
11+
@classmethod
12+
def setUpClass(cls):
13+
EventsViewsTests().setUpTestData()
14+
super().setUpClass()
15+
cls.now = timezone.now()
16+
17+
def setUp(self) -> None:
18+
try:
19+
self.browser = Chrome()
20+
self.browser.implicitly_wait(5)
21+
except WebDriverException: # GitHub Actions Django CI
22+
from selenium import webdriver
23+
self.browser = webdriver.FirefoxOptions()
24+
self.browser.headless = True
25+
webdriver.Firefox(options=self.browser)
26+
27+
def tearDown(self) -> None:
28+
self.browser.quit()
29+
30+
def test_event_starting_future_year_displays_year(self):
31+
event = Event.objects.get(title=f"Event Starts Following Year")
32+
self.browser.get(self.live_server_url + '/events/')
33+
future_event_span_value = self.browser.find_element_by_id(str(event.id))
34+
self.assertIn(str(event.next_time.dt_start.year), future_event_span_value.text)
35+
36+
def test_event_ending_future_year_displays_year(self):
37+
event = Event.objects.get(title=f"Event Ends Following Year")
38+
self.browser.get(self.live_server_url + '/events/')
39+
future_event_span_value = self.browser.find_element_by_id(str(event.id))
40+
self.assertIn(str(event.next_time.dt_end.year), future_event_span_value.text)
41+
Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
{% if next_time.single_day %}
2-
<time datetime="{{ next_time.dt_start|date:'c' }}">{{ next_time.dt_start|date:"d N" }}<span class="say-no-more"> {{ next_time.dt_start|date:"Y" }}</span>{% if not next_time.all_day %} {{ next_time.dt_start|date:"fA"|lower }} {{ next_time.dt_start|date:"e" }}{% if next_time.valid_dt_end %} – {{ next_time.dt_end|date:"fA"|lower }} {{ next_time.dt_end|date:"e" }}{% endif %}{% endif %}</time>
2+
<time id="{{ object.id }}" datetime="{{ next_time.dt_start|date:'c' }}">{{ next_time.dt_start|date:"d N" }}
3+
<span {% if scheduled_start_this_year %}class="say-no-more"{% endif %}>
4+
{{ next_time.dt_start|date:"Y" }}
5+
</span>
6+
7+
<span {% if scheduled_end_this_year %}class="say-no-more"{% endif %}>
8+
{{ next_time.dt_start|date:"Y" }}
9+
</span>
10+
11+
{% if not next_time.all_day %}
12+
{{ next_time.dt_start|date:"fA"|lower }} {{ next_time.dt_start|date:"e" }}
13+
{% if next_time.valid_dt_end %} – {{ next_time.dt_end|date:"fA"|lower }}
14+
{{ next_time.dt_end|date:"e" }}
15+
{% endif %}
16+
{% endif %}
17+
</time>
318
{% else %}
4-
<time datetime="{{ next_time.dt_start|date:'c' }}">{{ next_time.dt_start|date:"d N" }}{% if next_time.valid_dt_end %} &ndash; {{ next_time.dt_end|date:"d N" }}{% endif %} <span class="say-no-more"> {{ next_time.dt_end|date:"Y" }}</span></time>
19+
<time id="{{ object.id }}" datetime="{{ next_time.dt_start|date:'c' }}">{{ next_time.dt_start|date:"d N" }}
20+
<span {% if scheduled_start_this_year %}class="say-no-more"{% endif %}>
21+
{{ next_time.dt_start|date:"Y" }}
22+
</span>
23+
24+
{% if next_time.valid_dt_end %} &ndash;
25+
{{ next_time.dt_end|date:"d N" }}
26+
{% endif %}
27+
28+
<span {% if scheduled_end_this_year %}class="say-no-more"{% endif %}>
29+
{{ next_time.dt_end|date:"Y" }}
30+
</span>
31+
</time>
532
{% endif %}

0 commit comments

Comments
 (0)