From 6cb6525561199787a03e1c2d1871671a2472b72a Mon Sep 17 00:00:00 2001 From: Maxime Urbanski Date: Thu, 27 Jun 2024 10:36:45 +0200 Subject: [PATCH] test show, list & create ok --- package-lock.json | 50 ++++++++--------- package.json | 2 +- .../components/foo/edit/edit.component.html | 6 +- .../components/foo/show/show.component.html | 2 +- templates/angular/app/router/foo.ts | 2 +- tests/create.spec.ts | 33 ++++++----- tests/edit.spec.ts | 22 +++----- tests/show.spec.ts | 52 ++++++++++------- yarn.lock | 56 +++++++++---------- 9 files changed, 116 insertions(+), 109 deletions(-) diff --git a/package-lock.json b/package-lock.json index b84c3aab..0a2ea975 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.10.0", "license": "MIT", "dependencies": { - "@angular/cli": "^18.0.5", + "@angular/cli": "^18.0.6", "@api-platform/api-doc-parser": "^0.16.0", "@babel/runtime": "^7.0.0", "chalk": "^5.0.0", @@ -64,11 +64,11 @@ } }, "node_modules/@angular-devkit/architect": { - "version": "0.1800.5", - "resolved": "https://registry.npmjs.org/@angular-devkit/architect/-/architect-0.1800.5.tgz", - "integrity": "sha512-KliFJTqwAIyRvW10JnJLlpXK86yx683unTgwgvkg9V4gUc/7cNCmWJiOCmYh1+gATpFq+3d3o36EdTzb4QS03g==", + "version": "0.1800.6", + "resolved": "https://registry.npmjs.org/@angular-devkit/architect/-/architect-0.1800.6.tgz", + "integrity": "sha512-VJ08XM9XR8d3ldXEMIeaiamBSvQqX+ucIKw73zubP37yFVAuvXriDOFskcouVUT0RxWXIZVcNxrgp2t3FE4F6w==", "dependencies": { - "@angular-devkit/core": "18.0.5", + "@angular-devkit/core": "18.0.6", "rxjs": "7.8.1" }, "engines": { @@ -78,9 +78,9 @@ } }, "node_modules/@angular-devkit/core": { - "version": "18.0.5", - "resolved": "https://registry.npmjs.org/@angular-devkit/core/-/core-18.0.5.tgz", - "integrity": "sha512-sGtrS0SqkcBvyuv0QkIfyadwPgDhMroz1r51lMh1hwzJaJ0LNuVMLviEeYIybeBnvAdp9YvYC8I1WgB/FUEFBw==", + "version": "18.0.6", + "resolved": "https://registry.npmjs.org/@angular-devkit/core/-/core-18.0.6.tgz", + "integrity": "sha512-07U0S2fpUBjkg4k6uAEQQHSFfearyHGrONlgkxAlk7HWM5jfHp/8D2+ui1OFZgXpSAHF2C5gULbze/2o9ZNgag==", "dependencies": { "ajv": "8.13.0", "ajv-formats": "3.0.1", @@ -143,11 +143,11 @@ } }, "node_modules/@angular-devkit/schematics": { - "version": "18.0.5", - "resolved": "https://registry.npmjs.org/@angular-devkit/schematics/-/schematics-18.0.5.tgz", - "integrity": "sha512-hZwAq3hwuJzCuh7uqO/7T9IMERhYVxz+ganJlEykpyr58o0IjUM1Q4ZSH5UOYlGRPdBCZJbfiafZ0Sg5w5xBww==", + "version": "18.0.6", + "resolved": "https://registry.npmjs.org/@angular-devkit/schematics/-/schematics-18.0.6.tgz", + "integrity": "sha512-lzjPp8qWV4p3reyKZ2QRF7rQYc17WMCR61vKldQJBuJrS30yx87x22ASn4BCAo7kKKRv8gXJmoXjCPDFlcfRsw==", "dependencies": { - "@angular-devkit/core": "18.0.5", + "@angular-devkit/core": "18.0.6", "jsonc-parser": "3.2.1", "magic-string": "0.30.10", "ora": "5.4.1", @@ -160,14 +160,14 @@ } }, "node_modules/@angular/cli": { - "version": "18.0.5", - "resolved": "https://registry.npmjs.org/@angular/cli/-/cli-18.0.5.tgz", - "integrity": "sha512-w3NOdj6T7QhBmFleavc+AEhcAMyPkt7RsyWW2saufD6x55gzynGQZb9UBZwKDUAR6UtqchBX/HEBWCLNnjbiHg==", - "dependencies": { - "@angular-devkit/architect": "0.1800.5", - "@angular-devkit/core": "18.0.5", - "@angular-devkit/schematics": "18.0.5", - "@schematics/angular": "18.0.5", + "version": "18.0.6", + "resolved": "https://registry.npmjs.org/@angular/cli/-/cli-18.0.6.tgz", + "integrity": "sha512-T0ii60zVqBzxtC4jusKkR5YOdubP5+n9SPd8gm9Dat4jUeePc5O5+6qmjpFXZlibxLNSVIm89hLBb7/rMJIkIg==", + "dependencies": { + "@angular-devkit/architect": "0.1800.6", + "@angular-devkit/core": "18.0.6", + "@angular-devkit/schematics": "18.0.6", + "@schematics/angular": "18.0.6", "@yarnpkg/lockfile": "1.1.0", "ansi-colors": "4.1.3", "ini": "4.1.2", @@ -3508,12 +3508,12 @@ } }, "node_modules/@schematics/angular": { - "version": "18.0.5", - "resolved": "https://registry.npmjs.org/@schematics/angular/-/angular-18.0.5.tgz", - "integrity": "sha512-dV50GIEGl6S5wE6xtAhmHWdLhsOlnNUpAx/v3BPR2AOr90zJvIM03TqAQTzAlnPatxK2WLelRgqVMbPfAVvLAg==", + "version": "18.0.6", + "resolved": "https://registry.npmjs.org/@schematics/angular/-/angular-18.0.6.tgz", + "integrity": "sha512-SZ73nNhCengIOy3GCUbLL++GdpaQ5T9bh05OAdQJuUNtwz1ot8QoQjkcbumKIfTicwMiLxy+OR4sZN1VcUVYpQ==", "dependencies": { - "@angular-devkit/core": "18.0.5", - "@angular-devkit/schematics": "18.0.5", + "@angular-devkit/core": "18.0.6", + "@angular-devkit/schematics": "18.0.6", "jsonc-parser": "3.2.1" }, "engines": { diff --git a/package.json b/package.json index b6fb08c5..8bf7d6a2 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "tmp": "^0.2.0" }, "dependencies": { - "@angular/cli": "^18.0.5", + "@angular/cli": "^18.0.6", "@api-platform/api-doc-parser": "^0.16.0", "@babel/runtime": "^7.0.0", "chalk": "^5.0.0", diff --git a/templates/angular/app/components/foo/edit/edit.component.html b/templates/angular/app/components/foo/edit/edit.component.html index ab06d1a4..dff82cf8 100644 --- a/templates/angular/app/components/foo/edit/edit.component.html +++ b/templates/angular/app/components/foo/edit/edit.component.html @@ -8,10 +8,8 @@ @if (error()) { } -

- Edit \{{ item()['name'] }} - \{{ item()["@id"] }} -

+

Edit {{ titleUcFirst }} \{{ item()["@id"] }}

+ -

Edit \{{ item()['name'] }} \{{ item()["@id"] }}

+

Show {{ titleUcFirst }} \{{ item()["@id"] }}

diff --git a/templates/angular/app/router/foo.ts b/templates/angular/app/router/foo.ts index 0700d127..c64b66dd 100644 --- a/templates/angular/app/router/foo.ts +++ b/templates/angular/app/router/foo.ts @@ -4,7 +4,7 @@ export const {{title}}Routes = [ loadComponent: () => import("@components/{{lc}}/list/list.component").then(c => c.ListComponent) }, { - path: '{{lc}}s/add', + path: '{{lc}}s/create', loadComponent: () => import("@components/{{lc}}/create/create.component").then(c => c.CreateComponent) }, { diff --git a/tests/create.spec.ts b/tests/create.spec.ts index bc93c6dd..24558c9b 100644 --- a/tests/create.spec.ts +++ b/tests/create.spec.ts @@ -1,20 +1,27 @@ -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(fixtures) +const test = baseTest.extend(fixtures); -test('resource create', async ({ page, queries: { getByLabelText, getByRole, getByText, queryByRole, queryByText } }) => { - await page.goto('http://localhost:3000/books/create'); +test("resource create", async ({ + page, + queries: { getByLabelText, getByRole, getByText, queryByRole, queryByText }, +}) => { + await page.goto("http://localhost:3000/books/create"); - await expect(queryByText('Loading...')).not.toBeVisible(); + await expect(queryByText("Loading...")).not.toBeVisible(); - await expect(queryByRole('heading', { level: 1 })).toHaveText(/^\s*Create Book/); + await expect(queryByRole("heading", { level: 1 })).toHaveText( + /^\s*Create Book/ + ); - await expect(getByLabelText('isbn')).toBeEditable(); - await expect(getByLabelText('description')).toBeEditable(); - await expect(getByText('reviews')).toBeVisible(); + await expect(getByLabelText("book")).toBeEditable(); + await expect(getByLabelText("condition")).toBeEditable(); + await expect(getByLabelText("title")).toBeEditable(); + await expect(getByLabelText("author")).toBeEditable(); + await expect(getByLabelText("rating")).toBeEditable(); - await expect(getByRole('button', { name: 'Submit' })).toBeVisible(); - await expect(getByRole('link', { name: /Back to list/ })).toBeVisible(); + await expect(getByRole("button", { name: "Submit" })).toBeVisible(); + await expect(getByRole("link", { name: /Back to list/ })).toBeVisible(); }); diff --git a/tests/edit.spec.ts b/tests/edit.spec.ts index c6359cb8..72fe7602 100644 --- a/tests/edit.spec.ts +++ b/tests/edit.spec.ts @@ -28,20 +28,9 @@ test("resource edit", async ({ const { getAllByRole: getAllByRoleWithinRow } = within(rows.nth(3)); - const bookLink = getAllByRoleWithinRow("link").nth(0); + const bookLink = getAllByRoleWithinRow("link", { name: "Edit" }).nth(0); bookLink.click(); - await expect( - queryByRole("heading", { level: 1, name: /^\s*Show Book/ }) - ).toBeVisible(); - await expect(queryByText("Loading...")).not.toBeVisible(); - - 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 })).toHaveText( @@ -50,9 +39,12 @@ test("resource edit", async ({ await expect(queryByText("Loading...")).not.toBeVisible(); - await expect(getByLabelText("isbn")).toBeEditable(); - await expect(getByLabelText("description")).toBeEditable(); - await expect(getByText("reviews")).toBeVisible(); + await expect(getByLabelText("book")).toBeEditable(); + await expect(getByLabelText("condition")).toBeEditable(); + await expect(getByLabelText("title")).toBeEditable(); + await expect(getByLabelText("author")).toBeEditable(); + await expect(getByLabelText("rating")).toBeEditable(); + //await expect(getByText("reviews")).toBeVisible(); await expect(getByRole("button", { name: "Submit" })).toBeVisible(); await expect(getByRole("button", { name: "Delete" })).toBeVisible(); diff --git a/tests/show.spec.ts b/tests/show.spec.ts index b269d707..8866b7a1 100644 --- a/tests/show.spec.ts +++ b/tests/show.spec.ts @@ -1,43 +1,53 @@ -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(fixtures) +const test = baseTest.extend(fixtures); -test('resource show', async ({ page, within, queries: { getAllByRole, getByRole, queryByRole, queryByText } }) => { - await page.goto('http://localhost:3000/books/'); +test("resource show", async ({ + page, + within, + queries: { getAllByRole, 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"); - const listRows = getAllByRole('row'); + const listRows = getAllByRole("row"); const { getAllByRole: getAllByRoleWithinListRow } = within(listRows.nth(3)); - const bookLink = getAllByRoleWithinListRow('link').nth(0); + const bookLink = getAllByRoleWithinListRow("link").nth(0); bookLink.click(); - await expect(queryByRole('heading', { level: 1 })).toHaveText(/^\s*Show Book/); + await expect(queryByRole("heading", { level: 1 })).toHaveText( + /^\s*Show Book/ + ); - await expect(queryByText('Loading...')).not.toBeVisible(); + await expect(queryByText("Loading...")).not.toBeVisible(); - const cols = getAllByRole('rowgroup').nth(0); + const cols = getAllByRole("rowgroup").nth(0); const { getByRole: getByRoleWithinCols } = within(cols); - await expect(getByRoleWithinCols('columnheader', { name: 'Field' })).toBeVisible(); - await expect(getByRoleWithinCols('columnheader', { name: 'Value' })).toBeVisible(); + await expect( + getByRoleWithinCols("columnheader", { name: "Field" }) + ).toBeVisible(); + await expect( + getByRoleWithinCols("columnheader", { name: "Value" }) + ).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"); const { getByRole: getByRoleWithinRow } = within(rows.nth(0)); - await expect(getByRoleWithinRow('rowheader')).toHaveText('isbn'); + await expect(getByRoleWithinRow("rowheader")).toHaveText("book"); - await expect(getByRole('link', { name: /Back to list/ })).toBeVisible(); - await expect(getByRole('link', { name: 'Edit' })).toBeVisible(); - await expect(getByRole('button', { name: 'Delete' })).toBeVisible(); + await expect(getByRole("link", { name: /Back to list/ })).toBeVisible(); + await expect(getByRole("link", { name: "Edit" })).toBeVisible(); + await expect(getByRole("button", { name: "Delete" })).toBeVisible(); }); diff --git a/yarn.lock b/yarn.lock index dfeed0d5..e35fc325 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10,18 +10,18 @@ "@jridgewell/gen-mapping" "^0.3.5" "@jridgewell/trace-mapping" "^0.3.24" -"@angular-devkit/architect@0.1800.5": - version "0.1800.5" - resolved "https://registry.npmjs.org/@angular-devkit/architect/-/architect-0.1800.5.tgz" - integrity sha512-KliFJTqwAIyRvW10JnJLlpXK86yx683unTgwgvkg9V4gUc/7cNCmWJiOCmYh1+gATpFq+3d3o36EdTzb4QS03g== +"@angular-devkit/architect@0.1800.6": + version "0.1800.6" + resolved "https://registry.npmjs.org/@angular-devkit/architect/-/architect-0.1800.6.tgz" + integrity sha512-VJ08XM9XR8d3ldXEMIeaiamBSvQqX+ucIKw73zubP37yFVAuvXriDOFskcouVUT0RxWXIZVcNxrgp2t3FE4F6w== dependencies: - "@angular-devkit/core" "18.0.5" + "@angular-devkit/core" "18.0.6" rxjs "7.8.1" -"@angular-devkit/core@18.0.5": - version "18.0.5" - resolved "https://registry.npmjs.org/@angular-devkit/core/-/core-18.0.5.tgz" - integrity sha512-sGtrS0SqkcBvyuv0QkIfyadwPgDhMroz1r51lMh1hwzJaJ0LNuVMLviEeYIybeBnvAdp9YvYC8I1WgB/FUEFBw== +"@angular-devkit/core@18.0.6": + version "18.0.6" + resolved "https://registry.npmjs.org/@angular-devkit/core/-/core-18.0.6.tgz" + integrity sha512-07U0S2fpUBjkg4k6uAEQQHSFfearyHGrONlgkxAlk7HWM5jfHp/8D2+ui1OFZgXpSAHF2C5gULbze/2o9ZNgag== dependencies: ajv "8.13.0" ajv-formats "3.0.1" @@ -30,26 +30,26 @@ rxjs "7.8.1" source-map "0.7.4" -"@angular-devkit/schematics@18.0.5": - version "18.0.5" - resolved "https://registry.npmjs.org/@angular-devkit/schematics/-/schematics-18.0.5.tgz" - integrity sha512-hZwAq3hwuJzCuh7uqO/7T9IMERhYVxz+ganJlEykpyr58o0IjUM1Q4ZSH5UOYlGRPdBCZJbfiafZ0Sg5w5xBww== +"@angular-devkit/schematics@18.0.6": + version "18.0.6" + resolved "https://registry.npmjs.org/@angular-devkit/schematics/-/schematics-18.0.6.tgz" + integrity sha512-lzjPp8qWV4p3reyKZ2QRF7rQYc17WMCR61vKldQJBuJrS30yx87x22ASn4BCAo7kKKRv8gXJmoXjCPDFlcfRsw== dependencies: - "@angular-devkit/core" "18.0.5" + "@angular-devkit/core" "18.0.6" jsonc-parser "3.2.1" magic-string "0.30.10" ora "5.4.1" rxjs "7.8.1" -"@angular/cli@^18.0.5": - version "18.0.5" - resolved "https://registry.npmjs.org/@angular/cli/-/cli-18.0.5.tgz" - integrity sha512-w3NOdj6T7QhBmFleavc+AEhcAMyPkt7RsyWW2saufD6x55gzynGQZb9UBZwKDUAR6UtqchBX/HEBWCLNnjbiHg== +"@angular/cli@^18.0.6": + version "18.0.6" + resolved "https://registry.npmjs.org/@angular/cli/-/cli-18.0.6.tgz" + integrity sha512-T0ii60zVqBzxtC4jusKkR5YOdubP5+n9SPd8gm9Dat4jUeePc5O5+6qmjpFXZlibxLNSVIm89hLBb7/rMJIkIg== dependencies: - "@angular-devkit/architect" "0.1800.5" - "@angular-devkit/core" "18.0.5" - "@angular-devkit/schematics" "18.0.5" - "@schematics/angular" "18.0.5" + "@angular-devkit/architect" "0.1800.6" + "@angular-devkit/core" "18.0.6" + "@angular-devkit/schematics" "18.0.6" + "@schematics/angular" "18.0.6" "@yarnpkg/lockfile" "1.1.0" ansi-colors "4.1.3" ini "4.1.2" @@ -1625,13 +1625,13 @@ dependencies: playwright "1.44.1" -"@schematics/angular@18.0.5": - version "18.0.5" - resolved "https://registry.npmjs.org/@schematics/angular/-/angular-18.0.5.tgz" - integrity sha512-dV50GIEGl6S5wE6xtAhmHWdLhsOlnNUpAx/v3BPR2AOr90zJvIM03TqAQTzAlnPatxK2WLelRgqVMbPfAVvLAg== +"@schematics/angular@18.0.6": + version "18.0.6" + resolved "https://registry.npmjs.org/@schematics/angular/-/angular-18.0.6.tgz" + integrity sha512-SZ73nNhCengIOy3GCUbLL++GdpaQ5T9bh05OAdQJuUNtwz1ot8QoQjkcbumKIfTicwMiLxy+OR4sZN1VcUVYpQ== dependencies: - "@angular-devkit/core" "18.0.5" - "@angular-devkit/schematics" "18.0.5" + "@angular-devkit/core" "18.0.6" + "@angular-devkit/schematics" "18.0.6" jsonc-parser "3.2.1" "@sideway/address@^4.1.5":