Repository navigation
feat(i18n): selector de idioma del cliente al compartir una cotizacion (tarea 12) #75
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
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { fireEvent, screen, waitFor } from "@testing-library/react"; | ||
| import { fireEvent, screen, waitFor, within } from "@testing-library/react"; | ||
| import i18next, { type i18n as I18n } from "i18next"; | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
|
|
@@ -341,6 +341,25 @@ describe("QuoteDetail in English", () => { | |
| expect(screen.getByPlaceholderText("[email protected]")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("proposes English for the customer and lets the seller switch to Spanish", async () => { | ||
| renderDetail(await english()); | ||
| fireEvent.click(await screen.findByRole("button", { name: /Share/ })); | ||
|
|
||
| const select = await screen.findByLabelText("Customer language"); | ||
| expect(select).toHaveValue("en"); | ||
| expect(within(select).getByRole("option", { name: "English" })).toBeInTheDocument(); | ||
| expect(within(select).getByRole("option", { name: "Español" })).toBeInTheDocument(); | ||
| expect(screen.getByText("The email to the customer is sent in this language.")).toBeInTheDocument(); | ||
|
|
||
| // «Copy link» no cierra el diálogo, así que se puede probar con los dos idiomas seguidos. | ||
| fireEvent.click(screen.getByRole("button", { name: /Copy link/ })); | ||
| await waitFor(() => expect(portal.createSession).toHaveBeenLastCalledWith(expect.objectContaining({ locale: "en" }))); | ||
|
|
||
| fireEvent.change(select, { target: { value: "es" } }); | ||
| fireEvent.click(screen.getByRole("button", { name: /Copy link/ })); | ||
| await waitFor(() => expect(portal.createSession).toHaveBeenLastCalledWith(expect.objectContaining({ locale: "es" }))); | ||
| }); | ||
|
|
||
| it("copies the link and sends the email, saying to whom", async () => { | ||
| renderDetail(await english()); | ||
| fireEvent.click(await screen.findByRole("button", { name: /Share/ })); | ||
|
|
||
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,9 @@ | ||
| /** El idioma escrito en si mismo ("Espanol", "English"), sin pasar por un catalogo. */ | ||
| export function languageName(code: string): string { | ||
| try { | ||
| const name = new Intl.DisplayNames([code], { type: "language" }).of(code) ?? code; | ||
| return name.charAt(0).toLocaleUpperCase(code) + name.slice(1); | ||
| } catch { | ||
| return code; | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -93,6 +93,8 @@ | |
| "clientEmail": "Customer email", | ||
| "emailPlaceholder": "[email protected]", | ||
| "validFor": "Valid for", | ||
| "clientLanguage": "Customer language", | ||
| "clientLanguageHint": "The email to the customer is sent in this language.", | ||
| "copyLink": "Copy link", | ||
| "sendEmail": "Send email" | ||
| }, | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -93,6 +93,8 @@ | |
| "clientEmail": "Email del cliente", | ||
| "emailPlaceholder": "[email protected]", | ||
| "validFor": "Válida por", | ||
| "clientLanguage": "Idioma del cliente", | ||
| "clientLanguageHint": "El correo al cliente sale en este idioma.", | ||
| "copyLink": "Copiar link", | ||
| "sendEmail": "Enviar email" | ||
| }, | ||
|
|
||
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { fireEvent, screen, waitFor } from "@testing-library/react"; | ||
| import { fireEvent, screen, waitFor, within } from "@testing-library/react"; | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import i18n from "@/i18n"; | ||
|
|
@@ -162,6 +162,42 @@ describe("QuoteDetail, in Spanish", () => { | |
| expect(screen.getByPlaceholderText("[email protected]")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("proposes the interface language for the customer and sends it with the session", async () => { | ||
| render(); | ||
| fireEvent.click(await screen.findByRole("button", { name: /Compartir/ })); | ||
|
|
||
| const select = await screen.findByLabelText("Idioma del cliente"); | ||
| expect(select).toHaveValue("es"); | ||
| expect(within(select).getByRole("option", { name: "Español" })).toBeInTheDocument(); | ||
| expect(within(select).getByRole("option", { name: "English" })).toBeInTheDocument(); | ||
| expect(screen.getByText("El correo al cliente sale en este idioma.")).toBeInTheDocument(); | ||
|
|
||
| fireEvent.click(screen.getByRole("button", { name: /Copiar link/ })); | ||
| await waitFor(() => expect(portal.createSession).toHaveBeenCalledWith(expect.objectContaining({ locale: "es" }))); | ||
| }); | ||
|
|
||
| it("lets the seller write to the customer in another language", async () => { | ||
| render(); | ||
| fireEvent.click(await screen.findByRole("button", { name: /Compartir/ })); | ||
| fireEvent.change(await screen.findByLabelText("Idioma del cliente"), { target: { value: "en" } }); | ||
| fireEvent.change(screen.getByPlaceholderText("[email protected]"), { target: { value: "[email protected]" } }); | ||
| fireEvent.click(screen.getByRole("button", { name: /Enviar email/ })); | ||
|
|
||
| await waitFor(() => expect(portal.createSession).toHaveBeenCalledWith(expect.objectContaining({ locale: "en", client_email: "[email protected]" }))); | ||
| await waitFor(() => expect(portal.sendEmail).toHaveBeenCalledWith("s1")); | ||
| }); | ||
|
|
||
| it("goes back to the interface language when the dialog is closed and reopened", async () => { | ||
| render(); | ||
| fireEvent.click(await screen.findByRole("button", { name: /Compartir/ })); | ||
| fireEvent.change(await screen.findByLabelText("Idioma del cliente"), { target: { value: "en" } }); | ||
| fireEvent.keyDown(screen.getByRole("dialog"), { key: "Escape" }); | ||
| await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument()); | ||
|
|
||
| fireEvent.click(screen.getByRole("button", { name: /Compartir/ })); | ||
| expect(await screen.findByLabelText("Idioma del cliente")).toHaveValue("es"); | ||
| }); | ||
|
|
||
| it("copies the link and confirms", async () => { | ||
| render(); | ||
| fireEvent.click(await screen.findByRole("button", { name: /Compartir/ })); | ||
|
|
||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resetting
shareLocaleonly inonOpenChangemisses the successful-send path:sendPortalEmailMutation.onSuccesscloses this controlled dialog directly withsetShareOpen(false), which does not invokeonOpenChange. After sending to one customer in a non-default language, reopening the dialog retains that language and can send the next customer's email in it instead of proposing the interface language as intended. Route successful closure through the reset logic or resetshareLocalein the success handler.Useful? React with 👍 / 👎.