Skip to content

Commit

Permalink
Added E2E for #114 (#183)
Browse files Browse the repository at this point in the history
## Summary

Added E2E for #114. 
Creating new TST that imports an coded test. Check in E2E if we can edit
the coded test with `// vmock` autocompletion.

## Added
`vcast_coded_tests_relative_path.test.ts` E2E test.
Added `import_coded_tests` spec group.
  • Loading branch information
Den1552 authored Aug 29, 2024
1 parent 1f6b65f commit 37d33d8
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 6 deletions.
183 changes: 183 additions & 0 deletions tests/internal/e2e/test/specs/vcast_coded_tests_relative_path.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
// Test/specs/vcast.test.ts
import {
type BottomBarPanel,
type TextEditor,
type Workbench,
type TreeItem,
} from "wdio-vscode-service";
import { Key } from "webdriverio";
import {
getViewContent,
findSubprogram,
updateTestID,
expandWorkspaceFolderSectionInExplorer,
getTestHandle,
} from "../test_utils/vcast_utils";

describe("vTypeCheck VS Code Extension", () => {
let bottomBar: BottomBarPanel;
let workbench: Workbench;
const TIMEOUT = 20_000;
before(async () => {
workbench = await browser.getWorkbench();
// Opening bottom bar and problems view before running any tests
bottomBar = workbench.getBottomBar();
await bottomBar.toggle(true);
process.env.E2E_TEST_ID = "0";
});

it("test 1: should be able to load VS Code", async () => {
await updateTestID();
expect(await workbench.getTitleBar().getTitle()).toBe(
"[Extension Development Host] vcastTutorial - Visual Studio Code"
);
});

it("should activate vcastAdapter", async () => {
await updateTestID();

await browser.keys([Key.Control, Key.Shift, "p"]);
// Typing Vector in the quick input box
// This brings up VectorCAST Test Explorer: Configure
// so just need to hit Enter to activate
for (const character of "vector") {
await browser.keys(character);
}

await browser.keys(Key.Enter);

const activityBar = workbench.getActivityBar();
const viewControls = await activityBar.getViewControls();
for (const viewControl of viewControls) {
console.log(await viewControl.getTitle());
}

await bottomBar.toggle(true);
const outputView = await bottomBar.openOutputView();

console.log("Waiting for VectorCAST activation");
await $("aria/VectorCAST Test Pane Initialization");
console.log("WAITING FOR TESTING");
await browser.waitUntil(
async () => (await activityBar.getViewControl("Testing")) !== undefined,
{ timeout: TIMEOUT }
);
console.log("WAITING FOR TEST EXPLORER");
await browser.waitUntil(async () =>
(await outputView.getChannelNames())
.toString()
.includes("VectorCAST Test Explorer")
);
await outputView.selectChannel("VectorCAST Test Explorer");
console.log("Channel selected");
console.log("WAITING FOR LANGUAGE SERVER");
await browser.waitUntil(
async () =>
(await outputView.getText())
.toString()
.includes("Starting the language server"),
{ timeout: TIMEOUT }
);

const testingView = await activityBar.getViewControl("Testing");
await testingView?.openView();
});

it("should set default config file", async () => {
await updateTestID();

const workbench = await browser.getWorkbench();
const activityBar = workbench.getActivityBar();
const explorerView = await activityBar.getViewControl("Explorer");
await explorerView?.openView();

const workspaceFolderSection =
await expandWorkspaceFolderSectionInExplorer("vcastTutorial");

const configFile = await workspaceFolderSection.findItem("CCAST_.CFG");
await configFile.openContextMenu();
await (await $("aria/Set as VectorCAST Configuration File")).click();
});

it("should enable coded test", async () => {
await updateTestID();

const workbench = await browser.getWorkbench();
const settingsEditor = await workbench.openSettings();
console.log("Looking for coded tests settings");
await settingsEditor.findSetting(
"vectorcastTestExplorer.enableCodedTesting"
);
// Only one setting in search results, so the current way of clicking is correct
console.log("Enabling coded tests");
await (await settingsEditor.checkboxSetting$).click();
await workbench.getEditorView().closeAllEditors();
});

it("should check for vmock code completion", async () => {
await updateTestID();

console.log("Opening Testing View");
const vcastTestingViewContent = await getViewContent("Testing");

let subprogram: TreeItem;
let testHandle: TreeItem;

// Iterate over sections to find the "moo" subprogram and expand it
for (const section of await vcastTestingViewContent.getSections()) {
subprogram = await findSubprogram("moo", section);
if (subprogram) {
// Expand the subprogram if it's not already expanded
if (!(await subprogram.isExpanded())) await subprogram.expand();
console.log("Getting test handle");

testHandle = await getTestHandle(
subprogram,
"Coded Tests",
"mooTests.ExampleTestCase",
1
);

if (testHandle) break;
throw new Error("Test handle not found for mooTests.ExampleTestCase");
}
}

expect(testHandle).not.toBe(undefined);

let contextMenu = await testHandle.openContextMenu();
await contextMenu.select("VectorCAST");

let menuElement = await $("aria/Edit Coded Test");
await menuElement.click();

// Wait until the "tests.cpp" tab is active in the editor view
const editorView = workbench.getEditorView();
await browser.waitUntil(
async () =>
(await (await editorView.getActiveTab()).getTitle()) === "tests.cpp"
);

// Open the "tests.cpp" file in the editor and trigger code completion
const tab = (await editorView.openEditor("tests.cpp")) as TextEditor;
await browser.keys([Key.Ctrl, Key.Space]);

const contentAssist = await tab.toggleContentAssist(true);

// Just do some autocompletion to see if we can edit the Coded Test
await tab.setTextAtLine(14, "// vmock");
let currentLine = await tab.getLineOfText("// vmock");
await tab.typeTextAt(currentLine, "// vmock".length + 1, " ");
await tab.save();
await browser.waitUntil(
async () => (await contentAssist.getItems()).length > 0
);

// Validating content assist for '// vmock'
const expectedItems = ["moo", "Prototype-Stubs"];

for (const item of expectedItems) {
expect(await contentAssist.hasItem(item)).toBe(true);
}
});
});
6 changes: 6 additions & 0 deletions tests/internal/e2e/test/specs_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ export function getSpecGroups(useVcast24: boolean) {
env: {},
params: {},
};

specGroups["import_coded_test"] = {
specs: ["./**/**/vcast_coded_tests_relative_path.test.ts"],
env: { IMPORT_CODED_TEST_IN_TST: "True" },
params: {},
};
}

return specGroups;
Expand Down
9 changes: 3 additions & 6 deletions tests/internal/e2e/test/wdio.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export const config: Options.Testrunner = {

if (envKey) {
// Execute the corresponding function if an environment variable is found
await envActions.get(envKey)!();
await envActions.get(envKey)();
} else {
// Default case if no matching environment variable is found
await setupSingleEnvironment(initialWorkdir);
Expand Down Expand Up @@ -426,7 +426,7 @@ export const config: Options.Testrunner = {
}

/**
* Builds one env with 2024sp3 and switches to vc24__101394_store_mock_info at the end.
* Builds one env with 2024sp3 and switches to vc24 at the end.
* TARGET SPEC GROUP: coded_mock_different_env
*/
async function setupSingleEnvAndImportCT(initialWorkdir: string) {
Expand All @@ -444,7 +444,7 @@ export const config: Options.Testrunner = {
);

let vcastRoot = await getVcastRoot();
const newVersion = "vc24__101394_store_mock_info";
const newVersion = "release24";

// Set up environment directory
process.env.VECTORCAST_DIR = path.join(vcastRoot, newVersion);
Expand All @@ -457,9 +457,6 @@ export const config: Options.Testrunner = {
await executeRGWCommands(testInputVcastTutorial);
await copyPathsToTestLocation(testInputVcastTutorial);

// Log that SWITCH_ENV_AT_THE_END is being defined
console.log("SWITCH_ENV_AT_THE_END IS DEFINED");

// Define paths and content for the necessary test files
const unitFileContent = `void foo (void){}`;
const unitFile = path.join(workspacePath, "moo.cpp");
Expand Down

0 comments on commit 37d33d8

Please sign in to comment.