-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] Perte des infos GAR quand la page est rafraichie (PIX-12534)
- Loading branch information
Showing
5 changed files
with
224 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export class SessionStorageEntry { | ||
constructor(key) { | ||
this.key = key; | ||
} | ||
|
||
set(value) { | ||
sessionStorage.setItem(this.key, JSON.stringify({ value })); | ||
} | ||
|
||
get() { | ||
const result = JSON.parse(sessionStorage.getItem(this.key)) || {}; | ||
return result.value; | ||
} | ||
|
||
remove() { | ||
sessionStorage.removeItem(this.key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { SessionStorageEntry } from 'mon-pix/utils/session-storage-entry'; | ||
import { module, test } from 'qunit'; | ||
|
||
module('Unit | Utilities | SessionStorageEntry', function () { | ||
test('sets and gets a string value', function (assert) { | ||
// given | ||
const entry = new SessionStorageEntry('testKey'); | ||
const value = 'testValue'; | ||
|
||
// when | ||
entry.set(value); | ||
|
||
// then | ||
assert.strictEqual(entry.get(), value); | ||
}); | ||
|
||
test('sets and gets a number value', function (assert) { | ||
// given | ||
const entry = new SessionStorageEntry('numberKey'); | ||
const value = 123; | ||
|
||
// when | ||
entry.set(value); | ||
|
||
// then | ||
assert.strictEqual(entry.get(), value); | ||
}); | ||
|
||
test('sets and gets a boolean value', function (assert) { | ||
// given | ||
const entry = new SessionStorageEntry('booleanKey'); | ||
const value = true; | ||
|
||
// when | ||
entry.set(value); | ||
|
||
// then | ||
assert.strictEqual(entry.get(), value); | ||
}); | ||
|
||
test('sets and gets a null value', function (assert) { | ||
// given | ||
const entry = new SessionStorageEntry('nullKey'); | ||
const value = null; | ||
|
||
// when | ||
entry.set(value); | ||
|
||
// then | ||
assert.strictEqual(entry.get(), value); | ||
}); | ||
|
||
test('returns undefined for a non-existing key', function (assert) { | ||
// given | ||
const entry = new SessionStorageEntry('nonExistingKey'); | ||
|
||
// when | ||
const result = entry.get(); | ||
|
||
// then | ||
assert.strictEqual(result, undefined); | ||
}); | ||
|
||
test('removes a key', function (assert) { | ||
// given | ||
const entry = new SessionStorageEntry('testKey'); | ||
const value = 'testValue'; | ||
entry.set(value); | ||
|
||
// when | ||
entry.remove(); | ||
|
||
// then | ||
assert.strictEqual(entry.get(), undefined); | ||
}); | ||
}); |