Commit 7c01aebe authored by Laurent Wouters's avatar Laurent Wouters
Browse files

[test] Adding tests for libview/definition with http request mocking

parent c50ecec30280
......@@ -28,6 +28,7 @@
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.5",
"@types/rdflib": "^0.17.0",
"@types/xhr-mock": "^2.0.0",
"chai": "^4.2.0",
"copy-webpack-plugin": "^4.5.2",
"mocha": "^5.2.0",
......@@ -39,6 +40,7 @@
"typescript": "^2.9.2",
"typescript-formatter": "^7.2.2",
"webpack": "^4.20.2",
"webpack-cli": "^3.1.1"
"webpack-cli": "^3.1.1",
"xhr-mock": "^2.4.1"
}
}
/*******************************************************************************
* Copyright 2003-2018 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
* contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
*
* This file is part of CubicWeb.
*
* CubicWeb is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 2.1 of the License, or (at your option)
* any later version.
*
* CubicWeb is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
import * as chai from "chai";
import {
ViewRegistry,
ViewRegistrySourceKind,
ViewRegistrySourceRemote,
ViewDescriptor,
ViewResourceRemote,
ViewResourceLocation,
loadRegistry
} from "./view-def";
import mock from "xhr-mock";
import { fail } from "assert";
const expect = chai.expect;
describe("@logilab/libview/view-def", () => {
beforeEach(() => mock.setup());
afterEach(() => mock.teardown());
it("should load the descriptors for a registry", async () => {
let registry: ViewRegistry = {
descriptors: {},
sources: [
{
kind: ViewRegistrySourceKind.remote,
name: "source 1",
uri: "http://example.com/source"
} as ViewRegistrySourceRemote
]
};
let descriptors: ViewDescriptor[] = [
{
identifier: "descriptor1",
name: "view1",
description: "some description",
entrypoint: "ENTRYPOINT",
resourceCss: [],
resourceJs: [],
resourceMain: {
location: ViewResourceLocation.remote,
uri: "http://example.com/view1"
} as ViewResourceRemote
}
];
mock.get("http://example.com/source", {
status: 200,
body: JSON.stringify(descriptors)
});
let target = await loadRegistry(registry);
expect(target.sources.length).equals(registry.sources.length);
expect(target.sources[0].name).equals(registry.sources[0].name);
let d = target.descriptors[descriptors[0].identifier];
if (d === undefined) {
fail();
return;
}
expect(d.identifier).equals(descriptors[0].identifier);
});
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment