-
Notifications
You must be signed in to change notification settings - Fork 3
feat: added prototype code to make ui grey and present a banner to user #39
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
Open
dlabaj
wants to merge
3
commits into
patternfly:main
Choose a base branch
from
dlabaj:prototype
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,145 @@ | ||
| jest.mock('fs-extra', () => { | ||
| const real = jest.requireActual<typeof import('fs-extra')>('fs-extra'); | ||
| return { | ||
| __esModule: true, | ||
| default: { | ||
| pathExists: jest.fn(), | ||
| readFile: jest.fn(), | ||
| writeFile: jest.fn(), | ||
| existsSync: real.existsSync, | ||
| readFileSync: real.readFileSync, | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| jest.mock('glob', () => ({ | ||
| __esModule: true, | ||
| glob: jest.fn(), | ||
| })); | ||
|
|
||
| import path from 'path'; | ||
| import fs from 'fs-extra'; | ||
| import { glob } from 'glob'; | ||
| import { runPrototype } from '../prototype.js'; | ||
|
|
||
| const mockPathExists = fs.pathExists as jest.MockedFunction<typeof fs.pathExists> & jest.Mock; | ||
| const mockReadFile = fs.readFile as jest.MockedFunction<typeof fs.readFile> & jest.Mock; | ||
| const mockWriteFile = fs.writeFile as jest.MockedFunction<typeof fs.writeFile> & jest.Mock; | ||
| const mockGlob = glob as jest.MockedFunction<typeof glob> & jest.Mock; | ||
|
|
||
| describe('runPrototype', () => { | ||
| const testCwd = '/test/project'; | ||
| const CSS_IMPORT = "import '@patternfly/patternfly-cli/prototype.css';"; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| // Suppress console.log and console.error during tests | ||
| jest.spyOn(console, 'log').mockImplementation(); | ||
| jest.spyOn(console, 'error').mockImplementation(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it('should find and modify src/index.tsx', async () => { | ||
| const indexPath = path.join(testCwd, 'src/index.tsx'); | ||
| const originalContent = `import React from 'react';\nimport ReactDOM from 'react-dom';\n\nReactDOM.render(<App />, document.getElementById('root'));`; | ||
| const expectedContent = `import React from 'react';\nimport ReactDOM from 'react-dom';\n${CSS_IMPORT}\n\nReactDOM.render(<App />, document.getElementById('root'));`; | ||
|
|
||
| mockPathExists.mockResolvedValue(true); | ||
| mockReadFile.mockResolvedValue(originalContent); | ||
| mockWriteFile.mockResolvedValue(undefined); | ||
|
|
||
| await runPrototype(testCwd); | ||
|
|
||
| expect(mockPathExists).toHaveBeenCalledWith(indexPath); | ||
| expect(mockReadFile).toHaveBeenCalledWith(indexPath, 'utf-8'); | ||
| expect(mockWriteFile).toHaveBeenCalledWith(indexPath, expectedContent, 'utf-8'); | ||
| }); | ||
|
|
||
| it('should find and modify src/index.jsx', async () => { | ||
| const tsxPath = path.join(testCwd, 'src/index.tsx'); | ||
| const jsxPath = path.join(testCwd, 'src/index.jsx'); | ||
| const originalContent = `import React from 'react';\n\nReactDOM.render(<App />, document.getElementById('root'));`; | ||
|
|
||
| mockPathExists | ||
| .mockResolvedValueOnce(false) // src/index.tsx doesn't exist | ||
| .mockResolvedValueOnce(true); // src/index.jsx exists | ||
| mockReadFile.mockResolvedValue(originalContent); | ||
| mockWriteFile.mockResolvedValue(undefined); | ||
|
|
||
| await runPrototype(testCwd); | ||
|
|
||
| expect(mockPathExists).toHaveBeenCalledWith(tsxPath); | ||
| expect(mockPathExists).toHaveBeenCalledWith(jsxPath); | ||
| expect(mockReadFile).toHaveBeenCalledWith(jsxPath, 'utf-8'); | ||
| }); | ||
|
|
||
| it('should not modify file if import already exists', async () => { | ||
| const indexPath = path.join(testCwd, 'src/index.tsx'); | ||
| const contentWithImport = `import React from 'react';\n${CSS_IMPORT}\nimport ReactDOM from 'react-dom';\n\nReactDOM.render(<App />, document.getElementById('root'));`; | ||
|
|
||
| mockPathExists.mockResolvedValue(true); | ||
| mockReadFile.mockResolvedValue(contentWithImport); | ||
|
|
||
| await runPrototype(testCwd); | ||
|
|
||
| expect(mockReadFile).toHaveBeenCalledWith(indexPath, 'utf-8'); | ||
| expect(mockWriteFile).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should add import at the beginning if no imports exist', async () => { | ||
| const indexPath = path.join(testCwd, 'src/index.tsx'); | ||
| const originalContent = `const app = document.getElementById('root');\napp.innerHTML = 'Hello';`; | ||
| const expectedContent = `${CSS_IMPORT}\nconst app = document.getElementById('root');\napp.innerHTML = 'Hello';`; | ||
|
|
||
| mockPathExists.mockResolvedValue(true); | ||
| mockReadFile.mockResolvedValue(originalContent); | ||
| mockWriteFile.mockResolvedValue(undefined); | ||
|
|
||
| await runPrototype(testCwd); | ||
|
|
||
| expect(mockWriteFile).toHaveBeenCalledWith(indexPath, expectedContent, 'utf-8'); | ||
| }); | ||
|
|
||
| it('should throw error if no index file is found', async () => { | ||
| mockPathExists.mockResolvedValue(false); | ||
| mockGlob.mockResolvedValue([]); | ||
|
|
||
| await expect(runPrototype(testCwd)).rejects.toThrow('Main index file not found'); | ||
|
|
||
| expect(mockWriteFile).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should use glob to find index file if common locations do not exist', async () => { | ||
| const foundIndexPath = path.join(testCwd, 'app/index.tsx'); | ||
| const originalContent = `import React from 'react';\n\nfunction App() { return <div>Hello</div>; }`; | ||
|
|
||
| mockPathExists.mockResolvedValue(false); | ||
| mockGlob.mockResolvedValue([foundIndexPath]); | ||
| mockReadFile.mockResolvedValue(originalContent); | ||
| mockWriteFile.mockResolvedValue(undefined); | ||
|
|
||
| await runPrototype(testCwd); | ||
|
|
||
| expect(mockGlob).toHaveBeenCalled(); | ||
| expect(mockReadFile).toHaveBeenCalledWith(foundIndexPath, 'utf-8'); | ||
| expect(mockWriteFile).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should prefer src directory when multiple index files are found', async () => { | ||
| const srcIndexPath = path.join(testCwd, 'src/index.tsx'); | ||
| const otherIndexPath = path.join(testCwd, 'other/index.tsx'); | ||
| const originalContent = `import React from 'react';`; | ||
|
|
||
| mockPathExists.mockResolvedValue(false); | ||
| mockGlob.mockResolvedValue([otherIndexPath, srcIndexPath]); | ||
| mockReadFile.mockResolvedValue(originalContent); | ||
| mockWriteFile.mockResolvedValue(undefined); | ||
|
|
||
| await runPrototype(testCwd); | ||
|
|
||
| expect(mockReadFile).toHaveBeenCalledWith(srcIndexPath, 'utf-8'); | ||
| }); | ||
| }); | ||
This file contains hidden or 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 hidden or 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,17 @@ | ||
| import * as React from "react"; | ||
| import { Banner, Bullseye } from "@patternfly/react-core"; | ||
|
|
||
| export interface ProtoProps { | ||
| message?: string; | ||
| } | ||
| const ProtoBanner: React.FC<ProtoProps> = ({ message = "This application is a design prototype"}) => { | ||
| return ( | ||
| <Banner isSticky> | ||
| <Bullseye> | ||
| <strong>{message}</strong> | ||
| </Bullseye> | ||
| </Banner> | ||
| ); | ||
| }; | ||
|
|
||
| export default ProtoBanner; |
This file contains hidden or 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,2 @@ | ||
| // Export React components | ||
| export { default as ProtoBanner } from './components/protoBanner.js'; |
This file contains hidden or 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,3 @@ | ||
| html { | ||
| filter: grayscale(100%); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: patternfly/patternfly-cli
Length of output: 378
🏁 Script executed:
Repository: patternfly/patternfly-cli
Length of output: 86
🏁 Script executed:
Repository: patternfly/patternfly-cli
Length of output: 2204
🏁 Script executed:
Repository: patternfly/patternfly-cli
Length of output: 2206
🏁 Script executed:
Repository: patternfly/patternfly-cli
Length of output: 1200
🏁 Script executed:
Repository: patternfly/patternfly-cli
Length of output: 2532
Mock
inquirer.promptso tests do not hang waiting for user input.runPrototypecallsinquirer.prompt()at line 206 ofsrc/prototype.ts, but this test file lacks a mock forinquirer. All test cases will hang or fail in CI environments without it.Proposed fix
🤖 Prompt for AI Agents