Skip to content

Commit

Permalink
Merge c72bd74 into f83ac88
Browse files Browse the repository at this point in the history
  • Loading branch information
veredcon committed Nov 6, 2023
2 parents f83ac88 + c72bd74 commit 16ae0b1
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 70 deletions.
14 changes: 7 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@
"name": "frontend unit tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"./node_modules/@vue/cli-service/bin/vue-cli-service.js",
"test:unit",
"--runInBand"
],
"runtimeArgs": ["--inspect-brk", "./node_modules/jest/bin/jest.js", "-w 1", "--colors"],
"cwd": "${workspaceFolder}/packages/frontend",
"protocol": "inspector",
"disableOptimisticBPs": true,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"outFiles": ["${workspaceFolder}/packages/frontend/src/**/*.js"],
"outFiles": ["${workspaceFolder}/packages/frontend/dist/**/*.js"],
"resolveSourceMapLocations": [
"${workspaceFolder}/packages/frontend/**",
"${workspaceFolder}/**",
"!**/node_modules/**"
],
"port": 9229
}
]
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ export default {
isInVsCode() {
return typeof acquireVsCodeApi !== "undefined";
},
/* c8 ignore start */
async setupRpc() {
/* istanbul ignore if */
if (this.isInVsCode()) {
// eslint-disable-next-line no-undef
window.vscode = acquireVsCodeApi();
Expand Down Expand Up @@ -118,6 +118,7 @@ export default {
});
});
},
/* c8 ignore stop */
init() {
this.rpc.invoke("init").then((target) => {
this.initialTarget = target;
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend/src/components/CFSignin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,11 @@ export default {
return this.isLoggedIn ? "none" : "";
},
ssoVisibility() {
/* c8 ignore next */
return this.ssoOrCredentials === "SSO" ? "" : "none";
},
credentialsVisibility() {
/* c8 ignore next */
return this.ssoOrCredentials === "Credentials" ? "" : "none";
},
},
Expand Down
5 changes: 3 additions & 2 deletions packages/frontend/src/components/CFTarget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import { provideVSCodeDesignSystem, vsCodeButton } from "@vscode/webview-ui-toolkit";
provideVSCodeDesignSystem().register(vsCodeButton());
import * as _ from "lodash";
export default {
name: "CFTarget",
Expand Down Expand Up @@ -119,7 +120,7 @@ export default {
selected: org.label === target.org,
};
});
this.orgs = orgsWithSelected;
this.orgs = _.sortBy(orgsWithSelected, (item) => item.label.toLowerCase());
// If no org could be selected from the current target, set it to the first org if exists
if (!this.selectedOrg || !this.selectedOrg.guid) {
Expand Down Expand Up @@ -147,7 +148,7 @@ export default {
selected: targetSpace ? space.label === targetSpace : false,
};
});
this.spaces = spacesWithSelected;
this.spaces = _.sortBy(spacesWithSelected, (item) => item.label.toLowerCase());
// If a specific space should be selected - choose it, otherwise take the first if exists and fallback to empty selection object.
this.selectedSpace =
_.find(this.spaces, (space) => space.selected === true) ?? (this.spaces && this.spaces[0]) ?? {};
Expand Down
23 changes: 22 additions & 1 deletion packages/frontend/test/App.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ jest.mock("../src/components/CFSignin.vue", () => ({
template: "<div>Mocked CFSignin</div>", // Replace with your desired mock template
}));

// Stub is used to avoid console warnings of vscode custom elements
const global = {
stubs: {
VscodeProgressRing: {
template: "<div></div>",
},
},
};

describe("App.vue", () => {
// Mock the rpc object with the required methods
const mockRpc = {
Expand All @@ -67,8 +76,10 @@ describe("App.vue", () => {
data() {
return {
rpc: mockRpc, // Provide the mock rpc object
initialTarget: {},
};
},
global,
});

// Assert that the component exists without errors
Expand All @@ -80,8 +91,10 @@ describe("App.vue", () => {
data() {
return {
rpc: mockRpc, // Provide the mock rpc object
initialTarget: {},
};
},
global,
});
expect(wrapper.vm.isLoggedIn).to.be.false; // Initial state

Expand All @@ -97,10 +110,12 @@ describe("App.vue", () => {
data() {
return {
rpc: mockRpc, // Provide the mock rpc object
initialTarget: {},
};
},
global,
});
const expectedHtml = `<divid="app"><c-f-header-stubclass="app"></c-f-header-stub><vscode-progress-ringclass="progress-ring"style="display:none;"></vscode-progress-ring><divclass="app"><divstyle="visibility:none;"><c-f-signin-stubtarget="functionObject(){[nativecode]}"rpc="[objectObject]"></c-f-signin-stub><divstyle="display:none;"><c-f-target-stubtarget="[Function]"rpc="[objectObject]"isloggedin="false"></c-f-target-stub></div></div></div><!--endprogress--></div>`;
const expectedHtml = `<divid="app"><c-f-header-stubclass="app"></c-f-header-stub><divclass="progress-ring"style="display:none;"></div><divclass="app"><divstyle="visibility:none;"><c-f-signin-stubtarget="[objectObject]"rpc="[objectObject]"></c-f-signin-stub><divstyle="display:none;"><c-f-target-stubtarget="[objectObject]"rpc="[objectObject]"isloggedin="false"></c-f-target-stub></div></div></div><!--endprogress--></div>`;
expect(wrapper.html().replace(/\s/g, "")).to.equal(expectedHtml);
});

Expand All @@ -109,8 +124,10 @@ describe("App.vue", () => {
data() {
return {
rpc: mockRpc, // Provide the mock rpc object
initialTarget: {},
};
},
global,
});

// Check that the computed property returns true
Expand All @@ -123,8 +140,10 @@ describe("App.vue", () => {
return {
rpc: mockRpc, // Provide the mock rpc object
showBusyIndicator: false, // Initialize with a specific value
initialTarget: {},
};
},
global,
});

// Call the setBusyIndicator method with a value of true
Expand All @@ -140,8 +159,10 @@ describe("App.vue", () => {
return {
rpc: mockRpc, // Provide the mock rpc object
showBusyIndicator: true, // Initialize with a specific value
initialTarget: {},
};
},
global,
});

// Call the setBusyIndicator method with a value of false
Expand Down
20 changes: 15 additions & 5 deletions packages/frontend/test/components/CFHeader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ jest.spyOn(window, "getComputedStyle").mockImplementation(() => ({
},
}));

const global = {
stubs: {
VscodeDivider: {
template: "<div></div>",
},
},
};

jest.mock("@vscode/webview-ui-toolkit", () => ({
provideVSCodeDesignSystem: jest.fn(() => ({
register: jest.fn(),
Expand All @@ -24,19 +32,21 @@ jest.mock("@vscode/webview-ui-toolkit", () => ({

describe("CFHeader.vue", () => {
it("renders without errors", () => {
const wrapper = mount(CFHeader);
const wrapper = mount(CFHeader, {
global,
});
expect(wrapper.exists()).to.be.true;
});

it("renders the component with correct content", () => {
const wrapper = mount(CFHeader);
const wrapper = mount(CFHeader, { global });
expect(wrapper.text()).contain("Cloud Foundry Sign In and Targets");
expect(wrapper.text()).contain("Provide your Cloud Foundry parameters to sign in to the Cloud Foundry enviroment");
expect(wrapper.find('[role="separator"]').exists()).to.be.true;
});

it("applies the correct subtitle-field style", () => {
const wrapper = mount(CFHeader);
const wrapper = mount(CFHeader, { global });

// Access the element with class "subtitle-field"
const subtitleField = wrapper.find(".subtitle-field").element;
Expand All @@ -49,8 +59,8 @@ describe("CFHeader.vue", () => {
});

it("renders the correct HTML structure", () => {
const wrapper = mount(CFHeader);
const expectedHtml = `<div><h1wrapping-type="Normal">CloudFoundrySignInandTargets</h1><spanclass="subtitle-field">ProvideyourCloudFoundryparameterstosignintotheCloudFoundryenviroment</span><br><br><vscode-dividerrole="separator"></vscode-divider><br></div>`;
const wrapper = mount(CFHeader, { global });
const expectedHtml = `<div><h1wrapping-type="Normal">CloudFoundrySignInandTargets</h1><spanclass="subtitle-field">ProvideyourCloudFoundryparameterstosignintotheCloudFoundryenviroment</span><br><br><divrole="separator"></div><br></div>`;
expect(wrapper.html().replace(/\s/g, "")).to.equal(expectedHtml);
});
});
Loading

0 comments on commit 16ae0b1

Please sign in to comment.