Skip to content

Commit

Permalink
Merge pull request #548 from vigoren/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
vigoren committed Sep 26, 2023
2 parents 2fb730a + f91b19b commit 2586681
Show file tree
Hide file tree
Showing 21 changed files with 328 additions and 205 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Change Log

## 2.4.3 - Bug Fixes

![](https://img.shields.io/badge/release%20date-September%2025%2C%202023-blue)
![GitHub release](https://img.shields.io/github/downloads-pre/vigoren/foundryvtt-simple-calendar/v2.4.3/module.zip)

### Bug Fixes

- Fixed an issue where selecting a date range across multiple months would close the select dialog before the second date could be chosen. ([#547](https://github.com/vigoren/foundryvtt-simple-calendar/issues/547))
- Improved how chat message timestamps are updated for better compatibility with other modules. ([#542](https://github.com/vigoren/foundryvtt-simple-calendar/issues/542))
- Improved how chat message timestamps are displayed for better compatibility with other modules.([#545](https://github.com/vigoren/foundryvtt-simple-calendar/issues/545))

### Translation Updates

Thank you to the follow people for making updates to Simple Calendars translations:

- [Jakub](https://weblate.foundryvtt-hub.com/user/Lioheart/) (Polish)
- [vincent](https://weblate.foundryvtt-hub.com/user/rectulo/) (French)
- [Martin Matoška](https://weblate.foundryvtt-hub.com/user/Mortan/) (Czech)
- [Sven Hesse](https://weblate.foundryvtt-hub.com/user/DrMcCoy/) (German)

<hr/>

## 2.4.0 - Leap Year Starting Year and Bug Fixes

![](https://img.shields.io/badge/release%20date-September%2012%2C%202023-blue)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "foundryvtt-simple-calendar",
"description": "A simple calendar module for keeping track of game days and events.",
"version": "2.4.0",
"version": "2.4.3",
"author": "Dean Vigoren (vigorator)",
"keywords": [
"foundryvtt",
Expand Down
1 change: 1 addition & 0 deletions src/classes/applications/configuration-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export default class ConfigurationApp extends FormApplication {
DateSelectorManager.RemoveSelector(`sc_season_start_date_${s.id}`);
DateSelectorManager.RemoveSelector(`sc_season_sunrise_time_${s.id}`);
});
DateSelectorManager.DeactivateSelector("quick-setup-predefined-calendar");
this.appWindow = null;
return super.close(options);
}
Expand Down
59 changes: 59 additions & 0 deletions src/classes/chat/chat-timestamp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,63 @@ describe("Chat Timestamp Tests", () => {
expect(cm.getFlag).toHaveBeenCalledTimes(1);
expect(ts.style.display).toBe("none");
});

test("Update Chat Message Timestamps", () => {
const chat = document.createElement("div");
chat.id = "chat";
document.body.append(chat);

const li = document.createElement("li");
li.dataset.messageId = "a";
chat.append(li);

const fTime = document.createElement("time");
const scTime = document.createElement("span");

//@ts-ignore
const cqsa = jest.spyOn(chat, "querySelectorAll").mockReturnValue([li]);
const liqsa = jest.spyOn(li, "querySelector").mockReturnValue(fTime);
//@ts-ignore
game.messages = {
get: jest.fn((id: string) => {
return { id: id };
})
};
jest.spyOn(ChatTimestamp, "getFormattedChatTimestamp").mockReturnValue("test");

// Show Foundries timestamp
ChatTimestamp.updateChatMessageTimestamps();
expect(cqsa).toHaveBeenCalledTimes(1);
expect(liqsa).toHaveBeenCalledTimes(2);
expect(fTime.style.display).toBe("");

// Create SC timestamp
liqsa.mockReturnValueOnce(fTime).mockReturnValueOnce(null);
SC.globalConfiguration.inGameChatTimestamp = true;
ChatTimestamp.updateChatMessageTimestamps();
expect(cqsa).toHaveBeenCalledTimes(2);
expect(liqsa).toHaveBeenCalledTimes(4);
expect(fTime.style.display).toBe("none");

// Update SC timestamp
liqsa.mockReturnValueOnce(fTime).mockReturnValueOnce(scTime);
ChatTimestamp.updateChatMessageTimestamps();
expect(cqsa).toHaveBeenCalledTimes(3);
expect(liqsa).toHaveBeenCalledTimes(6);
expect(fTime.style.display).toBe("none");
expect(scTime.innerText).toBe("test");

// FTime doesn't exist
liqsa.mockReturnValueOnce(null).mockReturnValueOnce(scTime);
ChatTimestamp.updateChatMessageTimestamps();
expect(cqsa).toHaveBeenCalledTimes(4);
expect(liqsa).toHaveBeenCalledTimes(8);
expect(scTime.innerText).toBe("test");

//No dataset id
li.dataset.messageId = "";
ChatTimestamp.updateChatMessageTimestamps();
expect(cqsa).toHaveBeenCalledTimes(5);
expect(liqsa).toHaveBeenCalledTimes(10);
});
});
32 changes: 32 additions & 0 deletions src/classes/chat/chat-timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,36 @@ export class ChatTimestamp {
}
}
}

public static updateChatMessageTimestamps() {
const chat = document.getElementById("chat");
if (chat) {
chat.querySelectorAll("#chat-log .message").forEach((li) => {
const message = (<Game>game).messages?.get((<HTMLElement>li).dataset.messageId || "");
if (message) {
const formattedDateTime = this.getFormattedChatTimestamp(message);
const foundryTime = li.querySelector(".message-header .message-metadata .message-timestamp");
const stamp = <HTMLElement>li.querySelector(".sc-timestamp");
if (formattedDateTime && foundryTime) {
if (SC.globalConfiguration.inGameChatTimestamp) {
(<HTMLElement>foundryTime).style.display = "none";
if (stamp) {
stamp.innerText = formattedDateTime;
} else {
const newTime = document.createElement("time");
newTime.classList.add("sc-timestamp");
newTime.innerText = formattedDateTime;
foundryTime.after(newTime);
}
} else {
(<HTMLElement>foundryTime).style.display = "";
stamp?.remove();
}
} else if (formattedDateTime && stamp) {
stamp.innerText = formattedDateTime;
}
}
});
}
}
}
63 changes: 36 additions & 27 deletions src/classes/date-selector/date-selector-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,76 @@
* @jest-environment jsdom
*/
import "../../../__mocks__/index";
import {jest, beforeEach, describe, expect, test} from '@jest/globals';
import { jest, beforeEach, describe, expect, test } from "@jest/globals";

import DateSelectorManager from "./date-selector-manager";
import {DateSelector} from "./index";
import { DateSelector } from "./index";
import Calendar from "../calendar";
import {CalManager, updateCalManager} from "../index";
import { CalManager, updateCalManager } from "../index";
import CalendarManager from "../calendar/calendar-manager";


describe('Date Selector Manager Class Tests', () => {
describe("Date Selector Manager Class Tests", () => {
let tCal: Calendar;
let ds: DateSelector
let ds: DateSelector;

beforeEach(()=>{
beforeEach(() => {
updateCalManager(new CalendarManager());
tCal = new Calendar('','');
jest.spyOn(CalManager, 'getActiveCalendar').mockImplementation(() => {return tCal;});
tCal = new Calendar("", "");
jest.spyOn(CalManager, "getActiveCalendar").mockImplementation(() => {
return tCal;
});
DateSelectorManager.Selectors = {};
ds = DateSelectorManager.GetSelector('test', {showDateSelector: true, showTimeSelector: true});
ds = DateSelectorManager.GetSelector("test", { showDateSelector: true, showTimeSelector: true });
});

test('Get Selector', () => {
let newDs = DateSelectorManager.GetSelector('test2', {
test("Get Selector", () => {
let newDs = DateSelectorManager.GetSelector("test2", {
showDateSelector: true,
showTimeSelector: true,
allowDateRangeSelection: true,
onDateSelect: () => {},
timeDelimiter: '/',
timeDelimiter: "/",
showCalendarYear: false,
timeSelected: false,
allowTimeRangeSelection: true,
selectedStartDate: {year: 0, month: 1, day: 1, hour: 0, minute: 0, seconds: 0},
selectedEndDate: {year: 0, month: 1, day: 1, hour: 0, minute: 0, seconds: 0}
selectedStartDate: { year: 0, month: 1, day: 1, hour: 0, minute: 0, seconds: 0 },
selectedEndDate: { year: 0, month: 1, day: 1, hour: 0, minute: 0, seconds: 0 }
});
expect(newDs.id).toBe('test2');
expect(newDs.id).toBe("test2");
expect(newDs.allowDateRangeSelection).toBe(true);
expect(newDs.onDateSelect ).not.toBeNull();
expect(newDs.onDateSelect).not.toBeNull();
expect(Object.keys(DateSelectorManager.Selectors).length).toBe(2);

newDs = DateSelectorManager.GetSelector('test', {
newDs = DateSelectorManager.GetSelector("test", {
showDateSelector: true,
showTimeSelector: true,
selectedStartDate: {year: 1, month: 1, day: 1, hour: 0, minute: 0, seconds: 0},
selectedEndDate: {year: 1, month: 1, day: 1, hour: 0, minute: 0, seconds: 0}
selectedStartDate: { year: 1, month: 1, day: 1, hour: 0, minute: 0, seconds: 0 },
selectedEndDate: { year: 1, month: 1, day: 1, hour: 0, minute: 0, seconds: 0 }
});
expect(newDs).toStrictEqual(ds);
});

test('Remove Selector', () => {
test("Remove Selector", () => {
expect(Object.keys(DateSelectorManager.Selectors).length).toBe(1);
DateSelectorManager.RemoveSelector('no');
DateSelectorManager.RemoveSelector("no");
expect(Object.keys(DateSelectorManager.Selectors).length).toBe(1);
DateSelectorManager.RemoveSelector('test');
DateSelectorManager.RemoveSelector("test");
expect(Object.keys(DateSelectorManager.Selectors).length).toBe(0);
});

test('Activate Selector', () => {
jest.spyOn(ds, 'activateListeners').mockImplementation(() => {});
DateSelectorManager.ActivateSelector('no');
test("Activate Selector", () => {
jest.spyOn(ds, "activateListeners").mockImplementation(() => {});
DateSelectorManager.ActivateSelector("no");
expect(ds.activateListeners).not.toHaveBeenCalled();
DateSelectorManager.ActivateSelector('test');
DateSelectorManager.ActivateSelector("test");
expect(ds.activateListeners).toHaveBeenCalledTimes(1);
});

test("Deactivate Selector", () => {
jest.spyOn(ds, "deactivateListeners").mockImplementation(() => {});
DateSelectorManager.DeactivateSelector("no");
expect(ds.deactivateListeners).not.toHaveBeenCalled();
DateSelectorManager.DeactivateSelector("test");
expect(ds.deactivateListeners).toHaveBeenCalledTimes(1);
});
});
7 changes: 7 additions & 0 deletions src/classes/date-selector/date-selector-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class DateSelectorManager {
*/
static RemoveSelector(id: string) {
if (Object.prototype.hasOwnProperty.call(this.Selectors, id)) {
this.Selectors[id].deactivateListeners();
delete this.Selectors[id];
}
}
Expand All @@ -42,4 +43,10 @@ export default class DateSelectorManager {
this.Selectors[id].activateListeners();
}
}

static DeactivateSelector(id: string) {
if (Object.prototype.hasOwnProperty.call(this.Selectors, id)) {
this.Selectors[id].deactivateListeners();
}
}
}
Loading

0 comments on commit 2586681

Please sign in to comment.