load("@rules_ruby//ruby:defs.bzl", "rb_library")
load("//rb/spec:tests.bzl", "DEFAULT_BROWSERS", "rb_integration_test")

rb_library(
    name = "spec_helper",
    testonly = True,
    srcs = [
        "spec_helper.rb",
        "spec_support.rb",
    ] + glob(["spec_support/**/*"]),
    data = [
        "//rb:manager-linux",
        "//rb:manager-macos",
        "//rb:manager-windows",
    ],
    visibility = ["//rb/spec:__subpackages__"],
    deps = [
        "//rb/lib:selenium-webdriver",
        "//rb/lib/selenium:devtools",
        "//rb/lib/selenium:server",
        "//rb/lib/selenium:webdriver",
        "//rb/lib/selenium/webdriver:atoms",
        "//rb/lib/selenium/webdriver:common",
        "//rb/lib/selenium/webdriver:remote",
        "//rb/spec:rspec_matchers",
        "@bundle",
    ],
)

_OS_SENSITIVE = [
    "action_builder_spec.rb",
    "takes_screenshot_spec.rb",
    "window_spec.rb",
]

# specs whose classes have both bidi implementations
_BIDI_IMPLEMENTATIONS = [
    "navigation_spec.rb",
]

# tests that require bidi enabled
_BIDI_ONLY = [
    "bidi_spec.rb",
    "network_spec.rb",
]

_DEVTOOLS = ["devtools_spec.rb"]

_NO_GRID = ["driver_finder_spec.rb"]

[
    rb_integration_test(
        name = file[:-8],
        srcs = [file],
        deps = [
            "//rb/lib/selenium/webdriver:common",
        ],
    )
    for file in glob(
        ["*_spec.rb"],
        exclude = _OS_SENSITIVE + _BIDI_IMPLEMENTATIONS + _BIDI_ONLY + _DEVTOOLS + _NO_GRID,
    )
]

[
    rb_integration_test(
        name = f[:-8],
        srcs = [f],
        browsers = DEFAULT_BROWSERS,
        no_grid = True,
        tags = ["se-manager"],
        deps = [
            "//rb/lib/selenium/webdriver:common",
        ],
    )
    for f in _NO_GRID
]

[
    rb_integration_test(
        name = f[:-8],
        srcs = [f],
        tags = ["os-sensitive"],
        deps = [
            "//rb/lib/selenium/webdriver:common",
        ],
    )
    for f in _OS_SENSITIVE
]

[
    rb_integration_test(
        name = f[:-8],
        srcs = [f],
        tags = ["bidi"],
        deps = [
            "//rb/lib/selenium/webdriver:bidi",
        ],
    )
    for f in _BIDI_IMPLEMENTATIONS
]

[
    rb_integration_test(
        name = f[:-8],
        srcs = [f],
        bidi_only = True,
        deps = [
            "//rb/lib/selenium/webdriver:bidi",
        ],
    )
    for f in _BIDI_ONLY
]

[
    rb_integration_test(
        name = f[:-8],
        srcs = [f],
        tags = ["exclusive-if-local"],
        deps = [
            "//rb/lib/selenium/devtools",
            "//rb/lib/selenium/webdriver:devtools",
        ],
    )
    for f in _DEVTOOLS
]
