From 4ebb7d1b1e899d5293df0aefed4e3c8aa2d41b3c Mon Sep 17 00:00:00 2001 From: SverreNystad Date: Fri, 4 Oct 2024 12:47:18 +0200 Subject: [PATCH 1/7] test: add cypress test for embedded frame loading --- .../e2e/pages/test_embedded_frame.cy.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 frontend/cypress/e2e/pages/test_embedded_frame.cy.ts diff --git a/frontend/cypress/e2e/pages/test_embedded_frame.cy.ts b/frontend/cypress/e2e/pages/test_embedded_frame.cy.ts new file mode 100644 index 0000000..a7b7c7f --- /dev/null +++ b/frontend/cypress/e2e/pages/test_embedded_frame.cy.ts @@ -0,0 +1,19 @@ +// cypress/e2e/iframe.cy.ts + +const external_component_url = "https://byggesak3d.norkart.no/view/bf204afe-e50e-4ac6-8839-ebd9406167ac"; +const BASE_URL = "http://localhost:3000/"; +const PAGE_URL = BASE_URL + "tiltaksvisning"; + +describe('Iframe Tests', () => { + beforeEach(() => { + cy.visit(PAGE_URL); + }); + + it('should load the iframe without errors', () => { + // Select the iframe using the correct selector + cy.get('[data-cy="tiltaksvisning"]') + .should('exist') + .and('have.attr', 'src', external_component_url) + .and('be.visible') + }); +}); From 40b950a0616ae69adc5885fe6efce2d2a732b52b Mon Sep 17 00:00:00 2001 From: SverreNystad Date: Fri, 4 Oct 2024 12:47:52 +0200 Subject: [PATCH 2/7] feat: add embeddedFrame component --- .../src/app/_components/EmbeddedFrame.tsx | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 frontend/src/app/_components/EmbeddedFrame.tsx diff --git a/frontend/src/app/_components/EmbeddedFrame.tsx b/frontend/src/app/_components/EmbeddedFrame.tsx new file mode 100644 index 0000000..4116958 --- /dev/null +++ b/frontend/src/app/_components/EmbeddedFrame.tsx @@ -0,0 +1,33 @@ +import React from 'react'; + +interface IframeProps { + src: string; + title?: string; + width?: string | number; + height?: string | number; + frameBorder?: number; + allowFullScreen?: boolean; +} + +const EmbeddedFrame: React.FC = ({ + src, + title = 'Embedded Frame', + width = '90%', + height = '600vh', + allowFullScreen = false, + ...props +}) => { + return ( + + ); +}; + +export default EmbeddedFrame; From 7e55bf056280dc749bf0b2fbdd123f500b5c245c Mon Sep 17 00:00:00 2001 From: SverreNystad Date: Fri, 4 Oct 2024 12:48:14 +0200 Subject: [PATCH 3/7] feat: add page for tiltaksvisning --- frontend/src/app/tiltaksvisning/page.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 frontend/src/app/tiltaksvisning/page.tsx diff --git a/frontend/src/app/tiltaksvisning/page.tsx b/frontend/src/app/tiltaksvisning/page.tsx new file mode 100644 index 0000000..c34dc9b --- /dev/null +++ b/frontend/src/app/tiltaksvisning/page.tsx @@ -0,0 +1,11 @@ +import EmbeddedFrame from "../_components/EmbeddedFrame"; + + +export default async function Home() { + return ( +
+ +
+ ); +} + From c225a50b76b48910ecb63a664b4393ad6c020bc8 Mon Sep 17 00:00:00 2001 From: SverreNystad Date: Fri, 4 Oct 2024 12:51:49 +0200 Subject: [PATCH 4/7] test: add Cypress test checking the title of the page --- frontend/cypress/e2e/pages/test_embedded_frame.cy.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/frontend/cypress/e2e/pages/test_embedded_frame.cy.ts b/frontend/cypress/e2e/pages/test_embedded_frame.cy.ts index a7b7c7f..c5da542 100644 --- a/frontend/cypress/e2e/pages/test_embedded_frame.cy.ts +++ b/frontend/cypress/e2e/pages/test_embedded_frame.cy.ts @@ -17,3 +17,14 @@ describe('Iframe Tests', () => { .and('be.visible') }); }); + +describe("The page must ", () => { + it("should load the title", () => { + cy.visit(PAGE_URL) + cy.get('[data-cy="title"]') + .should("exist") + .and("contain.text", "3D tiltaksvisning") + .and('be.visible') + } + ) +}) From 0ed16143fadb6e532ec533b3b1c9b302c32349da Mon Sep 17 00:00:00 2001 From: SverreNystad Date: Fri, 4 Oct 2024 12:52:37 +0200 Subject: [PATCH 5/7] test: improve Cypress test for embedded frame loading with checking that it receives OK response --- .../e2e/pages/test_embedded_frame.cy.ts | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/frontend/cypress/e2e/pages/test_embedded_frame.cy.ts b/frontend/cypress/e2e/pages/test_embedded_frame.cy.ts index c5da542..410e455 100644 --- a/frontend/cypress/e2e/pages/test_embedded_frame.cy.ts +++ b/frontend/cypress/e2e/pages/test_embedded_frame.cy.ts @@ -1,23 +1,35 @@ -// cypress/e2e/iframe.cy.ts - const external_component_url = "https://byggesak3d.norkart.no/view/bf204afe-e50e-4ac6-8839-ebd9406167ac"; const BASE_URL = "http://localhost:3000/"; const PAGE_URL = BASE_URL + "tiltaksvisning"; + describe('Iframe Tests', () => { beforeEach(() => { + // Intercept the GET request for the iframe's src URL and alias it as 'iframeLoad' + cy.intercept('GET', `${external_component_url}*`).as('iframeLoad'); + + // Visit the target page after setting up the intercept cy.visit(PAGE_URL); }); it('should load the iframe without errors', () => { - // Select the iframe using the correct selector - cy.get('[data-cy="tiltaksvisning"]') - .should('exist') + let timeout = 10_000; + cy.get('[data-cy="tiltaksvisning"]', { timeout: timeout }) + .should('exist') .and('have.attr', 'src', external_component_url) .and('be.visible') + .as('embedding'); + + // Wait for the iframe's network request to complete and assert the response status + cy.wait('@iframeLoad', { timeout: timeout }) + .its('response.statusCode') + .should('eq', 200); + + cy.get('@embedding').should('be.visible'); }); }); + describe("The page must ", () => { it("should load the title", () => { cy.visit(PAGE_URL) From e5f6d6a080d6a5dfb9f2c86784d56174a5a8f32d Mon Sep 17 00:00:00 2001 From: SverreNystad Date: Fri, 4 Oct 2024 12:52:46 +0200 Subject: [PATCH 6/7] feat: update page title in tiltaksvisning --- frontend/src/app/tiltaksvisning/page.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/app/tiltaksvisning/page.tsx b/frontend/src/app/tiltaksvisning/page.tsx index c34dc9b..5607259 100644 --- a/frontend/src/app/tiltaksvisning/page.tsx +++ b/frontend/src/app/tiltaksvisning/page.tsx @@ -4,6 +4,7 @@ import EmbeddedFrame from "../_components/EmbeddedFrame"; export default async function Home() { return (
+

3D tiltaksvisning

); From 9e5399fcbef2a23b074fc7cfc736797b4a9598c7 Mon Sep 17 00:00:00 2001 From: SverreNystad Date: Fri, 4 Oct 2024 12:52:59 +0200 Subject: [PATCH 7/7] fix: update pre-commit script to run linting in frontend directory --- scripts/pre-commit.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh index 4c896c7..65de30c 100755 --- a/scripts/pre-commit.sh +++ b/scripts/pre-commit.sh @@ -1,6 +1,7 @@ #!/bin/sh # Run linter on staged JavaScript, TypeScript files -npx next lint --fix +cd frontend +npm run lint --fix if [ $? -ne 0 ]; then echo "Linting failed. Please fix the issues before committing."