Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,33 +1,78 @@
import { render } from "@testing-library/react";
import { describe, expect, test } from "vitest";
import { describe, expect, test, vi } from "vitest";

import { CountryPicker } from "../../CountryPicker";

describe("CountryPicker Component", () => {
test("should render correctly with a limited list of countries", () => {
describe("CountryPicker Component Snapshots", () => {
test("renders simple list correctly", () => {
const { container } = render(
<CountryPicker
name="simple-country-picker"
name="simple-picker"
include={["NP", "US", "GB"]}
value="NP"
onChange={() => {}}
onChange={vi.fn()}
/>,
);

expect(container).toMatchSnapshot();
});

test("should render correctly with favorites and localization", () => {
test("renders with favorites and custom labels", () => {
const { container } = render(
<CountryPicker
name="favorites-picker"
locale="fr"
include={["NP", "US", "FR", "DE"]}
favorites={["FR", "DE"]}
labels={{ favorites: "Principaux", allCountries: "Autres" }}
value={["FR"]}
multiple
onChange={() => {}}
labels={{ favorites: "Favoris", allCountries: "Tous les pays" }}
value="FR"
onChange={vi.fn()}
/>,
);

expect(container).toMatchSnapshot();
});

test("renders with grouped countries", () => {
const groups = {
Europe: ["FR", "DE", "GB"],
Asia: ["NP", "CN", "JP"],
};

const { container } = render(
<CountryPicker
name="grouped-picker"
groups={groups}
onChange={vi.fn()}
value=""
/>,
);

expect(container).toMatchSnapshot();
});

test("renders with flag options disabled", () => {
const { container } = render(
<CountryPicker
name="no-flags"
include={["US", "GB"]}
flags={false}
onChange={vi.fn()}
value=""
/>,
);

expect(container).toMatchSnapshot();
});

test("renders with custom flag path function", () => {
const { container } = render(
<CountryPicker
name="custom-flags"
include={["US"]}
flagsPath={(code) => `https://cdn.example.com/flags/${code}.png`}
onChange={vi.fn()}
value=""
/>,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,182 @@ exports[`CountryPicker Component > should render correctly with favorites and lo
</div>
</div>
`;

exports[`CountryPicker Component Snapshots > renders simple list correctly 1`] = `
<div>
<div
class="field"
>
<div
class="select"
>
<div
class="label-container"
tabindex="0"
>
<span
class="selected-options"
>
Nepal
</span>
<span
class="action-items"
>
<i
class="pi pi-times"
tabindex="0"
/>
<i
class="pi pi-chevron-down"
/>
</span>
</div>
</div>
</div>
</div>
`;

exports[`CountryPicker Component Snapshots > renders with custom flag path function 1`] = `
<div>
<div
class="field"
>
<div
class="select"
>
<div
class="label-container"
tabindex="0"
>
<div
class="field debounced-input"
>
<input
class="input-field "
id=""
name=""
tabindex="-1"
type="text"
value=""
/>
</div>
<span
class="action-items"
>
<i
class="pi pi-chevron-down"
/>
</span>
</div>
</div>
</div>
</div>
`;

exports[`CountryPicker Component Snapshots > renders with favorites and custom labels 1`] = `
<div>
<div
class="field"
>
<div
class="select"
>
<div
class="label-container"
tabindex="0"
>
<span
class="selected-options"
>
France
</span>
<span
class="action-items"
>
<i
class="pi pi-times"
tabindex="0"
/>
<i
class="pi pi-chevron-down"
/>
</span>
</div>
</div>
</div>
</div>
`;

exports[`CountryPicker Component Snapshots > renders with flag options disabled 1`] = `
<div>
<div
class="field"
>
<div
class="select"
>
<div
class="label-container"
tabindex="0"
>
<div
class="field debounced-input"
>
<input
class="input-field "
id=""
name=""
tabindex="-1"
type="text"
value=""
/>
</div>
<span
class="action-items"
>
<i
class="pi pi-chevron-down"
/>
</span>
</div>
</div>
</div>
</div>
`;

exports[`CountryPicker Component Snapshots > renders with grouped countries 1`] = `
<div>
<div
class="field"
>
<div
class="select"
>
<div
class="label-container"
tabindex="0"
>
<div
class="field debounced-input"
>
<input
class="input-field "
id=""
name=""
tabindex="-1"
type="text"
value=""
/>
</div>
<span
class="action-items"
>
<i
class="pi pi-chevron-down"
/>
</span>
</div>
</div>
</div>
</div>
`;