-
Notifications
You must be signed in to change notification settings - Fork 19
Add live conversation signposts #497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dtrn2048
wants to merge
7
commits into
main
Choose a base branch
from
feat/signposts-main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f2d4930
Add live conversation signposts
dtrn2048 bde33c5
Fix signposting test doubles
dtrn2048 6d0a97d
Fix signposting mypy narrowing
dtrn2048 64fb6c9
Use persisted chunk id for signposting
dtrn2048 cb40548
Fix signposts localization catalogs
dtrn2048 c6b81fb
Fix signposting review follow-ups
dtrn2048 da35b29
Clean up signposting lint fixes
dtrn2048 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,224 @@ | ||
| import { loginToApp, logout } from "../../support/functions/login"; | ||
| import { openPortalEditor } from "../../support/functions/portal"; | ||
| import { createProject, deleteProject } from "../../support/functions/project"; | ||
| import { openSettingsMenu } from "../../support/functions/settings"; | ||
|
|
||
| describe("Live Signposts", () => { | ||
| const directusUrl = (Cypress.env("directusUrl") || "http://localhost:8055").replace( | ||
| /\/$/, | ||
| "", | ||
| ); | ||
| let projectId; | ||
| let locale = "en-US"; | ||
|
|
||
| const getAuthCredentials = () => { | ||
| const auth = Cypress.env("auth") || {}; | ||
| if (!auth.email || !auth.password) { | ||
| throw new Error( | ||
| "Missing Directus credentials. Set CYPRESS_EMAIL and CYPRESS_PASSWORD.", | ||
| ); | ||
| } | ||
| return auth; | ||
| }; | ||
|
|
||
| const getFocusTermsTextarea = () => | ||
| cy | ||
| .get('[data-testid="portal-editor-signposting-focus-terms-textarea"]') | ||
| .then(($element) => { | ||
| const $textarea = $element.is("textarea") | ||
| ? $element | ||
| : $element.find("textarea").first(); | ||
| return cy.wrap($textarea); | ||
| }); | ||
|
|
||
| const toggleLiveSignposting = (enable = true) => { | ||
| cy.get('[data-testid="portal-editor-signposting-switch"]') | ||
| .scrollIntoView() | ||
| .should("exist") | ||
| .then(($input) => { | ||
| const $label = $input.closest("label"); | ||
| const isChecked = $input.is(":checked"); | ||
|
|
||
| if ((enable && !isChecked) || (!enable && isChecked)) { | ||
| cy.wrap($label).click({ force: true }); | ||
| } | ||
| }); | ||
|
|
||
| cy.get('[data-testid="portal-editor-signposting-switch"]').should( | ||
| enable ? "be.checked" : "not.be.checked", | ||
| ); | ||
| }; | ||
|
|
||
| const loginToDirectus = () => { | ||
| const auth = getAuthCredentials(); | ||
| return cy | ||
| .request("POST", `${directusUrl}/auth/login`, { | ||
| email: auth.email, | ||
| password: auth.password, | ||
| }) | ||
| .its("body.data.access_token"); | ||
| }; | ||
|
|
||
| afterEach(() => { | ||
| if (projectId) { | ||
| cy.visit(`/${locale}/projects/${projectId}/overview`); | ||
| deleteProject(projectId); | ||
| } | ||
|
|
||
| cy.get("body").then(($body) => { | ||
| const hasSettingsButton = | ||
| $body.find('[data-testid="header-settings-gear-button"]:visible').length > 0; | ||
| const hasLogoutButton = | ||
| $body.find('[data-testid="header-logout-menu-item"]:visible').length > 0; | ||
|
|
||
| if (hasSettingsButton) { | ||
| openSettingsMenu(); | ||
| logout(); | ||
| } else if (hasLogoutButton) { | ||
| logout(); | ||
| } | ||
| }); | ||
|
|
||
| projectId = undefined; | ||
| locale = "en-US"; | ||
| }); | ||
|
|
||
| const seedConversationWithSignposts = ({ locale, projectId }) => { | ||
| const suffix = Cypress._.random(1000, 9999); | ||
| const signpostTitle = `Transit affordability ${suffix}`; | ||
| const signpostSummary = | ||
| "Participants keep returning to the rising cost of buses and trains."; | ||
| const signpostQuote = "Public transport is becoming too expensive for families."; | ||
|
|
||
| return loginToDirectus().then((accessToken) => { | ||
| const headers = { | ||
| Authorization: `Bearer ${accessToken}`, | ||
| }; | ||
|
|
||
| return cy | ||
| .request({ | ||
| body: { | ||
| is_finished: false, | ||
| participant_name: `Signpost Participant ${suffix}`, | ||
| project_id: projectId, | ||
| source: "PORTAL_TEXT", | ||
| }, | ||
| headers, | ||
| method: "POST", | ||
| url: `${directusUrl}/items/conversation`, | ||
| }) | ||
| .then((conversationResponse) => { | ||
| const conversationId = conversationResponse.body.data.id; | ||
| const timestamp = new Date().toISOString(); | ||
|
|
||
| return cy | ||
| .request({ | ||
| body: { | ||
| conversation_id: conversationId, | ||
| signpost_processed_at: timestamp, | ||
| signpost_ready_at: timestamp, | ||
| source: "PORTAL_TEXT", | ||
| timestamp, | ||
| transcript: | ||
| "People agree that public transport costs are rising quickly.", | ||
| }, | ||
| headers, | ||
| method: "POST", | ||
| url: `${directusUrl}/items/conversation_chunk`, | ||
| }) | ||
| .then((chunkResponse) => { | ||
| const chunkId = chunkResponse.body.data.id; | ||
|
|
||
| return cy | ||
| .request({ | ||
| body: { | ||
| category: "theme", | ||
| confidence: 0.92, | ||
| conversation_id: conversationId, | ||
| evidence_chunk_id: chunkId, | ||
| evidence_quote: signpostQuote, | ||
| status: "active", | ||
| summary: signpostSummary, | ||
| title: signpostTitle, | ||
| }, | ||
| headers, | ||
| method: "POST", | ||
| url: `${directusUrl}/items/conversation_signpost`, | ||
| }) | ||
| .then((signpostResponse) => ({ | ||
| conversationId, | ||
| locale, | ||
| projectId, | ||
| signpostId: signpostResponse.body.data.id, | ||
| signpostQuote, | ||
| signpostSummary, | ||
| signpostTitle, | ||
| })); | ||
| }); | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
| it("shows seeded signposts in portal settings, conversation overview, and host guide", () => { | ||
| loginToApp(); | ||
| createProject(); | ||
|
|
||
| cy.location("pathname").then((pathname) => { | ||
| const segments = pathname.split("/").filter(Boolean); | ||
| projectId = segments[segments.indexOf("projects") + 1]; | ||
| locale = segments[0] || locale; | ||
| }); | ||
|
|
||
| openPortalEditor(); | ||
| toggleLiveSignposting(true); | ||
| cy.intercept("PATCH", `${directusUrl}/items/project/*`, (req) => { | ||
| const focusTerms = req.body?.signposting_focus_terms; | ||
| if ( | ||
| typeof focusTerms === "string" && | ||
| focusTerms.includes("public transport") | ||
| ) { | ||
| req.alias = "saveSignpostingFocusTerms"; | ||
| } | ||
| }); | ||
| getFocusTermsTextarea() | ||
| .scrollIntoView() | ||
| .clear() | ||
| .type("affordability{enter}public transport"); | ||
| cy.wait("@saveSignpostingFocusTerms"); | ||
|
|
||
| cy.reload(); | ||
| openPortalEditor(); | ||
| cy.get('[data-testid="portal-editor-signposting-switch"]').should("be.checked"); | ||
| getFocusTermsTextarea().should( | ||
| "have.value", | ||
| "affordability\npublic transport", | ||
| ); | ||
|
|
||
| cy.then(() => seedConversationWithSignposts({ locale, projectId })).then( | ||
| ({ conversationId, signpostId, signpostQuote, signpostSummary, signpostTitle }) => { | ||
| cy.visit( | ||
| `/${locale}/projects/${projectId}/conversation/${conversationId}/overview`, | ||
| ); | ||
|
|
||
| cy.get('[data-testid="conversation-signposts-section"]', { | ||
| timeout: 20000, | ||
| }).should("be.visible"); | ||
| cy.get(`[data-testid="conversation-signpost-card-${signpostId}"]`) | ||
| .should("contain.text", signpostTitle) | ||
| .and("contain.text", signpostSummary) | ||
| .and("contain.text", signpostQuote); | ||
|
|
||
| cy.visit(`/${locale}/projects/${projectId}/host-guide`); | ||
|
|
||
| cy.get('[data-testid="host-guide-live-signposts-panel"]', { | ||
| timeout: 30000, | ||
| }).should("be.visible"); | ||
| cy.get(`[data-testid="host-guide-live-signpost-${signpostId}"]`, { | ||
| timeout: 30000, | ||
| }) | ||
| .should("contain.text", signpostTitle) | ||
| .and("contain.text", signpostSummary); | ||
| }, | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or 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
28 changes: 28 additions & 0 deletions
28
echo/directus/sync/snapshot/collections/conversation_signpost.json
This file contains hidden or 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,28 @@ | ||
| { | ||
| "collection": "conversation_signpost", | ||
| "meta": { | ||
| "accountability": "all", | ||
| "archive_app_filter": true, | ||
| "archive_field": null, | ||
| "archive_value": null, | ||
| "collapse": "open", | ||
| "collection": "conversation_signpost", | ||
| "color": null, | ||
| "display_template": "{{title}}", | ||
| "group": null, | ||
| "hidden": false, | ||
| "icon": null, | ||
| "item_duplication_fields": null, | ||
| "note": null, | ||
| "preview_url": null, | ||
| "singleton": false, | ||
| "sort": 14, | ||
| "sort_field": null, | ||
| "translations": null, | ||
| "unarchive_value": null, | ||
| "versioning": false | ||
| }, | ||
| "schema": { | ||
| "name": "conversation_signpost" | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
echo/directus/sync/snapshot/fields/conversation/signposts.json
This file contains hidden or 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,28 @@ | ||
| { | ||
| "collection": "conversation", | ||
| "field": "signposts", | ||
| "type": "alias", | ||
| "meta": { | ||
| "collection": "conversation", | ||
| "conditions": null, | ||
| "display": null, | ||
| "display_options": null, | ||
| "field": "signposts", | ||
| "group": null, | ||
| "hidden": false, | ||
| "interface": "list-o2m", | ||
| "note": null, | ||
| "options": null, | ||
| "readonly": false, | ||
| "required": false, | ||
| "searchable": true, | ||
| "sort": 28, | ||
| "special": [ | ||
| "o2m" | ||
| ], | ||
| "translations": null, | ||
| "validation": null, | ||
| "validation_message": null, | ||
| "width": "full" | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.