Skip to content

Commit

Permalink
updated - added code for new config folder
Browse files Browse the repository at this point in the history
  • Loading branch information
SuparnaSuresh committed Dec 4, 2024
1 parent 499247d commit 9c3b83a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 21 deletions.
53 changes: 32 additions & 21 deletions src/test/GradleSingleModLCLSTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,63 @@ const assert = require('assert');
describe('LCLS Test for Gradle Project', function () {
let editor: TextEditor;

before(() => {
utils.copyConfig(path.join(utils.getGradleProjectPath(), 'src', 'main', 'liberty', 'config'),path.join(utils.getGradleProjectPath(), 'src', 'main', 'liberty', 'config2'));
});

it('should apply quick fix for invalid value in server.xml', async () => {
const section = await new SideBarView().getContent().getSection(constants.GRADLE_PROJECT);
section.expand();
await VSBrowser.instance.openResources(path.join(utils.getGradleProjectPath(), 'src', 'main', 'liberty', 'config', 'server.xml'));
await VSBrowser.instance.openResources(path.join(utils.getGradleProjectPath(), 'src', 'main', 'liberty', 'config2', 'server.xml'));

editor = await new EditorView().openEditor('server.xml') as TextEditor;
const actualContent = await editor.getText();
const stanzaSnippet = "<logging appsWriteJson = \"wrong\" />";
const expectedText = "<logging appsWriteJson = \"true\" />";
await editor.typeTextAt(18, 5, stanzaSnippet);
const actualSeverXMLContent = await editor.getText();
const stanzaSnipet = "<logging appsWriteJson = \"wrong\" />";
const expectedHoverData = "<logging appsWriteJson = \"true\" />";
await editor.typeTextAt(17, 5, stanzaSnipet);
await utils.delay(2000);
const flaggedString = await editor.findElement(By.xpath("//*[contains(text(), '\"wrong\"')]"));
const flagedString = await editor.findElement(By.xpath("//*[contains(text(), '\"wrong\"')]"));
await utils.delay(3000);

const actions = VSBrowser.instance.driver.actions();
await actions.move({ origin: flaggedString }).perform();
await actions.move({ origin: flagedString }).perform();
await utils.delay(3000);

const driver = VSBrowser.instance.driver;
const hoverValue = await editor.findElement(By.className('hover-row status-bar'));
const hoverTxt= await editor.findElement(By.className('hover-row status-bar'));
await utils.delay(2000);

const quickFixPopupLink = await hoverValue.findElement(By.xpath("//*[contains(text(), 'Quick Fix')]"));
await quickFixPopupLink.click();
const qckFixPopupLink = await hoverTxt.findElement(By.xpath("//*[contains(text(), 'Quick Fix')]"));
await qckFixPopupLink.click();

const hoverBar = await editor.findElement(By.className('context-view monaco-component bottom left fixed'));
await hoverBar.findElement(By.className('actionList'));
const hoverTaskBar = await editor.findElement(By.className('context-view monaco-component bottom left fixed'));
await hoverTaskBar.findElement(By.className('actionList'));
await utils.delay(2000);

const pointerBlockElementt = await driver.findElement(By.css('.context-view-pointerBlock'));
const pointerBlockedElement = await driver.findElement(By.css('.context-view-pointerBlock'));
// Setting pointer block element display value as none to choose option from Quickfix menu
if (pointerBlockElementt) {
await driver.executeScript("arguments[0].style.display = 'none';", pointerBlockElementt);
if (pointerBlockedElement) {
await driver.executeScript("arguments[0].style.display = 'none';", pointerBlockedElement);
} else {
console.log('pointerBlockElementt not found!');
}
const fixOption = await editor.findElement(By.xpath("//*[contains(text(), \"Replace with 'true'\")]"));
await fixOption.click();
const qckfixOption = await editor.findElement(By.xpath("//*[contains(text(), \"Replace with 'true'\")]"));
await qckfixOption.click();

const updatedContent = await editor.getText();
const updatedSeverXMLContent = await editor.getText();
await utils.delay(3000);
console.log("Content after Quick fix : ", updatedContent);
assert(updatedContent.includes(expectedText), 'quick fix not applied correctly.');
console.log("Content after Quick fix : ", updatedSeverXMLContent);
assert(updatedSeverXMLContent.includes(expectedHoverData), 'Quick fix not applied correctly.');
await editor.clearText();
await editor.setText(actualContent);
await editor.setText(actualSeverXMLContent);
console.log("Content restored");

}).timeout(38000);

after(() => {

utils.removeProjectFolderWithContent(path.join(utils.getGradleProjectPath(), 'src', 'main', 'liberty', 'config2'));
console.log("Removed new config folder:");

});
});
31 changes: 31 additions & 0 deletions src/test/utils/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MAVEN_PROJECT, STOP_DASHBOARD_MAC_ACTION } from '../definitions/consta
import { MapContextMenuforMac } from './macUtils';
import clipboard = require('clipboardy');
import { expect } from 'chai';
import * as fse from 'fs-extra';

export function delay(millisec: number) {
return new Promise( resolve => setTimeout(resolve, millisec) );
Expand Down Expand Up @@ -192,4 +193,34 @@ export async function clearCommandPalette() {
expect(buttons.length).equals(2);
await dialog.pushButton('Clear');
}

/**
* Remove newly created Project folder with content
*/
export async function removeProjectFolderWithContent(projectPath: string): Promise<void> {
try {
await fs.accessSync(projectPath);
const projectContent = await fs.readdirSync(projectPath);
await Promise.all(
projectContent.map(async (projectFiles) => {
const projectContentPath = path.join(projectPath, projectFiles);
const stats = await fs.lstatSync(projectContentPath);
if (stats.isDirectory()) {
await removeProjectFolderWithContent(projectContentPath);
} else {
await fs.unlinkSync(projectContentPath);
}
})
);
await fs.rmdirSync(projectPath);
} catch (error) {
console.error(`Error removing new project: ${error}`);
}
}

export async function copyConfig(existingConfigPath: string, copyConfigPath: string): Promise<void> {
fse.copy(existingConfigPath, copyConfigPath)
.then(() => console.log("New config folder created :" + copyConfigPath))
.catch(err => console.log("Error creating config folder"));
}

0 comments on commit 9c3b83a

Please sign in to comment.