generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(app-config-writer): enhance prompt for convert preview config (#…
…2848) * refactor user prompts * add changeset * undo package adjustment * fix typo * fix sonar errors * fix unit tests * fix sonar issue * add unit tests * minor adjustments * refactoring * fix logger * move prompts from create module to app-config-writer * adjust prompt texts * adjust prompt texts II * Update packages/app-config-writer/src/prompt/preview-config.ts Co-authored-by: Louise Findlay <louise.findlay@sap.com> --------- Co-authored-by: Louise Findlay <louise.findlay@sap.com> Co-authored-by: Klaus Keller <66327622+Klaus-Keller@users.noreply.github.com>
- Loading branch information
1 parent
117ae55
commit 42dee4d
Showing
11 changed files
with
200 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@sap-ux/app-config-writer': patch | ||
'@sap-ux/create': patch | ||
--- | ||
|
||
feat: enhance prompt for convert preview config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { getSmartLinksTargetFromPrompt, promptUserPass } from './smartlinks-config'; | ||
export * from './preview-config'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { prompt, type PromptObject, type Answers } from 'prompts'; | ||
|
||
/** | ||
* Prompt if the conversion should be done in simulation. | ||
* | ||
* @returns Indicator if the conversion should be simulated. | ||
*/ | ||
export async function simulatePrompt(): Promise<boolean> { | ||
const PROMPT_NAME = 'simulate'; | ||
const question: PromptObject = { | ||
type: 'confirm', | ||
name: PROMPT_NAME, | ||
initial: true, | ||
message: `The converter renames the local HTML files, deletes the JavaScript and TypeScript files used for the existing preview functionality, and configures virtual endpoints instead. | ||
Do you want to simulate the conversion?` | ||
}; | ||
const answer = (await prompt([question])) as Answers<typeof PROMPT_NAME>; | ||
return ( | ||
answer.simulate ?? (await Promise.reject(new Error('An error has occurred. The conversion has been canceled.'))) | ||
); //in case of doubt, reject | ||
} | ||
|
||
/** | ||
* Prompt if the conversion should include the test runners. | ||
* | ||
* @returns Indicator if the conversion should include test runners. | ||
*/ | ||
export async function includeTestRunnersPrompt(): Promise<boolean> { | ||
const PROMPT_NAME = 'includeTests'; | ||
const question: PromptObject = { | ||
type: 'confirm', | ||
name: PROMPT_NAME, | ||
initial: false, | ||
message: 'Do you want to convert the test runners?' | ||
}; | ||
const answer = (await prompt([question])) as Answers<typeof PROMPT_NAME>; | ||
return ( | ||
answer.includeTests ?? | ||
(await Promise.reject(new Error('An error has occurred. The conversion has been canceled.'))) | ||
); //in case of doubt, reject | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/app-config-writer/test/unit/prompt/preview-config.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { includeTestRunnersPrompt, simulatePrompt } from '../../../src'; | ||
|
||
let promptReturnObject: object; | ||
jest.mock('prompts', () => { | ||
return { | ||
prompt: () => { | ||
return promptReturnObject; | ||
} | ||
}; | ||
}); | ||
|
||
describe('Test prompts for convert preview', () => { | ||
test('Test simulatePrompt - true', async () => { | ||
promptReturnObject = { simulate: true }; | ||
expect(await simulatePrompt()).toBeTruthy(); | ||
}); | ||
|
||
test('Test simulatePrompt - false', async () => { | ||
promptReturnObject = { simulate: false }; | ||
expect(await simulatePrompt()).toBeFalsy(); | ||
}); | ||
|
||
test('Test simulatePrompt - cancel', async () => { | ||
promptReturnObject = { undefined }; | ||
await expect(simulatePrompt()).rejects.toThrowError(); | ||
}); | ||
|
||
test('Test includeTestRunnersPrompt - true', async () => { | ||
promptReturnObject = { includeTests: true }; | ||
expect(await includeTestRunnersPrompt()).toBeTruthy(); | ||
}); | ||
|
||
test('Test includeTestRunnersPrompt - false', async () => { | ||
promptReturnObject = { includeTests: false }; | ||
expect(await includeTestRunnersPrompt()).toBeFalsy(); | ||
}); | ||
|
||
test('Test includeTestRunnersPrompt - cancel', async () => { | ||
promptReturnObject = { undefined }; | ||
await expect(includeTestRunnersPrompt()).rejects.toThrowError(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.