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

caleb531 / workday-time-calculator / 6756527510

04 Nov 2023 06:29PM UTC coverage: 64.881% (+9.9%) from 55.016%
6756527510

push

github

caleb531
WIP: build out UI test infrastructure

Adds an additional test to check if log contents can be rendered into
the editor.

153 of 183 branches covered (0.0%)

Branch coverage included in aggregate %.

6 of 6 new or added lines in 2 files covered. (100.0%)

4 existing lines in 1 file now uncovered.

1543 of 2431 relevant lines covered (63.47%)

47.64 hits per line

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

56.72
/scripts/models/app-storage.js
1
import * as idbKeyval from 'idb-keyval';
2✔
2

2✔
3
// This is a storage API-agnostic class for accessing local data saved by the
2✔
4
// app; it uses IndexedDB as the internal storage API, falling back to
2✔
5
// localStorage if IndexedDB is unsupported by the user's browser, or if the
2✔
6
// storage upgrade process could not be successfully completed
2✔
7
class AppStorage {
2✔
8
  // Only use IndexedDB if the browser supports it and if the user has opted to
2✔
9
  // upgrade the data store to IndexedDB
2✔
10
  usingIDB() {
2✔
11
    return Boolean(
8✔
12
      // The browser must support IndexedDB
8✔
13
      typeof indexedDB !== 'undefined' &&
8✔
14
        // The user does not have any data left in localStorage
8✔
15
        !Object.keys(localStorage).find((key) => /^wtc-/.test(key))
8✔
16
    );
8✔
17
  }
8✔
18

2✔
19
  // Retrieve the contents of the storage entry at the given key
2✔
20
  get(key) {
2✔
21
    if (this.usingIDB()) {
6✔
22
      return idbKeyval.get(key);
6✔
23
    } else {
6!
UNCOV
24
      return new Promise((resolve) => {
×
UNCOV
25
        resolve(JSON.parse(localStorage.getItem(key)));
×
UNCOV
26
      });
×
UNCOV
27
    }
×
28
  }
6✔
29

2✔
30
  // Set the contents of the storage entry at the given key
2✔
31
  set(key, value) {
2✔
32
    if (this.usingIDB()) {
×
33
      return idbKeyval.set(key, value);
×
34
    } else {
×
35
      return new Promise((resolve) => {
×
36
        resolve(localStorage.setItem(key, JSON.stringify(value)));
×
37
      });
×
38
    }
×
39
  }
×
40

2✔
41
  // Remove an entry with the given key from the storage completely
2✔
42
  remove(key) {
2✔
43
    if (this.usingIDB()) {
×
44
      return idbKeyval.del(key);
×
45
    } else {
×
46
      return new Promise((resolve) => {
×
47
        resolve(localStorage.removeItem(key));
×
48
      });
×
49
    }
×
50
  }
×
51

2✔
52
  // Return an array of keys for all entries in the storage
2✔
53
  keys() {
2✔
54
    if (this.usingIDB()) {
×
55
      return idbKeyval.keys();
×
56
    } else {
×
57
      return new Promise((resolve) => {
×
58
        resolve(Object.keys(localStorage));
×
59
      });
×
60
    }
×
61
  }
×
62
}
2✔
63

2✔
64
export default new AppStorage();
2✔
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