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

MockPromptForString + doctor to work with ValidatePathError. #325

Merged
merged 11 commits into from
Sep 10, 2020

Conversation

chenlevy24
Copy link
Contributor

Added 'MockPromptForString' and changed 'doctor' to work with 'ValidatePathError'.

Copy link
Collaborator

@PEConn PEConn left a comment

Choose a reason for hiding this comment

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

I'm not quite sure how MockPromptForStrings is meant to be used, could you give an example?

packages/cli/src/spec/mock/MockPromptForStrings.ts Outdated Show resolved Hide resolved
…ed to insert the future answers and it will load them as aa user answer when a prompt is being done
/**
* A class which used for testing and which mocks user's input.
*/
export class MockPromptForStrings implements Prompt {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I just realised this isn't actually "for strings" anymore - it can just be called MockPrompt now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But the messages are always strings

Copy link
Collaborator

Choose a reason for hiding this comment

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

I had thought that the "ForStrings" was about the return type of the methods - for example that promptInput would always return a string (as opposed to a Color or something). The version we've got now works if it's used in a place that returns a Color.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The "forStrings" was for the input we accept, and as for now it's only strings

Copy link
Member

Choose a reason for hiding this comment

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

I had the same impression about T always being a string, which affects the validateFunction input and the Promise<T> output. But T can now have any values and we could drop ForStrings. The fact that addMessages() is always a string seems to be more of an implementation detail?

packages/cli/src/spec/mock/MockPromptForStrings.ts Outdated Show resolved Hide resolved
packages/cli/src/spec/mock/MockPromptForStrings.ts Outdated Show resolved Hide resolved
Comment on lines 103 to 104
const nextResponse = this.responses[0];
this.responses.shift();
Copy link
Member

Choose a reason for hiding this comment

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

Any reason why we're not just calling shift() and assigning the return value to nextResponse?

Suggested change
const nextResponse = this.responses[0];
this.responses.shift();
const nextResponse = this.responses.shift();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, if I do as you say, I get an error because the value could be undefined or string.. Even if I check that it isn't empty before.. this is the only way I could make this work

/**
* A class which used for testing and which mocks user's input.
*/
export class MockPromptForStrings implements Prompt {
Copy link
Member

Choose a reason for hiding this comment

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

I had the same impression about T always being a string, which affects the validateFunction input and the Promise<T> output. But T can now have any values and we could drop ForStrings. The fact that addMessages() is always a string seems to be more of an implementation detail?

import {Result} from '@bubblewrap/core';
import {MockPromptForStrings} from './mock/MockPromptForStrings';

async function validationFunction(message: string): Promise<Result<string, Error>> {
Copy link
Member

Choose a reason for hiding this comment

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

Should we test with a validationFunction that returns something other than a string?

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 don't see how it could change the bottom line.. every case depends on the implementation but with those tests I made sure that the logic of the class is good and functioning (At least I think so)

Copy link
Collaborator

@PEConn PEConn left a comment

Choose a reason for hiding this comment

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

Cool, this is looking good. Thanks for all of your work on it.

Approved (with two small comments).

packages/cli/src/spec/mock/MockPrompt.ts Outdated Show resolved Hide resolved
packages/cli/src/spec/MockPromptSpec.ts Outdated Show resolved Hide resolved
Copy link
Member

@andreban andreban left a comment

Choose a reason for hiding this comment

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

LGTM

@andreban andreban merged commit f0b4fb6 into GoogleChromeLabs:master Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants