Skip to content

Commit

Permalink
test list ok
Browse files Browse the repository at this point in the history
  • Loading branch information
maxime-urbanski committed Jun 26, 2024
1 parent 34d8057 commit 0730ef7
Show file tree
Hide file tree
Showing 14 changed files with 16,746 additions and 1,020 deletions.
14,484 changes: 14,484 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"tmp": "^0.2.0"
},
"dependencies": {
"@angular/cli": "^18.0.5",
"@api-platform/api-doc-parser": "^0.16.0",
"@babel/runtime": "^7.0.0",
"chalk": "^5.0.0",
Expand Down
7 changes: 4 additions & 3 deletions src/generators/AngularGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export default class extends BaseGenerator {
"app/app.component.html",
"app/app.component.ts",

// CONFIG
"app/app.config.ts",

//INTERFACE
"app/interface/api.ts",

Expand All @@ -71,9 +74,6 @@ export default class extends BaseGenerator {

handlebars.registerHelper("compare", hbhComparison.compare);
handlebars.registerHelper("lowercase", hbhString.lowercase);
handlebars.registerHelper("get_length", function (obj) {
return obj.length;
});
}

help(resource) {
Expand Down Expand Up @@ -180,6 +180,7 @@ export default class extends BaseGenerator {
"app/router/index.ts",
"app/app.component.html",
"app/app.component.ts",
"app/app.config.ts",
"app/app.routes.ts",
].forEach((file) =>
this.createFile(file, `${dir}/${file}`, context, false)
Expand Down
11 changes: 8 additions & 3 deletions src/generators/AngularGenerator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,20 @@ describe("generate", () => {
].forEach((file) => expect(fs.existsSync(tmpobj.name + file)).toBe(true));

[
"app/router/abc.ts",
"app/components/abc/list/list.component.html",
"app/components/abc/list/list.component.ts",
"app/components/abc/create/create.component.html",
"app/components/abc/create/create.component.ts",
"app/components/abc/edit/edit.component.html",
"app/components/abc/edit/edit.component.ts",
"app/components/abc/list/list.component.html",
"app/components/abc/list/list.component.ts",
"app/components/abc/form/form.component.html",
"app/components/abc/form/form.component.ts",
"app/components/abc/show/show.component.html",
"app/components/abc/show/show.component.ts",
"/interfaces/Abc.ts",
"app/components/abc/show/show.component.html",
"app/components/abc/table/table.component.html",
"app/components/abc/table/table.component.ts",
].forEach((file) => {
expect(fs.existsSync(tmpobj.name + file)).toBe(true);
expect(fs.readFileSync(tmpobj.name + file, "utf8")).toMatch(/bar/);
Expand Down
14 changes: 14 additions & 0 deletions templates/angular/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ApplicationConfig, provideZoneChangeDetection } from "@angular/core";
import { provideRouter } from "@angular/router";
import { routes } from "./app.routes";
import { provideClientHydration } from "@angular/platform-browser";
import { provideHttpClient, withFetch } from "@angular/common/http";

export const appConfig: ApplicationConfig = {
providers: [
provideZoneChangeDetection({ eventCoalescing: true }),
provideRouter(routes),
provideHttpClient(withFetch()),
provideClientHydration(),
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,30 @@
<nav aria-label="Page navigation">
<ul class="flex list-style-none">
<li>
<a [routerLink]="['/books']"
[queryParams]="pageParamValue('hydra:first')"
[routerLinkActive]="'bg-gray-200 text-gray-500 pointer-events-none'"
<a [routerLink]="pagination()['hydra:first']"
(click)="changeUri(pagination()!['hydra:first'])"
class="bg-gray block py-2 px-3 rounded"
aria-label="First page">
<span aria-hidden="true">&lArr;</span>First
</a>
</li>
@if (pagination()!['hydra:previous']) {
<li>
<a [routerLink]="['/books']"
[queryParams]="pageParamValue('hydra:previous')"
[routerLinkActive]="'bg-gray-200 text-gray-500 pointer-events-none'"
(click)="changeUri(pagination()!['hydra:previous'])"
class="bg-gray block py-2 px-3 rounded"
aria-label="Previous page">
Previous
</a>
</li>
}
@if (pagination()!['hydra:next']) {
<li>
<a [routerLink]="['/books']"
[queryParams]="pageParamValue('hydra:next')"
[routerLinkActive]="'bg-gray-200 text-gray-500 pointer-events-none'"
<a [routerLink]="pagination()['hydra:previous']"
(click)="changeUri(pagination()!['hydra:previous'])"
class="bg-gray block py-2 px-3 rounded"
aria-label="Previous page">
Previous
</a>
<li>
<a [routerLink]="pagination()['hydra:next']"
(click)="changeUri(pagination()!['hydra:next'])"
class="bg-gray block py-2 px-3 rounded"
aria-label="Next page">
Next
</a>
</li>
}
<li>
<a [routerLink]="['/books']"
[queryParams]="pageParamValue('hydra:last')"
[routerLinkActive]="'bg-gray-200 text-gray-500 pointer-events-none'"
<a [routerLink]="pagination()['hydra:last']"
(click)="changeUri(pagination()!['hydra:last'])"
class="bg-gray block py-2 px-3 rounded"
aria-label="Last page">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ export class PaginationComponent {
@Input() pagination!: WritableSignal<Pagination>;
@Output() handleChangePage = new EventEmitter()

pageParamValue(page: keyof Pagination) {
const pageParams = this.pagination()[page].split('?page=')
return {
page: pageParams![1]
}
}

changeUri(uri: string) {
this.handleChangePage.emit(uri)
}
Expand Down
4 changes: 2 additions & 2 deletions templates/angular/app/interface/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export interface ApiList {
}

export interface ApiShow extends Api {
[key: string]: string | null | undefined;
[key: string]: string | undefined;
}

export interface ApiItem extends Api {
[key: string]: string | null | undefined;
[key: string]: string | undefined;
}

export interface Pagination {
Expand Down
3 changes: 3 additions & 0 deletions templates/common/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ module.exports = {
"./pages/**/*.vue",
"./plugins/**/*.ts",
"./nuxt.config.ts",
//ANGULAR
"./src/app/components/**/**/*.component.ts",
"./src/app/components/**/**/*.component.html",
],
theme: {
extend: {},
Expand Down
12 changes: 6 additions & 6 deletions testapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,23 @@ if [ "$1" = "vue" ]; then
cp ./templates/vue/main.ts ./tmp/app/vue/src
cp ./templates/vue/App.vue ./tmp/app/vue/src
yarn --cwd ./tmp/app/vue build
start-server-and-test 'yarn --cwd ./tmp/app/vue vite preview --port 3000' http://localhost:3000/books/ 'yarn playwright test'
start-server-and-test 'yarn --cwd ./tmp/app/vue vite preview' http://localhost:3000/books/ 'yarn playwright test'
fi

if [ "$1" = "angular" ]; then
cd ./tmp/app
npm install -g @angular/cli
npm install @angular/cli

ng new angular --ssr --style=css
ng new angular --ssr --standalone --style=css
cd ../..
yarn --cwd ./tmp/app/angular add tailwindcss postcss autoprefixer dayjs
yarn --cwd ./tmp/app/angular tailwindcss init -p

cp ./templates/common/tailwind.config.js ./tmp/app/angular
cp ./templates/common/style.css ./tmp/app/angular/src
cp ./templates/common/style.css ./tmp/app/angular/src/styles.css

cp -R ./tmp/angular/* ./tmp/app/angular/src

file="./tmp/app/angular/tsconfig.json"
newContent='"baseUrl": "./src",\
"paths": {\
Expand All @@ -99,7 +100,6 @@ if [ "$1" = "angular" ]; then
"@utils/*" : ["app/utils/*"],\
},'
sed -i.bak '21a\'"$newContent" "$file"
cat ./tmp/app/angular/tsconfig.json
yarn --cwd ./tmp/app/angular build
start-server-and-test 'yarn --cwd ./tmp/app/angular start' http://127.0.0.1:4200/books/ 'yarn playwright test'
start-server-and-test 'BROWSER=none yarn --cwd ./tmp/app/angular start --port=3000' http://127.0.0.1:3000/books/ 'yarn playwright test'
fi
2 changes: 1 addition & 1 deletion testgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [ $ENTRYPOINT ]; then
entrypoint="$ENTRYPOINT"
fi

gens="angular"
gens="next angular"
if [ $1 ]; then
gens="$1"
fi
Expand Down
75 changes: 47 additions & 28 deletions tests/edit.spec.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,60 @@
import { test as baseTest, expect } from '@playwright/test';
import { locatorFixtures as fixtures } from '@playwright-testing-library/test/fixture.js';
import type { LocatorFixtures as TestingLibraryFixtures } from '@playwright-testing-library/test/fixture.js';

const test = baseTest.extend<TestingLibraryFixtures>(fixtures)

test('resource edit', async ({ page, within, queries: { getAllByRole, getByLabelText, getByRole, getByText, queryByRole, queryByText } }) => {
await page.goto('http://localhost:3000/books/');

await expect(queryByText('Loading...')).not.toBeVisible();

await expect(queryByRole('heading', { level: 1, name: 'Book List' })).toBeVisible();

const rows = getAllByRole('row');
import { test as baseTest, expect } from "@playwright/test";
import { locatorFixtures as fixtures } from "@playwright-testing-library/test/fixture.js";
import type { LocatorFixtures as TestingLibraryFixtures } from "@playwright-testing-library/test/fixture.js";

const test = baseTest.extend<TestingLibraryFixtures>(fixtures);

test("resource edit", async ({
page,
within,
queries: {
getAllByRole,
getByLabelText,
getByRole,
getByText,
queryByRole,
queryByText,
},
}) => {
await page.goto("http://localhost:3000/books/");

await expect(queryByText("Loading...")).not.toBeVisible();

await expect(
queryByRole("heading", { level: 1, name: "Book List" })
).toBeVisible();

const rows = getAllByRole("row");

const { getAllByRole: getAllByRoleWithinRow } = within(rows.nth(3));

const bookLink = getAllByRoleWithinRow('link').nth(0);
const bookLink = getAllByRoleWithinRow("link").nth(0);
bookLink.click();

await expect(queryByRole('heading', { level: 1, name: /^\s*Show Book/ })).toBeVisible();
await expect(queryByText('Loading...')).not.toBeVisible();
await expect(
queryByRole("heading", { level: 1, name: /^\s*Show Book/ })
).toBeVisible();
await expect(queryByText("Loading...")).not.toBeVisible();

const editLink = getByRole('link', { name: 'Edit' });
const editLink = getByRole("link", { name: "Edit" });
editLink.click();

await expect(queryByRole('heading', { level: 1, name: /^\s*Show Book/ })).not.toBeVisible();
await expect(queryByText('Loading...')).not.toBeVisible();
await expect(
queryByRole("heading", { level: 1, name: /^\s*Show Book/ })
).not.toBeVisible();
await expect(queryByText("Loading...")).not.toBeVisible();

await expect(queryByRole('heading', { level: 1 })).toHaveText(/^\s*Edit Book/);
await expect(queryByRole("heading", { level: 1 })).toHaveText(
/^\s*Edit Book/
);

await expect(queryByText('Loading...')).not.toBeVisible();
await expect(queryByText("Loading...")).not.toBeVisible();

await expect(getByLabelText('isbn')).toBeEditable();
await expect(getByLabelText('description')).toBeEditable();
await expect(getByText('reviews')).toBeVisible();
await expect(getByLabelText("isbn")).toBeEditable();
await expect(getByLabelText("description")).toBeEditable();
await expect(getByText("reviews")).toBeVisible();

await expect(getByRole('button', { name: 'Submit' })).toBeVisible();
await expect(getByRole('button', { name: 'Delete' })).toBeVisible();
await expect(getByRole('link', { name: /Back to list/ })).toBeVisible();
await expect(getByRole("button", { name: "Submit" })).toBeVisible();
await expect(getByRole("button", { name: "Delete" })).toBeVisible();
await expect(getByRole("link", { name: /Back to list/ })).toBeVisible();
});
58 changes: 40 additions & 18 deletions tests/list.spec.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,60 @@
import { test as baseTest, expect } from '@playwright/test';
import { locatorFixtures as fixtures } from '@playwright-testing-library/test/fixture.js';
import type { LocatorFixtures as TestingLibraryFixtures } from '@playwright-testing-library/test/fixture.js';
import { test as baseTest, expect } from "@playwright/test";
import { locatorFixtures as fixtures } from "@playwright-testing-library/test/fixture.js";
import type { LocatorFixtures as TestingLibraryFixtures } from "@playwright-testing-library/test/fixture.js";

const test = baseTest.extend<TestingLibraryFixtures>(fixtures)
const test = baseTest.extend<TestingLibraryFixtures>(fixtures);

test('resource list', async ({ page, within, queries: { getAllByRole, getByLabelText, getByRole, queryByRole, queryByText } }) => {
await page.goto('http://localhost:3000/books/');
test("resource list", async ({
page,
within,
queries: {
getAllByRole,
getByLabelText,
getByRole,
queryByRole,
queryByText,
},
}) => {
await page.goto("http://localhost:3000/books/");

await expect(queryByText('Loading...')).not.toBeVisible();
await expect(queryByText("Loading...")).not.toBeVisible();

await expect(queryByRole('heading', { level: 1 })).toHaveText('Book List');
await expect(queryByRole("heading", { level: 1 })).toHaveText("Book List");

await expect(getByRole('link', { name: 'Create' })).toBeVisible();
await expect(getByRole("link", { name: "Create" })).toBeVisible();

const cols = getAllByRole('rowgroup').nth(0);
const cols = getAllByRole("rowgroup").nth(0);
const { getByRole: getByRoleWithinCols } = within(cols);

await expect(getByRoleWithinCols('columnheader', { name: /^id/ })).toBeVisible();
await expect(getByRoleWithinCols('columnheader', { name: /^isbn/ })).toBeVisible();
await expect(getByRoleWithinCols('columnheader', { name: /^reviews/ })).toBeVisible();
await expect(
getByRoleWithinCols("columnheader", { name: /^book/ })
).toBeVisible();
await expect(
getByRoleWithinCols("columnheader", { name: /^condition/ })
).toBeVisible();
await expect(
getByRoleWithinCols("columnheader", { name: /^title/ })
).toBeVisible();
await expect(
getByRoleWithinCols("columnheader", { name: /^author/ })
).toBeVisible();
await expect(
getByRoleWithinCols("columnheader", { name: /^rating/ })
).toBeVisible();

await expect(queryByText('Loading...')).not.toBeVisible();
await expect(queryByText("Loading...")).not.toBeVisible();

const list = getAllByRole('rowgroup').nth(1);
const list = getAllByRole("rowgroup").nth(1);
const { getAllByRole: getAllByRoleWithinList } = within(list);

const rows = getAllByRoleWithinList('row');
const rows = getAllByRoleWithinList("row");

await expect(rows).toHaveCount(30);

const { getAllByRole: getAllByRoleWithinRow } = within(rows.nth(3));

await expect(getAllByRoleWithinRow('link', { name: 'Show' })).toBeVisible();
await expect(getAllByRoleWithinRow('link', { name: 'Edit' })).toBeVisible();
await expect(getAllByRoleWithinRow("link", { name: "Show" })).toBeVisible();
await expect(getAllByRoleWithinRow("link", { name: "Edit" })).toBeVisible();

await expect(getByLabelText(/^First/)).toBeVisible();
await expect(getByLabelText(/^Previous/)).toBeVisible();
Expand Down
Loading

0 comments on commit 0730ef7

Please sign in to comment.