-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for
TeachingUnitRepository
- Loading branch information
Showing
4 changed files
with
88 additions
and
2 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,42 @@ | ||
declare global { | ||
// eslint-disable-next-line no-var | ||
var myLocalStorage: object; | ||
} | ||
|
||
export const browser = { | ||
storage: { | ||
local: { | ||
get: function (code: string) { | ||
if (globalThis.myLocalStorage == undefined) { | ||
globalThis.myLocalStorage = {}; | ||
} | ||
if (code in globalThis.myLocalStorage) { | ||
return Promise.resolve(globalThis.myLocalStorage[code]); | ||
} | ||
return {}; | ||
}, | ||
set: function (obj: object) { | ||
if (globalThis.myLocalStorage == undefined) { | ||
globalThis.myLocalStorage = {}; | ||
} | ||
const code = Object.keys(obj)[0]; | ||
const state = Object.values(obj)[0]; | ||
const record = {}; | ||
record[code] = state; | ||
globalThis.myLocalStorage[code] = record; | ||
return Promise.resolve(); | ||
}, | ||
remove: function (code: string) { | ||
if (globalThis.myLocalStorage == undefined) { | ||
globalThis.myLocalStorage = {}; | ||
} | ||
if (code in globalThis.myLocalStorage) { | ||
delete globalThis.myLocalStorage[code]; | ||
} | ||
return Promise.resolve(); | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default browser; |
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,41 @@ | ||
import { State, TeachingUnit } from "../src/js/teaching_unit/model"; | ||
import { TeachingUnitRepository } from "../src/js/teaching_unit/repository"; | ||
|
||
test("save and delete from/to local storage", () => { | ||
document.body.innerHTML = | ||
'<div class="ue option clearfix">' + | ||
' <div class=" infos-ue">' + | ||
' <div class="details clearfix">' + | ||
' <div class="credits">6 ECTS<span class="dico"><span class="icon icon-help_simple"></span></span></div>' + | ||
' <h4 class="titre">' + | ||
' <a id="intitule_5df3b7279a53cb218ffb5684789f8939" href="/servlet/uFF?OBJET=ue&CODE=MVA003&LANGUE=0&RF=" target="ue">Mathematical tools for computing</a>' + | ||
" </h4>" + | ||
' <div class="code">' + | ||
' <a id="code_5df3b7279a53cb218ffb5684789f8939" href="/servlet/uFF?OBJET=ue&CODE=MVA003&LANGUE=0&RF=" target="ue">MVA003</a>' + | ||
" </div>" + | ||
" </div>" + | ||
" </div>" + | ||
"</div>"; | ||
const el = document.getElementsByClassName("ue")[0]; | ||
const teachingUnit = TeachingUnit.fromElement(el); | ||
|
||
new TeachingUnitRepository(teachingUnit); | ||
TeachingUnitRepository.getFromLocalStorage(el).then((teaching_unit) => { | ||
expect(teaching_unit.state).toBe(State.Unselected); | ||
}); | ||
|
||
teachingUnit.toggle(); | ||
TeachingUnitRepository.getFromLocalStorage(el).then((teaching_unit) => { | ||
expect(teaching_unit.state).toBe(State.Selected); | ||
}); | ||
|
||
teachingUnit.toggle(); | ||
TeachingUnitRepository.getFromLocalStorage(el).then((teaching_unit) => { | ||
expect(teaching_unit.state).toBe(State.Validated); | ||
}); | ||
|
||
teachingUnit.toggle(); | ||
TeachingUnitRepository.getFromLocalStorage(el).then((teaching_unit) => { | ||
expect(teaching_unit.state).toBe(State.Unselected); | ||
}); | ||
}); |