From 80a8af8a61c0a9faedca4f53a14845f419205762 Mon Sep 17 00:00:00 2001 From: Sverre Nystad Date: Wed, 27 Nov 2024 11:41:02 +0100 Subject: [PATCH] refactor: remove commented out code --- backend/src/services/agent.py | 7 +- docker-compose.yml | 4 +- webapp/cypress/e2e/pages/dashboard.cy.ts | 303 ++++++++---------- .../mine-saker/dashbord/[caseNumber]/page.tsx | 2 - webapp/xml_storage.py | 2 - 5 files changed, 136 insertions(+), 182 deletions(-) diff --git a/backend/src/services/agent.py b/backend/src/services/agent.py index 30c1030..428098e 100644 --- a/backend/src/services/agent.py +++ b/backend/src/services/agent.py @@ -214,7 +214,8 @@ def fill_out_checklist_responder(state): user_applications = state["user_application_documents"] checklist = state["checklist"] retrieval_state = state["retrieval_state"] - documents = retrieval_state.get("documents", []) # Retrieved laws and regulations + # Retrieved laws and regulations + documents = retrieval_state.get("documents", []) # Combine all application documents into one string application_text = "\n\n".join(user_applications) @@ -233,7 +234,6 @@ def fill_out_checklist_responder(state): logger.info(f"Checklist: {checklist}") for idx, checkpoint in enumerate(checklist): # Extract the checkpoint text from the tuple - # checkpoint_text = checkpoint[idx] checkpoint: Sjekkpunkt logger.info(f"Processing checkpoint {idx + 1}") logger.info(f"Checkpoint: {checkpoint}") @@ -368,7 +368,8 @@ def fill_out_checklist_responder(state): ) logger.info(f"Question for retrieval: {response}") state["retrieval_state"]["question"] = response - state["retrieval_performed"] = True # Mark that retrieval has been performed + # Mark that retrieval has been performed + state["retrieval_performed"] = True # Clear the feedback after using it if "revisor_feedback" in state: diff --git a/docker-compose.yml b/docker-compose.yml index 397d354..aa182d2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,13 +11,13 @@ services: - "3000:3000" image: t3-app environment: - - ARKIVGPT_URL=http://host.docker.internal:80/api # Overrides the URLs set in .env to use host.docker.internal instead of localhost + - ARKIVGPT_URL=http://host.docker.internal:80/api - PLANPRAT_URL=http://host.docker.internal:8000/plan-prat/ - CADAID_URL=${CADAID_URL} - DATABASE_URL=${DATABASE_URL} - NEXTAUTH_URL=${NEXTAUTH_URL} extra_hosts: - - "host.docker.internal:host-gateway" # Needed to override URLs on Linux + - "host.docker.internal:host-gateway" api: platform: "linux/amd64" build: diff --git a/webapp/cypress/e2e/pages/dashboard.cy.ts b/webapp/cypress/e2e/pages/dashboard.cy.ts index 02c94a3..ea06049 100644 --- a/webapp/cypress/e2e/pages/dashboard.cy.ts +++ b/webapp/cypress/e2e/pages/dashboard.cy.ts @@ -40,7 +40,7 @@ describe("Admin dashboard page displays correctly", () => { .should("exist") .invoke("text") .should("match", /\w+\.(pdf|xml|jpg)/); - + cy.get(".points") .invoke("text") .then((pointsText) => { @@ -51,7 +51,7 @@ describe("Admin dashboard page displays correctly", () => { }); }); }); - + it("should correctly sum the total points and update the progress dynamically", () => { let totalPoints = 0; @@ -62,7 +62,7 @@ describe("Admin dashboard page displays correctly", () => { .invoke("text") .then((pointsText) => { const match = /\d+/.exec(pointsText); - const points = match ? Number(match[0]) : 0; + const points = match ? Number(match[0]) : 0; totalPoints += points; }); }) @@ -81,7 +81,7 @@ describe("Admin dashboard page displays correctly", () => { const expectedProgressPercentage = (totalPoints / 10) * 100; // Check that the aria-valuenow correctly matches the progress percentage logic - expect(parseInt($progressBar.attr("aria-valuenow") ?? '')).to.equal( + expect(parseInt($progressBar.attr("aria-valuenow") ?? "")).to.equal( totalPoints, ); expect(expectedProgressPercentage).to.equal( @@ -220,17 +220,6 @@ describe("Admin dashboard page displays correctly", () => { .and("be.visible"); }); - /* it("should render the document list dynamically", () => { - // Fetch all document titles dynamically - cy.get("a").each(($el, index, $list) => { - // Get the filename from the href attribute - const documentName = $el.attr("href").split("/").pop(); - - // Assert that the document name is displayed in the component - cy.contains(documentName).should("exist"); - }); - }); */ - it("should have clickable links for each document dynamically", () => { // Fetch all document links dynamically and ensure they are clickable cy.get("a").each(($el) => { @@ -253,213 +242,181 @@ describe("Admin dashboard page displays correctly", () => { .and("be.visible"); }); - - it('should allow typing feedback', () => { + it("should allow typing feedback", () => { // Target the textarea and type some feedback - cy.get('textarea').type('Dette er en testtilbakemelding'); - + cy.get("textarea").type("Dette er en testtilbakemelding"); + // Verify if the text was entered correctly - cy.get('textarea').should('have.value', 'Dette er en testtilbakemelding'); + cy.get("textarea").should("have.value", "Dette er en testtilbakemelding"); }); - - it('should have buttons that work', () => { + + it("should have buttons that work", () => { // Check if all the buttons are rendered with correct labels - cy.contains('Delvis godkjenn').should('exist'); - cy.contains('Delvis avslå søknad').should('exist'); - cy.contains('Avslå søknad').should('exist'); - + cy.contains("Delvis godkjenn").should("exist"); + cy.contains("Delvis avslå søknad").should("exist"); + cy.contains("Avslå søknad").should("exist"); + // Click on the "Delvis godkjenn" button - cy.contains('Delvis godkjenn').click(); + cy.contains("Delvis godkjenn").click(); // Perform any assertion based on expected behavior - + // Click on the "Delvis avslå søknad" button - cy.contains('Delvis avslå søknad').click(); + cy.contains("Delvis avslå søknad").click(); // Perform any assertion based on expected behavior - + // Click on the "Avslå søknad" button - cy.contains('Avslå søknad').click(); + cy.contains("Avslå søknad").click(); // Perform any assertion based on expected behavior }); - - it('should allow sending feedback', () => { + + it("should allow sending feedback", () => { // Type some feedback - cy.get('textarea').type('Sending feedback test.'); - + cy.get("textarea").type("Sending feedback test."); + // Click the "Send tilbakemelding" button - cy.contains('Send tilbakemelding').click(); - + cy.contains("Send tilbakemelding").click(); + // Check if sending feedback triggers expected behavior // cy.intercept('/api/feedback', { statusCode: 200 }).as('sendFeedback'); }); - + /* Tests for plan situation*/ - const external_component_url = "https://www.arealplaner.no/vennesla4223/arealplaner/53?knr=4223&gnr=5&bnr=547&teigid=214401611"; + const external_component_url = + "https://www.arealplaner.no/vennesla4223/arealplaner/53?knr=4223&gnr=5&bnr=547&teigid=214401611"; const BASE_URL = "/mottak/dine-saker/dashbord/1/"; - - describe('Iframe Tests', () => { + 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'); + cy.intercept("GET", `${external_component_url}*`).as("iframeLoad"); // Visit the target page after setting up the intercept cy.visit(BASE_URL); }); - it('should load the iframe without errors', () => { + it("should load the iframe without errors", () => { const timeout = 10_000; cy.get('[data-cy="plansituasjon"]', { timeout: timeout }) - .should('exist') - .and('have.attr', 'src', external_component_url) - .and('be.visible') - .as('embedding'); + .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.wait("@iframeLoad", { timeout: timeout }) + .its("response.statusCode") + .should("eq", 200); - cy.get('@embedding').should('be.visible'); - }); + cy.get("@embedding").should("be.visible"); }); + }); - - it("The page must ", () => { - it("should load the title", () => { - cy.visit(BASE_URL) - cy.get('[data-cy="title"]') + it("The page must ", () => { + it("should load the title", () => { + cy.visit(BASE_URL); + cy.get('[data-cy="title"]') .should("exist") .and("contain.text", "Plansituasjon:") - .and('be.visible') - } - ) - }) + .and("be.visible"); + }); + }); - /* Tests for case documents component */ - it("Has case documents header", () => { + /* Tests for case documents component */ + it("Has case documents header", () => { cy.get('[data-cy="case-documents-header"]') .should("exist") .and("contain.text", "Sakens dokumenter") - .and("be.visible") - }); + .and("be.visible"); + }); - /* it('should render the document list dynamically', () => { - // Fetch all document titles dynamically - cy.get('a').each(($el, index, $list) => { - // Get the filename from the href attribute - const documentName = $el.attr('href').split('/').pop(); - - // Assert that the document name is displayed in the component - cy.contains(documentName).should('exist'); - }); - }); */ - - it('should have clickable links for each document dynamically', () => { - // Fetch all document links dynamically and ensure they are clickable - cy.get('a').each(($el) => { - // Get the href attribute and make sure it's a valid link - cy.wrap($el) - .should('have.attr', 'href') - .and('match', /(\.pdf|\.jpg|\.xml)$/); // Ensure it ends with .pdf, .jpg or .xml - - // Optionally, click the link (without actually navigating) - cy.wrap($el).click({ force: true }); - }); - }); + it("should have clickable links for each document dynamically", () => { + // Fetch all document links dynamically and ensure they are clickable + cy.get("a").each(($el) => { + // Get the href attribute and make sure it's a valid link + cy.wrap($el) + .should("have.attr", "href") + .and("match", /(\.pdf|\.jpg|\.xml)$/); // Ensure it ends with .pdf, .jpg or .xml + // Optionally, click the link (without actually navigating) + cy.wrap($el).click({ force: true }); + }); + }); - /* Tests for AI results components */ - describe('ArchiveGPT Component Tests', () => { - - it('Has ArchiveGPT header', () => { - cy.get('[data-cy="component-title"]') + /* Tests for AI results components */ + describe("ArchiveGPT Component Tests", () => { + it("Has ArchiveGPT header", () => { + cy.get('[data-cy="component-title"]') .should("exist") .and("contain.text", "Arkiv-GPT") - .and("be.visible") - }) - - it('should display the correct status icon and dynamic feedback text', () => { - // Check if the status is a success or failure - cy.get('[data-cy=status-indicator]').then(($statusIndicator) => { - if ($statusIndicator.hasClass('success')) { - // Success case: Check for a check mark and non-empty feedback text - cy.get('[data-cy=icon]').should('have.class', 'icon-checkmark'); - cy.get('[data-cy=feedback-text]') - .invoke('text') - .then((feedback) => { - expect(feedback.trim()).to.not.be.empty.and.to.be.a("string"); - cy.log(`Success feedback: ${feedback}`); // Log feedback for reference - }); - } else if ($statusIndicator.hasClass('failure')) { - // Failure case: Check for a warning icon and non-empty feedback text - cy.get('[data-cy=icon]').should('have.class', 'icon-warning'); - cy.get('[data-cy=feedback-text]') - .invoke('text') - .then((feedback) => { - expect(feedback.trim()).to.not.be.empty.and.to.be.a("string"); - cy.log(`Failure feedback: ${feedback}`); // Log feedback for reference - }); - } - }); - }); - - it('should navigate to the detailed report page when clicked', () => { - // Simulate clicking the component and ensure it navigates to the detailed page - cy.get('[data-cy=archiveGPT-component]') - .click() - .location('pathname') // TODO: Add route to report page - .should('include', '/report-page'); // Adjust this to the actual report page route + .and("be.visible"); + }); + + it("should display the correct status icon and dynamic feedback text", () => { + // Check if the status is a success or failure + cy.get("[data-cy=status-indicator]").then(($statusIndicator) => { + if ($statusIndicator.hasClass("success")) { + // Success case: Check for a check mark and non-empty feedback text + cy.get("[data-cy=icon]").should("have.class", "icon-checkmark"); + cy.get("[data-cy=feedback-text]") + .invoke("text") + .then((feedback) => { + expect(feedback.trim()).to.not.be.empty.and.to.be.a("string"); + cy.log(`Success feedback: ${feedback}`); // Log feedback for reference + }); + } else if ($statusIndicator.hasClass("failure")) { + // Failure case: Check for a warning icon and non-empty feedback text + cy.get("[data-cy=icon]").should("have.class", "icon-warning"); + cy.get("[data-cy=feedback-text]") + .invoke("text") + .then((feedback) => { + expect(feedback.trim()).to.not.be.empty.and.to.be.a("string"); + cy.log(`Failure feedback: ${feedback}`); // Log feedback for reference + }); + } }); - }); + }); - /* CAD-AiD */ - describe('CAD-AiD Component Tests', () => { - - it('Has CAD-AiD header', () => { - cy.get('[data-cy="component-title"]') - .should("exist") - .and("contain.text", "CAD-AiD") - .and("be.visible") + it("should navigate to the detailed report page when clicked", () => { + // Simulate clicking the component and ensure it navigates to the detailed page + cy.get("[data-cy=archiveGPT-component]") + .click() + .location("pathname") // TODO: Add route to report page + .should("include", "/report-page"); // Adjust this to the actual report page route + }); }); - it('should display the correct status icon and dynamic feedback text', () => { - cy.get('[data-cy=status-indicator]').then(($statusIndicator) => { - if ($statusIndicator.hasClass('success')) { - // Success case: Check for a check mark and non-empty feedback text - cy.get('[data-cy=icon]').should('have.class', 'icon-checkmark'); - cy.get('[data-cy=feedback-text]') - .invoke('text') - .then((feedback) => { - expect(feedback.trim()).to.not.be.empty.and.to.be.a("string"); - cy.log(`Success feedback: ${feedback}`); // Log feedback for reference - }); - } else if ($statusIndicator.hasClass('failure')) { - // Failure case: Check for a warning icon and non-empty feedback text - cy.get('[data-cy=icon]').should('have.class', 'icon-warning'); - cy.get('[data-cy=feedback-text]') - .invoke('text') - .then((feedback) => { - expect(feedback.trim()).to.not.be.empty.and.to.be.a("string"); - cy.log(`Failure feedback: ${feedback}`); // Log feedback for reference - }); - } + /* CAD-AiD */ + describe("CAD-AiD Component Tests", () => { + it("Has CAD-AiD header", () => { + cy.get('[data-cy="component-title"]') + .should("exist") + .and("contain.text", "CAD-AiD") + .and("be.visible"); + }); + + it("should display the correct status icon and dynamic feedback text", () => { + cy.get("[data-cy=status-indicator]").then(($statusIndicator) => { + if ($statusIndicator.hasClass("success")) { + // Success case: Check for a check mark and non-empty feedback text + cy.get("[data-cy=icon]").should("have.class", "icon-checkmark"); + cy.get("[data-cy=feedback-text]") + .invoke("text") + .then((feedback) => { + expect(feedback.trim()).to.not.be.empty.and.to.be.a("string"); + cy.log(`Success feedback: ${feedback}`); // Log feedback for reference + }); + } else if ($statusIndicator.hasClass("failure")) { + // Failure case: Check for a warning icon and non-empty feedback text + cy.get("[data-cy=icon]").should("have.class", "icon-warning"); + cy.get("[data-cy=feedback-text]") + .invoke("text") + .then((feedback) => { + expect(feedback.trim()).to.not.be.empty.and.to.be.a("string"); + cy.log(`Failure feedback: ${feedback}`); // Log feedback for reference + }); + } }); + }); }); - - /* it('should navigate to the detailed report page when clicked', () => { - const url = 'mottak/mine-saker/dashbord/' + VALID_CASE_ID + '/cadaid'; - cy.get('[data-cy=cadaid-component]') - .click() - .location(url) - .should('include', '/report-page'); // Adjust this to the actual report page route - }); */ - - /* it("should navigate to the detailed report page when clicked", () => { - cy.get("[data-test=dok-component]") - .click() - .location("pathname") // TODO: Add path to report page - .should("include", "/report-page"); // Adjust this to the actual report page route - }); */ }); }); -}); \ No newline at end of file diff --git a/webapp/src/app/mottak/mine-saker/dashbord/[caseNumber]/page.tsx b/webapp/src/app/mottak/mine-saker/dashbord/[caseNumber]/page.tsx index 3c0d04f..ecf7675 100644 --- a/webapp/src/app/mottak/mine-saker/dashbord/[caseNumber]/page.tsx +++ b/webapp/src/app/mottak/mine-saker/dashbord/[caseNumber]/page.tsx @@ -89,8 +89,6 @@ export default function CaseDashboard() { const detections = fetchDetections(); const checklist = transformDetectionToChecklist(detections); - /** Convert from string to number for getCase function */ - // const caseNumberAsNumber = Number(caseNumber); const ApplicationData: CaseData | undefined = getCase(100239); diff --git a/webapp/xml_storage.py b/webapp/xml_storage.py index 97bb9cb..18d95e1 100644 --- a/webapp/xml_storage.py +++ b/webapp/xml_storage.py @@ -13,8 +13,6 @@ def read_file_content(file_path): with open(file_path, "r", encoding="utf-8") as file: content = file.read() - # logger.info("Raw file content:") # Debugging line - # logger.info(repr(content)) # Use repr to see whitespace and special characters return content