# Path: multiseek/logic.py
# DATE = "date"
# 
# AUTOCOMPLETE = "autocomplete"
# 
# RANGE = "range"
# 
# STRING = "string"
# 
# VALUE_LIST = "value-list"
# 
# def get_registry(registry):
#     """
#     :rtype: MultiseekRegistry
#     """
# 
#     if isinstance(registry, str):
#         if registry not in _cached_registry:
#             m = importlib.import_module(registry).registry
#             _cached_registry[registry] = m
#         return _cached_registry[registry]
# 
#     return registry
# 
# Path: test_project/test_app/models.py
# class Language(models.Model):
#     name = models.TextField()
#     description = models.TextField()
# 
#     def __str__(self):
#         return self.name
# 
# class Author(models.Model):
#     last_name = models.TextField()
#     first_name = models.TextField()
# 
#     def __str__(self):
#         return u"%s %s" % (self.first_name, self.last_name)
# 
# class Book(models.Model):
#     title = models.TextField()
#     year = models.IntegerField()
#     language = models.ForeignKey(Language, on_delete=models.CASCADE)
#     authors = models.ManyToManyField(Author)
#     no_editors = models.IntegerField()
#     last_updated = models.DateField(auto_now=True)
#     available = models.BooleanField(default=False)
# 
#     def __str__(self):
#         return u"%s by %s" % (self.title, u", ".join(
#             [str(author) for author in self.authors.all()]))
# 
# Path: test_project/test_app/testutil.py
# class wait_for_page_load(object):
#     def __init__(self, browser):
#         self.browser = browser
# 
#     def __enter__(self):
#         self.old_page = self.browser.find_by_tag("html")[0]._element
# 
#     def __exit__(self, *_):
#         WebDriverWait(self.browser, 10).until(
#             lambda driver: staleness_of(self.old_page)
#         )


import json
import pytest
import datetime
from django.conf import settings
from django.urls import reverse
from model_bakery import baker
from selenium.webdriver.support.expected_conditions import staleness_of, \
    alert_is_present
from selenium.webdriver.support.ui import WebDriverWait
from splinter.exceptions import ElementDoesNotExist
from multiseek.logic import DATE, AUTOCOMPLETE, RANGE, STRING, VALUE_LIST, \
    get_registry
from .models import Language, Author, Book
from builtins import str as text
from django.utils.translation import gettext_lazy as _
from .testutil import wait_for_page_load
    def serialize(self):
        """Zwraca wartość funkcji serialize() dla formularza, w postaci
        listy -- czyli obiekt JSON"""
        return self.browser.evaluate_script(
            "$('#frame-0').multiseekFrame('serialize')")

    def get_field_value(self, field):
        return self.browser.evaluate_script(
            '$("#%s").multiseekField("getValue")' % field)

    def add_frame(self, frame="frame-0", prev_op=None):
        if not prev_op:
            return self.execute_script(
                """$("#%s").multiseekFrame('addFrame');""" % frame)

        return self.execute_script("""
            $("#%s").multiseekFrame('addFrame', '%s');
        """ % (frame, prev_op))

    def add_field(self, frame, label, op, value):
        code = """
        $("#%(frame)s").multiseekFrame("addField", "%(label)s", "%(op)s", %(value)s);
        """ % dict(frame=frame,
                   label=text(label),
                   op=text(op),
                   value=json.dumps(value))

        self.browser.execute_script(code)

    def load_form_by_name(self, name):

# Path: multiseek/logic.py
# DATE = "date"
# 
# AUTOCOMPLETE = "autocomplete"
# 
# RANGE = "range"
# 
# STRING = "string"
# 
# VALUE_LIST = "value-list"
# 
# def get_registry(registry):
#     """
#     :rtype: MultiseekRegistry
#     """
# 
#     if isinstance(registry, str):
#         if registry not in _cached_registry:
#             m = importlib.import_module(registry).registry
#             _cached_registry[registry] = m
#         return _cached_registry[registry]
# 
#     return registry
# 
# Path: test_project/test_app/models.py
# class Language(models.Model):
#     name = models.TextField()
#     description = models.TextField()
# 
#     def __str__(self):
#         return self.name
# 
# class Author(models.Model):
#     last_name = models.TextField()
#     first_name = models.TextField()
# 
#     def __str__(self):
#         return u"%s %s" % (self.first_name, self.last_name)
# 
# class Book(models.Model):
#     title = models.TextField()
#     year = models.IntegerField()
#     language = models.ForeignKey(Language, on_delete=models.CASCADE)
#     authors = models.ManyToManyField(Author)
#     no_editors = models.IntegerField()
#     last_updated = models.DateField(auto_now=True)
#     available = models.BooleanField(default=False)
# 
#     def __str__(self):
#         return u"%s by %s" % (self.title, u", ".join(
#             [str(author) for author in self.authors.all()]))
# 
# Path: test_project/test_app/testutil.py
# class wait_for_page_load(object):
#     def __init__(self, browser):
#         self.browser = browser
# 
#     def __enter__(self):
#         self.old_page = self.browser.find_by_tag("html")[0]._element
# 
#     def __exit__(self, *_):
#         WebDriverWait(self.browser, 10).until(
#             lambda driver: staleness_of(self.old_page)
#         )


# Path: test_project/test_app/conftest.py
import json
import pytest
import datetime
from django.conf import settings
from django.urls import reverse
from model_bakery import baker
from selenium.webdriver.support.expected_conditions import staleness_of, \
    alert_is_present
from selenium.webdriver.support.ui import WebDriverWait
from splinter.exceptions import ElementDoesNotExist
from multiseek.logic import DATE, AUTOCOMPLETE, RANGE, STRING, VALUE_LIST, \
    get_registry
from .models import Language, Author, Book
from builtins import str as text
from django.utils.translation import gettext_lazy as _
from .testutil import wait_for_page_load

    def serialize(self):
        """Zwraca wartość funkcji serialize() dla formularza, w postaci
        listy -- czyli obiekt JSON"""
        return self.browser.evaluate_script(
            "$('#frame-0').multiseekFrame('serialize')")

    def get_field_value(self, field):
        return self.browser.evaluate_script(
            '$("#%s").multiseekField("getValue")' % field)

    def add_frame(self, frame="frame-0", prev_op=None):
        if not prev_op:
            return self.execute_script(
                """$("#%s").multiseekFrame('addFrame');""" % frame)

        return self.execute_script("""
            $("#%s").multiseekFrame('addFrame', '%s');
        """ % (frame, prev_op))

    def add_field(self, frame, label, op, value):
        code = """
        $("#%(frame)s").multiseekFrame("addField", "%(label)s", "%(op)s", %(value)s);
        """ % dict(frame=frame,
                   label=text(label),
                   op=text(op),
                   value=json.dumps(value))

        self.browser.execute_script(code)

    def load_form_by_name(self, name):

        with wait_for_page_load(self.browser):