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

Feature: "SFDX: Open Documentation" (on web) #4414

Merged
merged 13 commits into from
Sep 9, 2022

Conversation

jeffb-sfdc
Copy link
Contributor

What does this PR do?

New feature to open up our docs

What issues does this PR fix or reference?

#https://github.com/forcedotcom/easywriter/issues/85, @W-11683184, W-1168318r@

@jeffb-sfdc jeffb-sfdc requested a review from a team as a code owner September 8, 2022 23:55
@@ -22,7 +22,7 @@ export const messages = {
up_to_five_checkpoints:
'You have %s of the maximum 5 enabled checkpoints. Remove or disable checkpoints until 5 or fewer are active.',
no_enabled_checkpoints:
'You don\'t have any checkpoints enabled. Enable a checkpoint and try again.',
"You don't have any checkpoints enabled. Enable a checkpoint and try again.",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was auto-made when I saved.

@@ -13,7 +13,7 @@
* decorations, e.g., $(x) uses the https://octicons.github.com/ and should not
* be localized
*
* If ommitted, we will assume _message.
* If omitted, we will assume _message.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha! that explains the 26 files...I was like 👀

const functionsPath = '/functions/';

const apexExtension = '.apex';
const soqlExtension = '.soql';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The const above seem like they are reusable outside this command (esp the path/extension values). Think we could move these all to packages/salesforcedx-utils-vscode/src/constants.ts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out there are 11 files named, "constants.ts". There doesn't seem to be any occurrences of constants being using from other packages (like utils) so I placed the extension constants in packages/salesforcedx-vscode-core/src/constants.ts, Let me know if you think they should be in a different file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 that works. we can figure out the right place for all the constants later.

export const lwcDocUrl =
'https://developer.salesforce.com/tools/vscode/en/lwc/writing';
export const functionsDocUrl =
'https://developer.salesforce.com/tools/vscode/en/functions/overview';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add these to the messages files since they include the language?

Copy link
Contributor Author

@jeffb-sfdc jeffb-sfdc Sep 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sbudhirajadoc are there localized versions of these pages?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think only ja and en are supported looking at the site (basically en or ja in the URL). @sbudhirajadoc please correctly me if I'm wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


if (docUrl === '') {
docUrl = defaultDocUrl;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice job handling the case where it doesn't get an active editor.

let openExternalStub: SinonStub;

beforeEach(() => {
sb = createSandbox();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go outside the before each I think https://sinonjs.org/releases/latest/sandbox/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not what we have in our code. Most(and I thought all) of our test code have the createSandbox() call in the beforeEach(). Searching the codebase, I found...
packages/salesforcedx-utils-vscode/test/unit/commands/channelService.test.ts
packages/salesforcedx-utils-vscode/test/unit/commands/commandletExecutor.test.ts
packages/salesforcedx-utils-vscode/test/unit/helpers/traceFlags.test.ts
.
.
.

There are some with it outside the beforeEach(), like in packages/salesforcedx-utils-vscode/test/unit/helpers/paths.test.ts, but the majority of our code has it in there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I think it's wrong in most of our code :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

expect(openExternalStub.getCall(0).args[0].toString()).to.equal(
defaultDocUrl
);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice tests. Are there any failure conditions we can verify? What happens if vscode.env.openExternal throws?

Copy link
Contributor Author

@jeffb-sfdc jeffb-sfdc Sep 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to think of any failure conditions, and I haven't found cases where openExternal fails.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a corner case, but what if the user doesn't have a default browser? It's usually good to know the behaviour (via a unit test) even if we don't expect failure. It documents what we expect to happen. Like if we can't open a browser we should probably be outputting to the user that something went wrong verse just silently doing nothing.

Copy link
Contributor Author

@jeffb-sfdc jeffb-sfdc Sep 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something we get automatically from VSC, and I think writing a unit test for it is writing a test validating VS Code, and doesn't validate our code. As an example, I ran this:

export async function forceOpenDocumentation() {
  let docUrl = '';
  const editor = vscode.window.activeTextEditor;
  if (editor) {
    const filePath = editor.document.fileName;
    const extension = path.extname(filePath);

    throw Error('OK dont do that');
.
.
.

And the user sees this:
image
...so we get the error notification "for free" from VS Code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool. The main thing I'd have expected in the unit test would be validating that the error thrown by the called function is what is get thrown from our calling code. Granted there's not error handling here so we don't have anything extra to verify so I'm cool with just calling it a day. Error conditions is just always something to consider in unit tests.

Copy link
Contributor

@gbockus-sf gbockus-sf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few comments to consider. I can QE after you check em out.

const auraPath = '/force-app/main/default/aura/';
const apexClassesPath = '/force-app/main/default/classes/';
const lwcPath = '/force-app/main/default/lwc/';
const functionsPath = '/functions/';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: FWIW I would have also put these in the constants file. Same deal where any time we need the auraPath we should always use the same value across the codebase. First other place it could be used is in the unit tests to build the stub responses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll go and move them

Copy link
Contributor

@gbockus-sf gbockus-sf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates...started QE

Copy link
Contributor

@gbockus-sf gbockus-sf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Command run: SFDX: Open Documentation

  • ✅ Open Apex section from Apex code
  • ✅ Aura from an Aura Component
  • ✅ Main site from a random non-SF file
  • ✅ Soql doc from soql builder
  • ✅ Functions
  • ✅ Lightning

@jeffb-sfdc jeffb-sfdc merged commit 20f77fa into develop Sep 9, 2022
@jeffb-sfdc jeffb-sfdc deleted the jb/open-documentation-on-web branch September 9, 2022 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants