25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

storage.js 1.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839
  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. });