Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

40 rindas
1.2 KiB

  1. import test from 'ava';
  2. import {LocalStorageMock} from './_helpers';
  3. import Storage, {LOCAL_STORAGE_KEY} from '../src/api/storage';
  4. const localStorage = new LocalStorageMock();
  5. const storage = new Storage(localStorage);
  6. test('get default storage', t => {
  7. t.is(storage.json().baseURL, 'https://lesspass.com');
  8. });
  9. test('get storage saved in local storage', t => {
  10. localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify({baseURL: 'https://example.org'}));
  11. t.is(storage.json().baseURL, 'https://example.org');
  12. });
  13. test('save storage in local storage', t => {
  14. storage.save({baseURL: 'https://example.org'});
  15. t.is(localStorage.getItem(LOCAL_STORAGE_KEY), '{"baseURL":"https://example.org"}');
  16. });
  17. test('save storage in local storage', t => {
  18. storage.save({baseURL: 'https://example.org'});
  19. t.is(localStorage.getItem(LOCAL_STORAGE_KEY), '{"baseURL":"https://example.org"}');
  20. });
  21. test('save storage in local storage merge', t => {
  22. localStorage.clear();
  23. storage.save({a: 'a'});
  24. storage.save({b: 'b'});
  25. t.is(localStorage.getItem(LOCAL_STORAGE_KEY), '{"a":"a","b":"b"}');
  26. });
  27. test('storage clear local storage', t => {
  28. storage.save({a: 'a'});
  29. storage.clear();
  30. t.is(localStorage.getItem(LOCAL_STORAGE_KEY), null);
  31. });