|
| 1 | +/* |
| 2 | +Copyright 2023 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import React from "react"; |
| 18 | +import { render } from "@testing-library/react"; |
| 19 | + |
| 20 | +import CountryDropdown from "../../../../src/components/views/auth/CountryDropdown"; |
| 21 | +import SdkConfig from "../../../../src/SdkConfig"; |
| 22 | + |
| 23 | +describe("CountryDropdown", () => { |
| 24 | + describe("default_country_code", () => { |
| 25 | + afterEach(() => { |
| 26 | + SdkConfig.unset(); |
| 27 | + }); |
| 28 | + |
| 29 | + it.each([ |
| 30 | + ["GB", 44], |
| 31 | + ["IE", 353], |
| 32 | + ["ES", 34], |
| 33 | + ["FR", 33], |
| 34 | + ["PL", 48], |
| 35 | + ["DE", 49], |
| 36 | + ])("should respect configured default country code for %s", (config, defaultCountryCode) => { |
| 37 | + SdkConfig.add({ |
| 38 | + default_country_code: config, |
| 39 | + }); |
| 40 | + |
| 41 | + const fn = jest.fn(); |
| 42 | + render(<CountryDropdown onOptionChange={fn} isSmall={false} showPrefix={false} />); |
| 43 | + expect(fn).toHaveBeenCalledWith(expect.objectContaining({ prefix: defaultCountryCode.toString() })); |
| 44 | + }); |
| 45 | + }); |
| 46 | + |
| 47 | + describe("defaultCountry", () => { |
| 48 | + it.each([ |
| 49 | + ["en-GB", 44], |
| 50 | + ["en-ie", 353], |
| 51 | + ["es-ES", 34], |
| 52 | + ["fr", 33], |
| 53 | + ["pl", 48], |
| 54 | + ["de-DE", 49], |
| 55 | + ])("should pick appropriate default country for %s", (language, defaultCountryCode) => { |
| 56 | + Object.defineProperty(navigator, "language", { |
| 57 | + configurable: true, |
| 58 | + get() { |
| 59 | + return language; |
| 60 | + }, |
| 61 | + }); |
| 62 | + |
| 63 | + const fn = jest.fn(); |
| 64 | + render(<CountryDropdown onOptionChange={fn} isSmall={false} showPrefix={false} />); |
| 65 | + expect(fn).toHaveBeenCalledWith(expect.objectContaining({ prefix: defaultCountryCode.toString() })); |
| 66 | + }); |
| 67 | + }); |
| 68 | +}); |
0 commit comments