fleet/frontend/test/envSetup.js

105 lines
2.4 KiB
JavaScript
Raw Normal View History

Feature - add search and sort to host table (#341) * start adding global search filter * update polyfill setup to use async await for react-table * update browerslist to sensible defaults * get global search functionality woring * more progress on the data table * get label network calls working in hostdatatable * get pagination functionality into the HostDataTable * get search query making network call * get ordering making query * make actual sort order network calls * disable cpu column sorting * seperate get table data from get labels * fix issues with input resetting and got search query working * get sort working * ignore vs code editor settings * improve loading spinner to move inside the table * improve styling * add sorting arrows * remove unused sorting arrow component * add host query params to labels endpoint * fix style for query textarea on label hosts * got new pagination working * set server data as source of truth for table global filter * cleanup logs * clean up pagination styles * fix up paginationa and no host styles * add result count to table * remove logs * tweak header styles * fix to sort order * simplify default sort direction * keep sort order of server api responses and use in host table * clean up logs * Add styles for header cell and pagination * fix tests for ManageHostPage * fix tests for HostContainer * fix lower level action reducer and thunk tests * fix tests for hosts client * fix up some host count styling * added back no hosts start message * fix linting errors * remove unused old pagination code * add back scrollToTop utility on pagination * remove unused code in managehostpage test Co-authored-by: Noah Talerman <[email protected]>
2021-02-25 12:05:08 +00:00
// used for babel polyfills.
import "core-js/stable";
import "regenerator-runtime/runtime";
Feature - add search and sort to host table (#341) * start adding global search filter * update polyfill setup to use async await for react-table * update browerslist to sensible defaults * get global search functionality woring * more progress on the data table * get label network calls working in hostdatatable * get pagination functionality into the HostDataTable * get search query making network call * get ordering making query * make actual sort order network calls * disable cpu column sorting * seperate get table data from get labels * fix issues with input resetting and got search query working * get sort working * ignore vs code editor settings * improve loading spinner to move inside the table * improve styling * add sorting arrows * remove unused sorting arrow component * add host query params to labels endpoint * fix style for query textarea on label hosts * got new pagination working * set server data as source of truth for table global filter * cleanup logs * clean up pagination styles * fix up paginationa and no host styles * add result count to table * remove logs * tweak header styles * fix to sort order * simplify default sort direction * keep sort order of server api responses and use in host table * clean up logs * Add styles for header cell and pagination * fix tests for ManageHostPage * fix tests for HostContainer * fix lower level action reducer and thunk tests * fix tests for hosts client * fix up some host count styling * added back no hosts start message * fix linting errors * remove unused old pagination code * add back scrollToTop utility on pagination * remove unused code in managehostpage test Co-authored-by: Noah Talerman <[email protected]>
2021-02-25 12:05:08 +00:00
import nock from "nock";
// for testing-library utils
2021-04-14 16:52:15 +00:00
import "@testing-library/jest-dom";
// Uncomment for verbose unhandled promise rejection warnings
// process.on('unhandledRejection', (reason) => {
// console.error('REJECTION', reason);
// });
nock.disableNetConnect();
nock.emitter.on("no match", (req) => {
console.log("NOCK NO MATCH ", req);
});
// nock.emitter.on('request', (req, interceptor) => {
// console.error('interceptor matched request: ', req, interceptor)
// });
// nock.emitter.on('replied', (req, interceptor) => {
// console.error('response replied with nocked payload', req, interceptor)
// });
// Many tests will output unhandled promise rejection warnings if this is not
// included to mock the common HTTP request.
nock("http://localhost:8080")
.persist()
.post("/api/latest/fleet/targets")
.reply(200, {
targets_count: 1234,
targets: [
{
id: 3,
label: "OS X El Capitan 10.11",
name: "osx-10.11",
platform: "darwin",
target_type: "hosts",
},
],
});
nock("http://localhost:8080")
.persist()
.get("/api/latest/fleet/status/live_query")
.reply(200, {});
nock("http://localhost:8080")
.persist()
.get("/api/latest/fleet/version")
.reply(200, {
version: "3.10.0",
branch: "master",
revision: "83d608962af583375bc20c644c5ac4b00b408461",
go_version: "go1.16.2",
build_date: "2021-03-31T20:05:51Z",
build_user: "zwass",
});
global.document.queryCommandEnabled = jest.fn();
global.document.execCommand = jest.fn();
global.window.getSelection = () => {
return {
removeAllRanges: () => {
return true;
},
};
};
global.window.scrollTo = jest.fn();
global.window.URL = new URL("http://localhost:8080");
global.navigator = global.window.navigator;
window.URL.createObjectURL = () => undefined;
function mockStorage() {
let storage = {};
return {
setItem(key, value = "") {
storage[key] = value;
},
getItem(key) {
return storage[key];
},
removeItem(key) {
delete storage[key];
},
get length() {
return Object.keys(storage).length;
},
key(i) {
return Object.keys(storage)[i] || null;
},
clear() {
storage = {};
},
};
}
global.localStorage = mockStorage();
window.localStorage = global.localStorage;