-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9578 from marmelab/create-react-admin-tests
Add tests to the app generated by create-react-admin with ra-data-fakerest
- Loading branch information
Showing
20 changed files
with
302 additions
and
137 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
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import { ProjectConfiguration } from './ProjectState'; | ||
|
||
export const generateAppFile = ( | ||
projectDirectory: string, | ||
state: ProjectConfiguration | ||
) => { | ||
fs.writeFileSync( | ||
path.join(projectDirectory, 'src', 'App.tsx'), | ||
` | ||
import { Admin, Resource, ListGuesser, EditGuesser, ShowGuesser } from 'react-admin'; | ||
import { Layout } from './Layout'; | ||
${ | ||
state.dataProvider !== 'none' | ||
? `import { dataProvider } from './dataProvider';\n` | ||
: '' | ||
}${ | ||
state.authProvider !== 'none' | ||
? `import { authProvider } from './authProvider';\n` | ||
: '' | ||
} | ||
export const App = () => ( | ||
<Admin | ||
layout={Layout} | ||
${ | ||
state.dataProvider !== 'none' | ||
? `dataProvider={dataProvider}\n\t` | ||
: '' | ||
}${ | ||
state.authProvider !== 'none' | ||
? `\tauthProvider={authProvider}\n\t` | ||
: '' | ||
}> | ||
${state.resources | ||
.map( | ||
resource => | ||
`<Resource name="${resource}" list={ListGuesser} edit={EditGuesser} show={ShowGuesser} />` | ||
) | ||
.join('\n\t\t')} | ||
</Admin> | ||
); | ||
` | ||
); | ||
}; |
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,56 @@ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import { ProjectConfiguration } from './ProjectState'; | ||
|
||
export const generateAppTestFile = ( | ||
projectDirectory: string, | ||
state: ProjectConfiguration | ||
) => { | ||
fs.writeFileSync( | ||
path.join(projectDirectory, 'src', 'App.spec.tsx'), | ||
` | ||
import { fireEvent, render, screen, waitFor } from "@testing-library/react"; | ||
import { App } from "./App"; | ||
test("should pass", async () => { | ||
vi.spyOn(window, "scrollTo").mockImplementation(() => {}); | ||
render(<App />); | ||
${ | ||
state.authProvider !== 'none' | ||
? ` | ||
// Sign in | ||
fireEvent.change(await screen.findByLabelText("Username *"), { | ||
target: { value: "janedoe" }, | ||
}); | ||
fireEvent.change(await screen.findByLabelText("Password *"), { | ||
target: { value: "password" }, | ||
}); | ||
fireEvent.click(await screen.findByText("Sign in"));` | ||
: '' | ||
} | ||
// Open the first post | ||
fireEvent.click(await screen.findByText("Post 1")); | ||
// Update its title | ||
fireEvent.change(await screen.findByDisplayValue("Post 1"), { | ||
target: { value: "Post 1 edited" }, | ||
}); | ||
fireEvent.click(await screen.findByText("Save")); | ||
await screen.findByText("Post 1 edited"); | ||
// Navigate to the comments | ||
fireEvent.click(await screen.findByText("Comments")); | ||
// Open the first comment | ||
fireEvent.click(await screen.findByText("Comment 1")); | ||
// Edit the comment selected post | ||
fireEvent.click(await screen.findByDisplayValue("#0")); | ||
fireEvent.click(await screen.findByText("#11")); | ||
fireEvent.click(await screen.findByText("Save")); | ||
// Check the comment has been updated by finding the post link in the comments list page | ||
await screen.findByText("#11", { selector: "a *" }); | ||
}, 10000); | ||
` | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
Oops, something went wrong.