Skip to content

Commit

Permalink
Use calendarStore over entryStore (#1096)
Browse files Browse the repository at this point in the history
  • Loading branch information
tupaschoal authored Dec 26, 2024
1 parent 97e2a42 commit f67d281
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 70 deletions.
6 changes: 3 additions & 3 deletions __tests__/__main__/import-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ describe('Import export', function()
});
});

const entryStore = new Store({name: 'flexible-store'});
const calendarStore = new Store({name: 'flexible-store'});
const waivedWorkdays = new Store({name: 'waived-workdays'});

entryStore.clear();
calendarStore.clear();
const entries = {
'2020-3-1': {'values': ['08:00', '12:00', '13:00', '17:00']},
'2020-3-2': {'values': ['07:00', '11:00', '14:00', '18:00']}
};
entryStore.set(entries);
calendarStore.set(entries);

waivedWorkdays.clear();
const waivedEntries = {
Expand Down
42 changes: 21 additions & 21 deletions __tests__/__main__/time-balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {
} from '../../js/time-balance.js';
import { resetPreferences } from '../../js/user-preferences.js';

const entryStore = new Store({name: 'flexible-store'});
const calendarStore = new Store({name: 'flexible-store'});
const waivedWorkdays = new Store({name: 'waived-workdays'});

describe('Time Balance', () =>
{
beforeEach(() =>
{
entryStore.clear();
calendarStore.clear();
waivedWorkdays.clear();
resetPreferences();
});
Expand All @@ -32,7 +32,7 @@ describe('Time Balance', () =>
const entryEx = {
'2020-3-1': {'values': ['08:00']}
};
entryStore.set(entryEx);
calendarStore.set(entryEx);
assert.strictEqual(getFirstInputInDb(), '2020-3-1');
});

Expand All @@ -42,7 +42,7 @@ describe('Time Balance', () =>
'2020-3-1': {'values': ['08:00']},
'2020-3-3': {'values': ['08:00']}
};
entryStore.set(entryEx);
calendarStore.set(entryEx);
assert.strictEqual(getFirstInputInDb(), '2020-3-1');
});

Expand All @@ -53,7 +53,7 @@ describe('Time Balance', () =>
'2020-3-3': {'values': ['08:00']},
'2020-2-1': {'values': ['08:00']}
};
entryStore.set(entryEx);
calendarStore.set(entryEx);
assert.strictEqual(getFirstInputInDb(), '2020-2-1');
});

Expand All @@ -66,7 +66,7 @@ describe('Time Balance', () =>
'2020-6-9': {'values': ['10:00', '12:00', '13:00', '22:00']},
'2020-6-10': {'values': ['08:00', '12:00', '13:00', '19:00']}
};
entryStore.set(entryEx);
calendarStore.set(entryEx);
assert.strictEqual(getFirstInputInDb(), '2020-6-6');
});

Expand All @@ -80,7 +80,7 @@ describe('Time Balance', () =>
const entryEx = {
'2020-6-1': {'values': ['08:00', '12:00', '13:00', '17:00']} // wed (8h total)
};
entryStore.set(entryEx);
calendarStore.set(entryEx);
// time balance until thu (excluding thu)
await expect(computeAllTimeBalanceUntil(new Date(2020, 6, 2))).resolves.toBe('00:00');
// time balance until fri (excluding fri)
Expand All @@ -100,7 +100,7 @@ describe('Time Balance', () =>
const entryEx = {
'2020-6-1': {'values': ['08:00', '12:00', '17:00', '13:00']} // wed (8h total)
};
entryStore.set(entryEx);
calendarStore.set(entryEx);
// time balance until thu (excluding thu)
await expect(computeAllTimeBalanceUntil(new Date(2020, 6, 2))).resolves.toBe('-08:00');
// time balance until fri (excluding fri)
Expand All @@ -120,7 +120,7 @@ describe('Time Balance', () =>
const entryEx = {
'2020-6-1': {'values': ['08:00', '10:00', '10:30', '11:30', '13:00', '17:00']} // wed (7h total)
};
entryStore.set(entryEx);
calendarStore.set(entryEx);
// time balance until thu (excluding thu)
await expect(computeAllTimeBalanceUntil(new Date(2020, 6, 2))).resolves.toBe('-01:00');
// time balance until fri (excluding fri)
Expand All @@ -140,7 +140,7 @@ describe('Time Balance', () =>
const entryEx = {
'2020-6-1': {'values': ['08:00', '12:00', '13:00', '18:30']} // wed (9h30 total)
};
entryStore.set(entryEx);
calendarStore.set(entryEx);
// time balance until thu (excluding thu)
await expect(computeAllTimeBalanceUntil(new Date(2020, 6, 2))).resolves.toBe('01:30');
// time balance until fri (excluding fri)
Expand All @@ -154,7 +154,7 @@ describe('Time Balance', () =>
const entryEx = {
'2020-6-1': {'values': ['06:00', '12:00', '13:00', '14:00', '14:30', '16:00', '17:00', '18:30']} // wed (10h total)
};
entryStore.set(entryEx);
calendarStore.set(entryEx);
// time balance until thu (excluding thu)
await expect(computeAllTimeBalanceUntil(new Date(2020, 6, 2))).resolves.toBe('02:00');
// time balance until fri (excluding fri)
Expand All @@ -168,7 +168,7 @@ describe('Time Balance', () =>
const entryEx = {
'2020-6-1': {'values': ['08:00', '12:00', '13:00', '15:15']} // wed (6h15 total)
};
entryStore.set(entryEx);
calendarStore.set(entryEx);
// time balance until thu (excluding thu)
await expect(computeAllTimeBalanceUntil(new Date(2020, 6, 2))).resolves.toBe('-01:45');
// time balance until fri (excluding fri)
Expand All @@ -184,7 +184,7 @@ describe('Time Balance', () =>
'2020-6-2': {'values': ['08:00', '12:00', '13:00', '18:15']}, // thu (9h15 total)
'2020-6-3': {'values': ['08:00', '12:00', '13:00', '15:15']} // fri (6h15 total)
};
entryStore.set(entryEx);
calendarStore.set(entryEx);
// time balance until thu (excluding thu)
await expect(computeAllTimeBalanceUntil(new Date(2020, 6, 2))).resolves.toBe('-01:45');
// time balance until fri (excluding fri)
Expand All @@ -203,7 +203,7 @@ describe('Time Balance', () =>
'2020-6-10': {'values': ['08:00', '12:00', '13:00', '15:00', '17:00']}, // fri (odd #entries, day is not considered => -8h)[-20h]
'2020-6-13': {'values': ['00:00', '18:00']}, // mon (18h/+10h)[-10h]
};
entryStore.set(entryEx);
calendarStore.set(entryEx);
// time balance until mon (excluding mon)
await expect(computeAllTimeBalanceUntil(new Date(2020, 6, 6))).resolves.toBe('00:00');
// time balance until tue (excluding tue)
Expand Down Expand Up @@ -232,7 +232,7 @@ describe('Time Balance', () =>
'2020-6-10': {'values': ['08:00', '12:00', '13:00', '15:00']}, // fri (even #entries, and > 4 => only up to '15:00' => 6h/-2h)[-10h]
'2020-6-13': {'values': ['00:00', '18:00']}, // mon (18h/+10h)[0h]
};
entryStore.set(entryEx);
calendarStore.set(entryEx);
// time balance until mon (excluding mon)
await expect(computeAllTimeBalanceUntil(new Date(2020, 6, 6))).resolves.toBe('00:00');
// time balance until tue (excluding tue)
Expand All @@ -257,7 +257,7 @@ describe('Time Balance', () =>
'2020-6-1': {'values': ['08:00', '12:00', '13:00', '17:00']}, // wed (8h total)
'2020-6-3': {'values': ['08:00', '12:00', '13:00', '17:00']} // fri (8h total)
};
entryStore.set(entryEx);
calendarStore.set(entryEx);
// time balance until thu (excluding thu)
await expect(computeAllTimeBalanceUntil(new Date(2020, 6, 2))).resolves.toBe('00:00');
// time balance until fri (excluding fri)
Expand All @@ -274,7 +274,7 @@ describe('Time Balance', () =>
'2020-6-1': {'values': ['08:00', '12:00', '13:00', '17:00']}, // wed (8h total)
'2020-6-3': {'values': ['08:00', '12:00', '13:00', '17:00']} // fri (8h total)
};
entryStore.set(entryEx);
calendarStore.set(entryEx);
const waivedEntries = {
'2020-07-02': { reason: 'Waiver', hours: '08:00' }, // thu
};
Expand All @@ -292,7 +292,7 @@ describe('Time Balance', () =>
const entryEx = {
'2020-6-8': {'values': ['08:00', '12:00', '13:00', '17:00']} // wed (8h total)
};
entryStore.set(entryEx);
calendarStore.set(entryEx);
const waivedEntries = {
'2020-07-09': { reason: 'Waiver', hours: '08:00' }, // tue
'2020-07-10': { reason: 'Waiver', hours: '08:00' }, // fri
Expand All @@ -314,7 +314,7 @@ describe('Time Balance', () =>
'2020-6-1': {'values': ['08:00', '12:00', '13:00', '17:00']}, // wed (8h total)
'2020-6-3': {'values': ['08:00', '12:00', '13:00', '17:00']} // fri (8h total)
};
entryStore.set(entryEx);
calendarStore.set(entryEx);
const waivedEntries = {
'2020-07-02': { reason: 'Waiver', hours: '02:00' }, // tue
};
Expand All @@ -333,7 +333,7 @@ describe('Time Balance', () =>
'2020-6-1': {'values': ['08:00', '12:00', '13:00', '17:00']}, // wed (8h total)
'2020-6-3': {'values': ['08:00', '12:00', '13:00', '17:00']} // fri (8h total)
};
entryStore.set(entryEx);
calendarStore.set(entryEx);
const waivedEntries = {
'2020-07-02': { reason: 'Waiver', hours: '02:00' }, // tue
};
Expand All @@ -347,7 +347,7 @@ describe('Time Balance', () =>
'2020-6-1': {'values': ['08:00', '12:00', '13:00', '17:00']}, // wed (8h total)
'2020-6-3': {'values': ['08:00', '12:00', '13:00', '17:00']} // fri (8h total)
};
entryStore.set(entryEx);
calendarStore.set(entryEx);
const waivedEntries = {
'2020-07-02': { reason: 'Waiver', hours: '02:00' }, // tue
};
Expand Down
18 changes: 9 additions & 9 deletions __tests__/__renderer__/classes/BaseCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ describe('BaseCalendar.js', () =>
const mocks = {};
beforeEach(() =>
{
const entryStore = new Store({name: 'flexible-store'});
entryStore.clear();
const calendarStore = new Store({name: 'flexible-store'});
calendarStore.clear();
const waivedWorkdays = new Store({name: 'waived-workdays'});
waivedWorkdays.clear();
ExtendedClass.prototype._initCalendar = () => {};
Expand All @@ -60,7 +60,7 @@ describe('BaseCalendar.js', () =>
{
return new Promise((resolve) =>
{
resolve(entryStore.store);
resolve(calendarStore.store);
});
};
window.mainApi.getWaiverStoreContents = () =>
Expand All @@ -72,7 +72,7 @@ describe('BaseCalendar.js', () =>
};
window.mainApi.setStoreData = (key, contents) =>
{
entryStore.set(key, contents);
calendarStore.set(key, contents);
return new Promise((resolve) =>
{
resolve(true);
Expand Down Expand Up @@ -122,8 +122,8 @@ describe('BaseCalendar.js', () =>
test('Should build with default internal store values', async(done) =>
{
ExtendedClass.prototype._initCalendar = () => { done(); };
const entryStore = new Store({name: 'flexible-store'});
entryStore.set('flexible', 'store');
const calendarStore = new Store({name: 'flexible-store'});
calendarStore.set('flexible', 'store');

const waivedWorkdays = new Store({name: 'waived-workdays'});
waivedWorkdays.set('2022-01-01', {
Expand Down Expand Up @@ -465,11 +465,11 @@ describe('BaseCalendar.js', () =>

test('Should update when day has ended', async() =>
{
const entryStore = new Store({name: 'flexible-store'});
const calendarStore = new Store({name: 'flexible-store'});
const newDate = new Date();
const key = generateKey(newDate.getFullYear(), newDate.getMonth(), newDate.getDate());
entryStore.set(key, '08:00');
entryStore.set(key, '16:00');
calendarStore.set(key, '08:00');
calendarStore.set(key, '16:00');
$('body').append(`<div id="${key}" ></div>`);
$('body').append('<div class="day-total-cell" ><span>--:--</span></div>');
$(`#${key}`).append('<input type="time" value="08:00" />');
Expand Down
18 changes: 9 additions & 9 deletions __tests__/__renderer__/classes/DayCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ jest.mock('../../../renderer/i18n-translator.js', () => ({

const languageData = {'language': 'en', 'data': {'dummy_string': 'dummy_string_translated'}};

const entryStore = new Store({name: 'flexible-store'});
const calendarStore = new Store({name: 'flexible-store'});
const waivedWorkdays = new Store({name: 'waived-workdays'});

window.mainApi.getStoreContents = () => { return new Promise((resolve) => { resolve(entryStore.store); }); };
window.mainApi.getStoreContents = () => { return new Promise((resolve) => { resolve(calendarStore.store); }); };
window.mainApi.getWaiverStoreContents = () => { return new Promise((resolve) => resolve(waivedWorkdays.store)); };
window.mainApi.setStoreData = (key, contents) =>
{
return new Promise((resolve) =>
{
entryStore.set(key, contents);
calendarStore.set(key, contents);
resolve(true);
});
};
window.mainApi.deleteStoreData = (key) =>
{
return new Promise((resolve) =>
{
entryStore.delete(key);
calendarStore.delete(key);
resolve(true);
});
};
Expand All @@ -65,12 +65,12 @@ describe('DayCalendar class Tests', () =>
{
process.env.NODE_ENV = 'test';

entryStore.clear();
calendarStore.clear();
const regularEntries = {
'2020-3-1': {'values': ['08:00', '12:00', '13:00', '17:00']},
'2020-3-2': {'values': ['10:00', '18:00']}
};
entryStore.set(regularEntries);
calendarStore.set(regularEntries);

waivedWorkdays.clear();
const waivedEntries = {
Expand Down Expand Up @@ -113,22 +113,22 @@ describe('DayCalendar class Tests', () =>
expect(calendar._getStore('2010-3-1')).toStrictEqual([]);

expect(Object.keys(calendar._internalStore).length).toStrictEqual(2);
expect(entryStore.size).toStrictEqual(2);
expect(calendarStore.size).toStrictEqual(2);

calendar._setStore('2010-3-1', ['05:00']);
expect(calendar._internalStore['2010-3-1']).toStrictEqual({'values': ['05:00']});
expect(calendar._getStore('2010-3-1')).toStrictEqual(['05:00']);

expect(Object.keys(calendar._internalStore).length).toStrictEqual(3);
expect(entryStore.size).toStrictEqual(3);
expect(calendarStore.size).toStrictEqual(3);

calendar._removeStore('2010-3-1');
assert.strictEqual(calendar._internalStore['2010-3-1'], undefined);
expect(calendar._getStore('2010-3-1')).toStrictEqual([]);

// remove just sets the value as undefined in internal store, if it existed
expect(Object.keys(calendar._internalStore).length).toStrictEqual(3);
expect(entryStore.size).toStrictEqual(2);
expect(calendarStore.size).toStrictEqual(2);
});

test('DayCalendar internal waiver storage correct loading', async() =>
Expand Down
Loading

0 comments on commit f67d281

Please sign in to comment.