Add test
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
4c1d0dbb69
commit
4442fc40e6
4 changed files with 55 additions and 3 deletions
|
@ -11,7 +11,7 @@ def missing_dependencies do
|
|||
if provider do
|
||||
provider.missing_dependencies()
|
||||
else
|
||||
nil
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -28,7 +28,7 @@ def detect(text) do
|
|||
end
|
||||
end
|
||||
|
||||
defp get_provider() do
|
||||
defp get_provider do
|
||||
Pleroma.Config.get([__MODULE__, :provider])
|
||||
end
|
||||
end
|
||||
|
|
31
test/pleroma/language/language_detector_test.ex
Normal file
31
test/pleroma/language/language_detector_test.ex
Normal file
|
@ -0,0 +1,31 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Language.LanguageDetectorTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Language.LanguageDetector
|
||||
|
||||
setup do: clear_config([Pleroma.Language.LanguageDetector, :provider], LanguageDetectorMock)
|
||||
|
||||
test "it detects text language" do
|
||||
detected_language = LanguageDetector.detect("Je viens d'atterrir en Tchéquie.")
|
||||
|
||||
assert detected_language == "fr"
|
||||
end
|
||||
|
||||
test "it returns nil if text is not long enough" do
|
||||
detected_language = LanguageDetector.detect("it returns nil")
|
||||
|
||||
assert detected_language == nil
|
||||
end
|
||||
|
||||
test "it returns nil if no provider specified" do
|
||||
clear_config([Pleroma.Language.LanguageDetector, :provider], nil)
|
||||
|
||||
detected_language = LanguageDetector.detect("this should also return nil")
|
||||
|
||||
assert detected_language == nil
|
||||
end
|
||||
end
|
|
@ -1,8 +1,11 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Language.TranslationTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Language.Translation
|
||||
# use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
setup do: clear_config([Pleroma.Language.Translation, :provider], TranslationMock)
|
||||
|
||||
|
|
18
test/support/language_detector_mock.ex
Normal file
18
test/support/language_detector_mock.ex
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule LanguageDetectorMock do
|
||||
alias Pleroma.Language.LanguageDetector.Provider
|
||||
|
||||
@behaviour Provider
|
||||
|
||||
@impl Provider
|
||||
def missing_dependencies, do: []
|
||||
|
||||
@impl Provider
|
||||
def configured?, do: true
|
||||
|
||||
@impl Provider
|
||||
def detect(text), do: "fr"
|
||||
end
|
Loading…
Reference in a new issue