Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2577675
tst_SendMessageBox.qml
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
tst_SendMessageBox.qml
View Options
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2020-2024 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import
QtQuick
2.15
import
QtQuick
.
Layouts
1.15
import
QtQuick
.
Controls
2.15
import
QtTest
1.0
import
org
.
kde
.
kirigami
2.13
as
Kirigami
import
'../../contents/ui'
as
Kazv
import
'test-helpers.js'
as
Helpers
import
'test-helpers'
as
TestHelpers
Item
{
id: item
width:
800
height:
600
function
makeRoom
()
{
return
{
timeline
()
{
return
{
count:
0
,
eventIds:
[],
gaps:
[],
at
()
{
return
{};
},
};
},
messageById
()
{
return
{};
},
member
()
{
return
{};
},
localDraft:
''
,
setLocalDraft
(
localDraft
)
{
this
.
localDraft
=
localDraft
;
},
updateLocalDraftNow
()
{
},
};
}
property
var
room:
makeRoom
()
property
var
l10n:
Helpers
.
fluentMock
property
var
matrixSdk:
TestHelpers
.
MatrixSdkMock
{}
property
var
kazvIOManager:
TestHelpers
.
KazvIOManagerMock
{}
Kazv
.
SendMessageBox
{
id: sendMessageBox
room:
item
.
room
}
TestCase
{
id: sendMessageBoxTest
name:
'SendMessageBoxTest'
when:
windowShown
function
init
()
{
findChild
(
sendMessageBox
,
'draftMessage'
).
text
=
''
;
}
function
test_empty
()
{
const
textArea
=
findChild
(
sendMessageBox
,
'draftMessage'
);
sendMessageBox
.
mentionUser
(
'@foo:example.com'
);
tryVerify
(()
=>
textArea
.
text
===
'@foo:example.com '
);
verify
(
textArea
.
cursorPosition
===
textArea
.
text
.
length
);
}
function
test_cursorAtEnd
()
{
const
textArea
=
findChild
(
sendMessageBox
,
'draftMessage'
);
textArea
.
text
=
'some test'
;
textArea
.
cursorPosition
=
textArea
.
text
.
length
;
sendMessageBox
.
mentionUser
(
'@foo:example.com'
);
tryVerify
(()
=>
textArea
.
text
===
'some test @foo:example.com '
);
verify
(
textArea
.
cursorPosition
===
textArea
.
text
.
length
);
}
function
test_cursorAtEndSpacingBefore
()
{
const
textArea
=
findChild
(
sendMessageBox
,
'draftMessage'
);
textArea
.
text
=
'some test\n'
;
textArea
.
cursorPosition
=
textArea
.
text
.
length
;
sendMessageBox
.
mentionUser
(
'@foo:example.com'
);
tryVerify
(()
=>
textArea
.
text
===
'some test\n@foo:example.com '
);
verify
(
textArea
.
cursorPosition
===
textArea
.
text
.
length
);
}
function
test_cursorAtBeginning
()
{
const
textArea
=
findChild
(
sendMessageBox
,
'draftMessage'
);
textArea
.
text
=
'some test'
;
textArea
.
cursorPosition
=
0
;
sendMessageBox
.
mentionUser
(
'@foo:example.com'
);
tryVerify
(()
=>
textArea
.
text
===
'@foo:example.com some test'
);
verify
(
textArea
.
cursorPosition
===
'@foo:example.com '
.
length
);
}
function
test_cursorAtBeginningSpacingAfter
()
{
const
textArea
=
findChild
(
sendMessageBox
,
'draftMessage'
);
textArea
.
text
=
'\nsome test'
;
textArea
.
cursorPosition
=
0
;
sendMessageBox
.
mentionUser
(
'@foo:example.com'
);
tryVerify
(()
=>
textArea
.
text
===
'@foo:example.com\nsome test'
);
verify
(
textArea
.
cursorPosition
===
'@foo:example.com'
.
length
);
}
function
test_cursorInMiddleNoSpacing
()
{
const
textArea
=
findChild
(
sendMessageBox
,
'draftMessage'
);
textArea
.
text
=
'some\ntest'
;
textArea
.
cursorPosition
=
1
;
sendMessageBox
.
mentionUser
(
'@foo:example.com'
);
tryVerify
(()
=>
textArea
.
text
===
's @foo:example.com ome\ntest'
);
verify
(
textArea
.
cursorPosition
===
's @foo:example.com '
.
length
);
}
function
test_cursorInMiddleSpacingBefore
()
{
const
textArea
=
findChild
(
sendMessageBox
,
'draftMessage'
);
textArea
.
text
=
'some\ntest'
;
textArea
.
cursorPosition
=
5
;
sendMessageBox
.
mentionUser
(
'@foo:example.com'
);
tryVerify
(()
=>
textArea
.
text
===
'some\n@foo:example.com test'
);
verify
(
textArea
.
cursorPosition
===
'some\n@foo:example.com '
.
length
);
}
function
test_cursorInMiddleSpacingAfter
()
{
const
textArea
=
findChild
(
sendMessageBox
,
'draftMessage'
);
textArea
.
text
=
'some\ntest'
;
textArea
.
cursorPosition
=
4
;
sendMessageBox
.
mentionUser
(
'@foo:example.com'
);
tryVerify
(()
=>
textArea
.
text
===
'some @foo:example.com\ntest'
);
verify
(
textArea
.
cursorPosition
===
'some @foo:example.com'
.
length
);
}
function
test_cursorInMiddleSpacingAround
()
{
const
textArea
=
findChild
(
sendMessageBox
,
'draftMessage'
);
textArea
.
text
=
'some\n\ntest'
;
textArea
.
cursorPosition
=
5
;
sendMessageBox
.
mentionUser
(
'@foo:example.com'
);
tryVerify
(()
=>
textArea
.
text
===
'some\n@foo:example.com\ntest'
);
verify
(
textArea
.
cursorPosition
===
'some\n@foo:example.com'
.
length
);
}
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Jun 24, 12:01 PM (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
93506
Default Alt Text
tst_SendMessageBox.qml (4 KB)
Attached To
Mode
rK kazv
Attached
Detach File
Event Timeline
Log In to Comment