mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* Adding LogTabStore Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Adding Pod selector in logs tab Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Refresh containers on pod change Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Adding <LogResourceSelector /> tests Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Adding LogTabStore tests Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Clearn getPodsByOwnerId method Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Extracting dummy pods into mock file Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Eliminating containers and initContainers from store Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Refreshing tab pods if pod amount is changed in store Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * A bit of cleaning up, fixing tests Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Fix lint newline errors Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Return getPodsByOwner() method Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Rename log tab when pod changes Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
114 lines
3.0 KiB
TypeScript
114 lines
3.0 KiB
TypeScript
/**
|
|
* @jest-environment jsdom
|
|
*/
|
|
|
|
import { podsStore } from "../../+workloads-pods/pods.store";
|
|
import { Pod } from "../../../api/endpoints";
|
|
import { dockStore } from "../dock.store";
|
|
import { logTabStore } from "../log-tab.store";
|
|
import { deploymentPod1, deploymentPod2, deploymentPod3, dockerPod } from "./pod.mock";
|
|
|
|
|
|
podsStore.items.push(new Pod(dockerPod));
|
|
podsStore.items.push(new Pod(deploymentPod1));
|
|
podsStore.items.push(new Pod(deploymentPod2));
|
|
|
|
describe("log tab store", () => {
|
|
afterEach(() => {
|
|
logTabStore.reset();
|
|
dockStore.reset();
|
|
});
|
|
|
|
it("creates log tab without sibling pods", () => {
|
|
const selectedPod = new Pod(dockerPod);
|
|
const selectedContainer = selectedPod.getAllContainers()[0];
|
|
|
|
logTabStore.createPodTab({
|
|
selectedPod,
|
|
selectedContainer
|
|
});
|
|
|
|
expect(logTabStore.getData(dockStore.selectedTabId)).toEqual({
|
|
pods: [selectedPod],
|
|
selectedPod,
|
|
selectedContainer,
|
|
showTimestamps: false,
|
|
previous: false
|
|
});
|
|
});
|
|
|
|
it("creates log tab with sibling pods", () => {
|
|
const selectedPod = new Pod(deploymentPod1);
|
|
const siblingPod = new Pod(deploymentPod2);
|
|
const selectedContainer = selectedPod.getInitContainers()[0];
|
|
|
|
logTabStore.createPodTab({
|
|
selectedPod,
|
|
selectedContainer
|
|
});
|
|
|
|
expect(logTabStore.getData(dockStore.selectedTabId)).toEqual({
|
|
pods: [selectedPod, siblingPod],
|
|
selectedPod,
|
|
selectedContainer,
|
|
showTimestamps: false,
|
|
previous: false
|
|
});
|
|
});
|
|
|
|
it("removes item from pods list if pod deleted from store", () => {
|
|
const selectedPod = new Pod(deploymentPod1);
|
|
const selectedContainer = selectedPod.getInitContainers()[0];
|
|
|
|
logTabStore.createPodTab({
|
|
selectedPod,
|
|
selectedContainer
|
|
});
|
|
|
|
podsStore.items.pop();
|
|
|
|
expect(logTabStore.getData(dockStore.selectedTabId)).toEqual({
|
|
pods: [selectedPod],
|
|
selectedPod,
|
|
selectedContainer,
|
|
showTimestamps: false,
|
|
previous: false
|
|
});
|
|
});
|
|
|
|
it("adds item into pods list if new sibling pod added to store", () => {
|
|
const selectedPod = new Pod(deploymentPod1);
|
|
const selectedContainer = selectedPod.getInitContainers()[0];
|
|
|
|
logTabStore.createPodTab({
|
|
selectedPod,
|
|
selectedContainer
|
|
});
|
|
|
|
podsStore.items.push(new Pod(deploymentPod3));
|
|
|
|
expect(logTabStore.getData(dockStore.selectedTabId)).toEqual({
|
|
pods: [selectedPod, deploymentPod3],
|
|
selectedPod,
|
|
selectedContainer,
|
|
showTimestamps: false,
|
|
previous: false
|
|
});
|
|
});
|
|
|
|
it("closes tab if no pods left in store", () => {
|
|
const selectedPod = new Pod(deploymentPod1);
|
|
const selectedContainer = selectedPod.getInitContainers()[0];
|
|
|
|
logTabStore.createPodTab({
|
|
selectedPod,
|
|
selectedContainer
|
|
});
|
|
|
|
podsStore.items.clear();
|
|
|
|
expect(logTabStore.getData(dockStore.selectedTabId)).toBeUndefined();
|
|
expect(dockStore.getTabById(dockStore.selectedTabId)).toBeUndefined();
|
|
});
|
|
});
|