Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/webapp/js_tests/spec/coffee/DependencyInputSpec.coffee
blob: 320e162fb66bff38b008080687ccd73990606ecf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
describe "DependencyInput", ->
    it "should render html element", ->
        expected_span = """
            <span class="_parentesis _parentesis_open">(</span><span class="_parentesis _parentesis_close">)</span>
                        """
        expected_input = """
            <input class="span2 droppable dependence_value" type="text" name="groups.1.fields.1.dependence.values" value="" placeholder="nro. ID"
                         """
        group_order = "1"
        field_order = "1"
        dependency_input = new DependencyInput(group_order, field_order)
        widget = dependency_input.render()
        outer_html = $('<div></div>').append(widget)[0].outerHTML
        expect(outer_html).toContain(expected_span)
        expect(outer_html).toContain(expected_input)

    it "render should have group_order, field_order and value", ->
        expected_input = """
            <input class="span2 droppable dependence_value" type="text" name="groups.0.fields.0.dependence.values" value="" placeholder="nro. ID"
                         """
        group_order = "0"
        field_order = "0"
        dependency_input = new DependencyInput(group_order, field_order)
        widget = dependency_input.render()
        outer_html = $('<div></div>').append(widget)[0].outerHTML
        expect(outer_html).toContain(expected_input)

    it "should respond with popover on click", ->
        setFixtures('<div id="container"></div>');
        container = $('#container');

        group_order = "0"
        field_order = "0"
        dependency_input = new DependencyInput(group_order, field_order)
        widget = dependency_input.render()
        container.append(widget)
        input = container.find("input.dependence_value")
        input.click()

        expect(container).toContain(".popover")

    it "should respond a popover with question and option description for every click", ->
        setFixtures('<div id="container"></div>');
        container = $('#container');

        mock_group_order = "0"
        mock_field_order = "0"
        q_name = "groups.#{mock_group_order}.fields.#{mock_field_order}.name"
        q_value = "Pregunta"
        mock_question = """
            <input type="text" name="#{q_name}" value="#{q_value}">
                        """
        container.append(mock_question)

        opt_id = "1378749492016"
        opt_value = "option value"
        q_name_ = q_name.replace(".name", "")
        opt_name = "#{q_name_}.options.#{opt_id}.text"
        mock_option = """
            <input type="text" name="#{opt_name}" value="#{opt_value}">
                      """
        container.append(mock_option)

        group_order = "1"
        field_order = "1"
        dependency_input = new DependencyInput(group_order, field_order)
        dependency_input.value = opt_id
        widget = dependency_input.render()
        container.append(widget)
        input = container.find("input.dependence_value")
        input.click()

        popover_title = $(".popover .popover-title")
        expect(popover_title).toHaveText(q_value)

        popover_content = $(".popover .popover-content")
        expect(popover_content).toHaveText(opt_value)

        $(".popover").remove()
        input.blur()
        new_value = "new value"
        q_selector = """input[name="#{q_name}"]"""
        opt_selector = """input[name="#{opt_name}"]"""
        $(q_selector).val(new_value)
        $(opt_selector).val(new_value)
        input.click()

        popover_title = $(".popover .popover-title")
        expect(popover_title).toHaveText(new_value)

        popover_content = $(".popover .popover-content")
        expect(popover_content).toHaveText(new_value)