File size: 5,458 Bytes
13555f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import React from 'react'
import {fireEvent, render} from '@testing-library/react'
import '@testing-library/jest-dom'

import 'isomorphic-fetch'

import {act} from 'react-dom/test-utils'

import userEvent from '@testing-library/user-event'

import {wrapDNDIntl} from '../../testUtils'

import {TestBlockFactory} from '../../test/testBlockFactory'

import {ColumnResizeProvider} from './tableColumnResizeContext'
import TableGroupHeaderRowElement from './tableGroupHeaderRow'

const board = TestBlockFactory.createBoard()
const view = TestBlockFactory.createBoardView(board)

const view2 = TestBlockFactory.createBoardView(board)
view2.fields.sortOptions = []

const boardTreeNoGroup = {
    option: {
        id: '',
        value: '',
        color: 'propColorBrown',
    },
    cards: [],
}

const boardTreeGroup = {
    option: {
        id: 'value1',
        value: 'value 1',
        color: 'propColorBrown',
    },
    cards: [],
}

const Wrapper: React.FC = ({children}) => {
    return wrapDNDIntl(
        <ColumnResizeProvider
            columnWidths={{}}
            onResizeColumn={jest.fn()}
        >
            {children}
        </ColumnResizeProvider>,
    )
}

test('should match snapshot, no groups', async () => {
    const {container} = render(
        <Wrapper>
            <TableGroupHeaderRowElement
                board={board}
                activeView={view}
                group={boardTreeNoGroup}
                readonly={false}
                hideGroup={jest.fn()}
                addCard={jest.fn()}
                propertyNameChanged={jest.fn()}
                onDrop={jest.fn()}
                groupByProperty={{
                    id: '',
                    name: 'Property 1',
                    type: 'text',
                    options: [{id: 'property1', value: 'Property 1', color: ''}],
                }}
            />
        </Wrapper>,
    )
    expect(container).toMatchSnapshot()
})

test('should match snapshot with Group', async () => {
    const {container} = render(
        <Wrapper>
            <TableGroupHeaderRowElement
                board={board}
                activeView={view}
                group={boardTreeGroup}
                readonly={false}
                hideGroup={jest.fn()}
                addCard={jest.fn()}
                propertyNameChanged={jest.fn()}
                onDrop={jest.fn()}
            />
        </Wrapper>,
    )
    expect(container).toMatchSnapshot()
})

test('should match snapshot on read only', async () => {
    const {container} = render(
        <Wrapper>
            <TableGroupHeaderRowElement
                board={board}
                activeView={view}
                group={boardTreeGroup}
                readonly={true}
                hideGroup={jest.fn()}
                addCard={jest.fn()}
                propertyNameChanged={jest.fn()}
                onDrop={jest.fn()}
            />
        </Wrapper>,
    )
    expect(container).toMatchSnapshot()
})

test('should match snapshot, hide group', async () => {
    const hideGroup = jest.fn()

    const collapsedOptionsView = TestBlockFactory.createBoardView(board)
    collapsedOptionsView.fields.collapsedOptionIds = [boardTreeGroup.option.id]

    const {container} = render(
        <Wrapper>
            <TableGroupHeaderRowElement
                board={board}
                activeView={collapsedOptionsView}
                group={boardTreeGroup}
                readonly={false}
                hideGroup={hideGroup}
                addCard={jest.fn()}
                propertyNameChanged={jest.fn()}
                onDrop={jest.fn()}
            />
        </Wrapper>,
    )

    const triangle = container.querySelector('.octo-table-cell__expand')
    expect(triangle).not.toBeNull()

    act(() => {
        fireEvent.click(triangle as Element)
    })
    expect(hideGroup).toBeCalled()
    expect(container).toMatchSnapshot()
})

test('should match snapshot, add new', async () => {
    const addNew = jest.fn()

    const {container} = render(
        <Wrapper>
            <TableGroupHeaderRowElement
                board={board}
                activeView={view}
                group={boardTreeGroup}
                readonly={false}
                hideGroup={jest.fn()}
                addCard={addNew}
                propertyNameChanged={jest.fn()}
                onDrop={jest.fn()}
            />
        </Wrapper>,
    )

    const triangle = container.querySelector('i.AddIcon')
    expect(triangle).not.toBeNull()

    act(() => {
        fireEvent.click(triangle as Element)
    })
    expect(addNew).toBeCalled()
    expect(container).toMatchSnapshot()
})

test('should match snapshot, edit title', async () => {
    const {container, getByTitle} = render(
        <Wrapper>
            <TableGroupHeaderRowElement
                board={board}
                activeView={view}
                group={boardTreeGroup}
                readonly={false}
                hideGroup={jest.fn()}
                addCard={jest.fn()}
                propertyNameChanged={jest.fn()}
                onDrop={jest.fn()}
            />
        </Wrapper>,
    )

    const input = getByTitle(/value 1/)
    act(() => {
        userEvent.click(input)
        userEvent.keyboard('{enter}')
    })

    expect(container).toMatchSnapshot()
})