Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
commit
b8cb45b0de
|
@ -1,7 +1,12 @@
|
||||||
import Notify from "common/notify";
|
import Notify from "common/notify";
|
||||||
let sinon = require("sinon");
|
let sinon = require("sinon");
|
||||||
|
|
||||||
|
let chai = require('../../../node_modules/chai/chai');
|
||||||
|
let assert = chai.assert;
|
||||||
|
|
||||||
describe("common/alert", () => {
|
describe("common/alert", () => {
|
||||||
|
|
||||||
|
let spywarn = sinon.spy(Notify, "warn");
|
||||||
it("should call alert.info", () => {
|
it("should call alert.info", () => {
|
||||||
let spy = sinon.spy(Notify, "info");
|
let spy = sinon.spy(Notify, "info");
|
||||||
Notify.info("message");
|
Notify.info("message");
|
||||||
|
@ -10,10 +15,9 @@ describe("common/alert", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should call alert.warning", () => {
|
it("should call alert.warning", () => {
|
||||||
let spy = sinon.spy(Notify, "warn");
|
|
||||||
Notify.warn("message");
|
Notify.warn("message");
|
||||||
sinon.assert.calledOnce(spy);
|
sinon.assert.calledOnce(spywarn);
|
||||||
spy.resetHistory();
|
spywarn.resetHistory();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should call alert.error", () => {
|
it("should call alert.error", () => {
|
||||||
|
@ -29,4 +33,27 @@ describe("common/alert", () => {
|
||||||
sinon.assert.calledOnce(spy);
|
sinon.assert.calledOnce(spy);
|
||||||
spy.resetHistory();
|
spy.resetHistory();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should call alert.logout", () => {
|
||||||
|
let spy = sinon.spy(Notify, "logout");
|
||||||
|
Notify.logout("message");
|
||||||
|
sinon.assert.calledOnce(spy);
|
||||||
|
spy.resetHistory();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call wait", () => {
|
||||||
|
Notify.wait();
|
||||||
|
sinon.assert.calledOnce(spywarn);
|
||||||
|
spywarn.resetHistory();
|
||||||
|
});
|
||||||
|
|
||||||
|
//TODO How to access element?
|
||||||
|
/*it("should test blocking an unblocking UI", () => {
|
||||||
|
const el = document.getElementById("p-busy-overlay");
|
||||||
|
assert.equal(el.style.display, "xxx");
|
||||||
|
Notify.blockUI();
|
||||||
|
assert.equal(el.style.display, "xxx");
|
||||||
|
Notify.unblockUI();
|
||||||
|
assert.equal(el.style.display, "xxx");
|
||||||
|
});*/
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,6 +3,7 @@ import Config from 'common/config'
|
||||||
import MockAdapter from "axios-mock-adapter";
|
import MockAdapter from "axios-mock-adapter";
|
||||||
import Api from "common/api";
|
import Api from "common/api";
|
||||||
|
|
||||||
|
//TODO Add tokens to config data and test hasToken
|
||||||
window.__CONFIG__ = {
|
window.__CONFIG__ = {
|
||||||
"name": "PhotoPrism",
|
"name": "PhotoPrism",
|
||||||
"version": "200531-4684f66-Linux-x86_64-DEBUG",
|
"version": "200531-4684f66-Linux-x86_64-DEBUG",
|
||||||
|
@ -171,6 +172,7 @@ describe('common/session', () => {
|
||||||
it('should set, get and delete token', () => {
|
it('should set, get and delete token', () => {
|
||||||
const storage = window.localStorage;
|
const storage = window.localStorage;
|
||||||
const session = new Session(storage, config);
|
const session = new Session(storage, config);
|
||||||
|
assert.equal(session.hasToken("1uhovi0e"), false);
|
||||||
assert.equal(session.session_id, null);
|
assert.equal(session.session_id, null);
|
||||||
session.setId(123421);
|
session.setId(123421);
|
||||||
assert.equal(session.session_id, 123421);
|
assert.equal(session.session_id, 123421);
|
||||||
|
@ -185,6 +187,8 @@ describe('common/session', () => {
|
||||||
const session = new Session(storage, config);
|
const session = new Session(storage, config);
|
||||||
assert.isFalse(session.user.hasId());
|
assert.isFalse(session.user.hasId());
|
||||||
const values = {"user": {ID: 5, FirstName: "Max", LastName: "Last", Email: "test@test.com", Admin: true}};
|
const values = {"user": {ID: 5, FirstName: "Max", LastName: "Last", Email: "test@test.com", Admin: true}};
|
||||||
|
session.setData();
|
||||||
|
assert.equal(session.user.FirstName, "");
|
||||||
session.setData(values);
|
session.setData(values);
|
||||||
assert.equal(session.user.FirstName, "Max");
|
assert.equal(session.user.FirstName, "Max");
|
||||||
assert.equal(session.user.Admin, true);
|
assert.equal(session.user.Admin, true);
|
||||||
|
@ -283,4 +287,51 @@ describe('common/session', () => {
|
||||||
mock.reset();
|
mock.reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//TODO Why does it make other tests fail?
|
||||||
|
/*it('should test onLogout', async () => {
|
||||||
|
mock
|
||||||
|
.onPost("session").reply(200, {id: "8877", data: {user: {ID: 1, Email: "test@test.com"}}})
|
||||||
|
.onDelete("session/8877").reply(200);
|
||||||
|
const storage = window.localStorage;
|
||||||
|
const session = new Session(storage, config);
|
||||||
|
//assert.equal(session.session_id, null);
|
||||||
|
//assert.equal(session.storage.data, undefined);
|
||||||
|
await session.login("test@test.com", "passwd");
|
||||||
|
assert.equal(session.session_id, 8877);
|
||||||
|
assert.equal(session.storage.data, '{"user":{"ID":1,"Email":"test@test.com"}}');
|
||||||
|
await session.onLogout();
|
||||||
|
assert.equal(session.session_id, null);
|
||||||
|
mock.reset();
|
||||||
|
//session.deleteData();
|
||||||
|
});*/
|
||||||
|
|
||||||
|
it('should use session storage', () => {
|
||||||
|
const storage = window.sessionStorage;
|
||||||
|
const session = new Session(storage, config);
|
||||||
|
assert.equal(storage.getItem("session_storage"), null);
|
||||||
|
session.useSessionStorage();
|
||||||
|
assert.equal(storage.getItem("session_storage"), "true");
|
||||||
|
session.deleteData();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use local storage', () => {
|
||||||
|
const storage = window.localStorage;
|
||||||
|
const session = new Session(storage, config);
|
||||||
|
assert.equal(storage.getItem("session_storage"), null);
|
||||||
|
session.useLocalStorage();
|
||||||
|
assert.equal(storage.getItem("session_storage"), "false");
|
||||||
|
session.deleteData();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should test redeem token', async () => {
|
||||||
|
mock
|
||||||
|
.onPost("session").reply(200, {id: "123", data: {token: "123token"}});
|
||||||
|
const storage = window.localStorage;
|
||||||
|
const session = new Session(storage, config);
|
||||||
|
assert.equal(session.data, null);
|
||||||
|
await session.redeemToken("token123");
|
||||||
|
assert.equal(session.data.token, "123token");
|
||||||
|
mock.reset();
|
||||||
|
session.deleteData();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue