• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

caleb531 / workday-time-calculator / 6751180710

03 Nov 2023 11:15PM UTC coverage: 85.528% (-0.4%) from 85.878%
6751180710

push

github

caleb531
Apply Prettier to all files

83 of 84 branches covered (0.0%)

Branch coverage included in aggregate %.

4 of 8 new or added lines in 2 files covered. (50.0%)

1 existing line in 1 file now uncovered.

443 of 531 relevant lines covered (83.43%)

285.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.67
/scripts/models/preferences.js
1
import { fromPairs, pick } from 'lodash-es';
3✔
2
import appStorage from './app-storage.js';
3✔
3

3✔
4
class Preferences {
3✔
5
  constructor(prefs = {}) {
3✔
6
    Object.assign(this, this.getDefaultValueMap(), prefs);
63✔
7
    this.eventCallbacks = {};
63✔
8
  }
63✔
9

3✔
10
  load() {
3✔
11
    return appStorage.get('wtc-prefs').then((prefs) => {
×
12
      Object.assign(this, this.getDefaultValueMap(), prefs);
×
13
      this.validatePreferenceValues();
×
14
      return this;
×
15
    });
×
16
  }
×
17

3✔
18
  // Get a map of default values, where the key is the preference ID and the
3✔
19
  // value is the default value for that preference
3✔
20
  getDefaultValueMap() {
3✔
21
    return fromPairs(
63✔
22
      Preferences.preferences.map((preference) => {
63✔
23
        return [preference.id, preference.defaultValue];
315✔
24
      })
63✔
25
    );
63✔
26
  }
63✔
27

3✔
28
  // Validate each of the user's saved preferences; if a value is not a valid
3✔
29
  // value, set it to the default value for that preference
3✔
30
  validatePreferenceValues() {
3✔
31
    let shouldResavePreferences = false;
×
32
    Preferences.preferences.forEach((preference) => {
×
33
      const validValues = preference.options.map((option) => option.value);
×
34
      if (this[preference.id] && !validValues.includes(this[preference.id])) {
×
35
        this[preference.id] = preference.defaultValue;
×
36
        shouldResavePreferences = true;
×
37
      }
×
38
    });
×
39
    // If at least one of the user's preferences has an invalid value, we
×
40
    // should not only correct it, but we should write back to the app storage
×
41
    // to ensure that corrected value persists
×
42
    if (shouldResavePreferences) {
×
43
      this.save();
×
44
    }
×
45
  }
×
46

3✔
47
  save() {
3✔
48
    return appStorage.set('wtc-prefs', this.toJSON());
×
49
  }
×
50

3✔
51
  set(props, { trigger = true } = {}) {
3✔
52
    Object.keys(props).forEach((key) => {
×
53
      this[key] = props[key];
×
54
      if (trigger) {
×
55
        this.trigger(`change:${key}`, key, props[key]);
×
56
      }
×
57
    });
×
58
  }
×
59

3✔
60
  on(eventName, eventCallback) {
3✔
61
    if (!this.eventCallbacks[eventName]) {
×
62
      this.eventCallbacks[eventName] = [];
×
63
    }
×
64
    this.eventCallbacks[eventName].push(eventCallback);
×
65
  }
×
66

3✔
67
  trigger(eventName, ...eventArgs) {
3✔
68
    if (!this.eventCallbacks[eventName]) {
×
69
      this.eventCallbacks[eventName] = [];
×
70
    }
×
71
    this.eventCallbacks[eventName].forEach((eventCallback) => {
×
72
      eventCallback.apply(this, eventArgs);
×
73
    });
×
74
  }
×
75

3✔
76
  toJSON() {
3✔
NEW
77
    return pick(
×
NEW
78
      this,
×
NEW
79
      Preferences.preferences.map((pref) => pref.id)
×
NEW
80
    );
×
UNCOV
81
  }
×
82
}
3✔
83

3✔
84
Preferences.preferences = [
3✔
85
  {
3✔
86
    id: 'colorTheme',
3✔
87
    label: 'Color Theme',
3✔
88
    description: "What color would you like as your WTC app's theme?",
3✔
89
    optionType: 'color',
3✔
90
    defaultValue: 'blue',
3✔
91
    options: [
3✔
92
      { label: 'Blue', value: 'blue' },
3✔
93
      { label: 'Green', value: 'green' },
3✔
94
      { label: 'Purple', value: 'purple' },
3✔
95
      { label: 'Rose', value: 'rose' },
3✔
96
      { label: 'Slate', value: 'slate' }
3✔
97
    ]
3✔
98
  },
3✔
99
  {
3✔
100
    id: 'reminderInterval',
3✔
101
    label: 'Reminder Interval',
3✔
102
    description: 'How often should WTC remind you to update your time log?',
3✔
103
    defaultValue: 0,
3✔
104
    options: [
3✔
105
      { label: 'Never', value: 0 },
3✔
106
      { label: 'Every 15 minutes', value: 15 },
3✔
107
      { label: 'Every half-hour', value: 30 },
3✔
108
      { label: 'Every hour', value: 60 }
3✔
109
    ]
3✔
110
  },
3✔
111
  {
3✔
112
    id: 'autocompleteMode',
3✔
113
    label: 'Autocomplete Suggestions',
3✔
114
    description:
3✔
115
      'Would you like WTC to suggest words as you type in the editor? These suggestions are based on your log history, and no data ever leaves your local device.',
3✔
116
    defaultValue: 'lazy',
3✔
117
    options: [
3✔
118
      { label: 'Disabled', value: 'off' },
3✔
119
      { label: 'Lazy Mode (autocompletes one word at a time)', value: 'lazy' },
3✔
120
      { label: 'Greedy Mode (autocompletes longer phrases)', value: 'greedy' }
3✔
121
    ]
3✔
122
  },
3✔
123
  {
3✔
124
    id: 'timeSystem',
3✔
125
    label: 'Time System',
3✔
126
    description:
3✔
127
      'Which time system do you prefer when entering and displaying times?',
3✔
128
    defaultValue: '12-hour',
3✔
129
    options: [
3✔
130
      { label: '12-hour', value: '12-hour' },
3✔
131
      { label: '24-hour / military time', value: '24-hour' }
3✔
132
    ]
3✔
133
  },
3✔
134
  {
3✔
135
    id: 'categorySortOrder',
3✔
136
    label: 'Category Sort Order',
3✔
137
    description: 'How should category groupings be sorted in the Summary view?',
3✔
138
    defaultValue: 'duration',
3✔
139
    options: [
3✔
140
      { label: 'No sorting', value: 'none' },
3✔
141
      { label: 'Title (ascending)', value: 'title' },
3✔
142
      { label: 'Duration (descending)', value: 'duration' }
3✔
143
    ]
3✔
144
  }
3✔
145
];
3✔
146

3✔
147
export default Preferences;
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc