Skip to content

Commit

Permalink
chore: test resource graph command
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneswuerbach committed Jun 5, 2024
1 parent a98895d commit 6dba26d
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { HumctlAdapter } from './adapters/humctl/HumctlAdapter';
import { LoginController } from './controllers/LoginController';
import { LoginService } from './services/LoginService';

const loggerChannel = vscode.window.createOutputChannel('Humanitec');
export const loggerChannel = vscode.window.createOutputChannel('Humanitec');

export async function activate(context: vscode.ExtensionContext) {
const logger = new LoggerService(loggerChannel);
Expand Down
105 changes: 105 additions & 0 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import waitForExpect from 'wait-for-expect';
import { HumanitecSidebarController } from '../../controllers/HumanitecSidebarController';
import { ConfigurationRepository } from '../../repos/ConfigurationRepository';
import { ConfigKey } from '../../domain/ConfigKey';
import { Environment } from '../../domain/Environment';
import { loggerChannel } from '../../extension';

const wait = (ms: number) =>
new Promise<void>(resolve => setTimeout(() => resolve(), ms));
Expand All @@ -31,6 +33,8 @@ suite('Extension Test Suite', () => {
let sandbox: sinon.SinonSandbox;
let showErrorMessage: sinon.SinonSpy;

const outputs: string[] = [];

beforeEach(async () => {
sandbox = sinon.createSandbox();
showErrorMessage = sandbox
Expand All @@ -42,6 +46,11 @@ suite('Extension Test Suite', () => {
}
);

sandbox.stub(loggerChannel, 'appendLine').callsFake((value: string) => {
console.log('output', value);
outputs.push(value);
});

humanitecOrg = readEnv('TEST_HUMANITEC_ORG');
humanitecToken = readEnv('TEST_HUMANITEC_TOKEN');

Expand Down Expand Up @@ -157,4 +166,100 @@ suite('Extension Test Suite', () => {
500
);
});

suite('resource graph', () => {
test('fails without app / env', async () => {
await vscode.commands.executeCommand(
'humanitec.sidebar.organization_structure.set_in_workspace',
new Organization(humanitecOrg, 'test-org')
);

await vscode.commands.executeCommand('humanitec.display_resources_graph');

await waitForExpect(
() => {
expect(showErrorMessage).to.have.been.called;
},
10000,
500
);

expect(showErrorMessage).to.have.been.calledWith(
'There is no enough context to process the request. Required context is: Application'
);
});

// TODO: We might want to improve this case.
test('fails with a not existing app / env', async () => {
await vscode.commands.executeCommand(
'humanitec.sidebar.organization_structure.set_in_workspace',
new Environment(
'development',
'Development',
humanitecOrg,
'not-found-app'
)
);

await vscode.commands.executeCommand('humanitec.display_resources_graph');

await waitForExpect(
() => {
expect(showErrorMessage).to.have.been.called;
},
10000,
500
);

expect(showErrorMessage).to.have.been.calledWith(
'Unexpected error occurred. Please contact the extension developer'
);
});

// TODO: We might want to improve this case.
test('fails with a not deployed app / env', async () => {
await vscode.commands.executeCommand(
'humanitec.sidebar.organization_structure.set_in_workspace',
new Environment(
'development',
'Development',
humanitecOrg,
'not-deployed'
)
);

await vscode.commands.executeCommand('humanitec.display_resources_graph');

await waitForExpect(
() => {
expect(showErrorMessage).to.have.been.called;
},
10000,
500
);

expect(showErrorMessage).to.have.been.calledWith(
'Environment development has no deployments. Deploy application to development environment first.'
);
});

test('works with a deployed app / env', async () => {
await vscode.commands.executeCommand(
'humanitec.sidebar.organization_structure.set_in_workspace',
new Environment('development', 'Development', humanitecOrg, 'deployed')
);

await vscode.commands.executeCommand('humanitec.display_resources_graph');

await waitForExpect(
() => {
expect(
vscode.window.tabGroups.activeTabGroup.activeTab?.label
).to.equal('Resources Graph');
},
10000,
500
);
});
});
});

0 comments on commit 6dba26d

Please sign in to comment.