Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: extract createFile func #99

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions test/specs/manifestBuilder.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,8 @@ describe('Manifest Builder', async () => {
const workbench = await browser.getWorkbench();

// Using the Command palette, run File: New File...
const inputBox = await utilities.executeQuickPick(
'Create: New File...',
utilities.Duration.seconds(1)
);

// Set the name of the new manifest file
const filePath = path.join('manifest', 'manifest.xml');
await inputBox.setText(filePath);

// The following 3 confirms are just confirming the file creation and the folder it will belong to
await inputBox.confirm();
await inputBox.confirm();
await inputBox.confirm();
await utilities.createFile(path.join('manifest', 'manifest.xml'));
await browser.keys(['Enter']); // This extra step is necessary, otherwise the process to create file here doesn't finish.

const textEditor = await utilities.getTextEditor(workbench, 'manifest.xml');
const content = [
Expand Down
18 changes: 3 additions & 15 deletions test/specs/miscellaneous.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('Miscellaneous', async () => {
const workbench = await utilities.getWorkbench();
const commandName =
EnvironmentSettings.getInstance().vscodeVersion === 'stable' ||
semver.gte(EnvironmentSettings.getInstance().vscodeVersion, '1.92.0')
semver.gte(EnvironmentSettings.getInstance().vscodeVersion, '1.92.0')
? 'Snippets: Configure Snippets'
: 'Snippets: Configure User Snippets';

Expand Down Expand Up @@ -96,13 +96,7 @@ describe('Miscellaneous', async () => {
].join('\n');

// Create simple lwc.html file
const inputBox = await utilities.executeQuickPick(
'Create: New File...',
utilities.Duration.seconds(1)
);
await inputBox.setText('lwc.html');
await browser.keys(['Enter']);
await browser.keys(['Enter']);
await utilities.createFile('lwc.html');

// Type snippet "lwc-button" and check it inserted the right lwc
const textEditor = await utilities.getTextEditor(workbench, 'lwc.html');
Expand Down Expand Up @@ -130,13 +124,7 @@ describe('Miscellaneous', async () => {
const lwcSnippet = 'this.dispatchEvent(new CustomEvent("event-name"));';

// Create simple lwc.js file
const inputBox = await utilities.executeQuickPick(
'Create: New File...',
utilities.Duration.seconds(1)
);
await inputBox.setText('lwc.js');
await browser.keys(['Enter']);
await browser.keys(['Enter']);
await utilities.createFile('lwc.js');

// Type snippet "lwc", select "lwc-event" and check it inserted the right thing
const textEditor = await utilities.getTextEditor(workbench, 'lwc.js');
Expand Down
13 changes: 4 additions & 9 deletions test/utilities/apexUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { TextEditor } from 'wdio-vscode-service';
import { executeQuickPick } from './commandPrompt.ts';
import { Duration, getTextEditor, pause } from './miscellaneous.ts';
import { Duration, getTextEditor, pause, createFile } from './miscellaneous.ts';
import { getWorkbench } from './workbench.ts';

export async function createApexClass(
Expand Down Expand Up @@ -107,16 +107,11 @@ export async function createApexClassWithBugs(): Promise<void> {
export async function createAnonymousApexFile(): Promise<void> {
const workbench = await getWorkbench();
const editorView = workbench.getEditorView();
const anonymousApexFileName = 'Anonymous.apex';

// Using the Command palette, run File: New File...
const inputBox = await executeQuickPick('Create: New File...', Duration.seconds(1));
await createFile(anonymousApexFileName);

// Set the name of the new Anonymous Apex file
await inputBox.setText('Anonymous.apex');
await browser.keys(['Enter']);
await browser.keys(['Enter']);

const textEditor = (await editorView.openEditor('Anonymous.apex')) as TextEditor;
const textEditor = (await editorView.openEditor(anonymousApexFileName)) as TextEditor;
await textEditor.setText("System.debug('¡Hola mundo!');");
await textEditor.save();
await pause(Duration.seconds(1));
Expand Down
16 changes: 16 additions & 0 deletions test/utilities/miscellaneous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,19 @@ export class Duration extends DurationKit.Duration {
return new Duration(quantity, Unit.WEEKS);
}
}


/**
* The function is not the best practice.
* We have observed that after installing the extension, the first time you specify the path with the command works,
* But it does not work for following file creation, it will ignore the path you specify but always follow the path from the first time
*/
export async function createFile(path: string): Promise<void> {
// Using the Command palette, run File: New File...
const inputBox = await executeQuickPick('Create: New File...', Duration.seconds(1));

// Set the filepath
await inputBox.setText(path);
await browser.keys(['Enter']);
await browser.keys(['Enter']);
}