github.com/replicatedhq/ship@v0.55.0/web/init/src/components/shared/NavBar.spec.js (about) 1 import React from "react"; 2 import { mount } from "enzyme"; 3 import { MemoryRouter } from "react-router-dom"; 4 import { NavBar } from "./NavBar"; 5 6 const mockRouterProps = { 7 location: { 8 pathname: "", 9 }, 10 } 11 12 const initProps = { 13 shipAppMetadata: { 14 name: "", 15 icon: "", 16 }, 17 channelDetails: { 18 name: "", 19 icon: "", 20 }, 21 routes: [], 22 }; 23 24 describe("NavBar", () => { 25 beforeAll(() => { 26 // Mocking Image.prototype.src to call onload immediately 27 Object.defineProperty(global.Image.prototype, "src", { 28 set() { 29 this.onload() 30 }, 31 }); 32 }); 33 34 describe("provided shipAppMetadata", () => { 35 const wrapper = mount( 36 <MemoryRouter initialEntries={["/"]} initialIndex={0}> 37 <NavBar 38 {...mockRouterProps} 39 {...initProps} 40 /> 41 </MemoryRouter> 42 ); 43 it("sets navDetails via shipAppMetadata", async () => { 44 wrapper.setProps({ 45 children: React.cloneElement( 46 wrapper.props().children, 47 { 48 ...mockRouterProps, 49 shipAppMetadata: { 50 name: "testHelm", 51 icon: "testHelmIcon", 52 loaded: true, 53 }, 54 }, 55 ), 56 }); 57 await wrapper.update(); 58 const navBar = wrapper.find(NavBar).instance(); 59 const navDetails = navBar.state.navDetails; 60 expect(navDetails.name).toEqual("testHelm"); 61 expect(navDetails.icon).toEqual("testHelmIcon"); 62 }); 63 }); 64 });