Skip to content

Commit 32fe5fb

Browse files
committed
tests: Improve tab groups tests
Signed-off-by: Marcel Klehr <[email protected]>
1 parent 883b1db commit 32fe5fb

File tree

1 file changed

+235
-3
lines changed

1 file changed

+235
-3
lines changed

src/test/test.js

Lines changed: 235 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Controller from '../lib/Controller'
1212
import FakeAdapter from '../lib/adapters/Fake'
1313
import BrowserTree from '../lib/browser/BrowserTree'
1414
import { AdditionFailsafeError, DeletionFailsafeError } from '../errors/Error'
15+
import SyncProcess from '../lib/strategies/Default'
1516

1617
chai.use(chaiAsPromised)
1718
const expect = chai.expect
@@ -5864,6 +5865,8 @@ describe('Floccus', function() {
58645865
await account.sync()
58655866
expect(account.getData().error).to.not.be.ok
58665867

5868+
await awaitTabsUpdated()
5869+
58675870
// Verify the result
58685871
const tree = await getAllBookmarks(account)
58695872
expectTreeEqual(
@@ -5887,6 +5890,30 @@ describe('Floccus', function() {
58875890
}),
58885891
false
58895892
)
5893+
5894+
const localTree = await account.localTabs.getBookmarksTree(true)
5895+
filterBookmarksInTree(localTree, b => b.url.startsWith('http'))
5896+
expectTreeEqual(
5897+
localTree,
5898+
new Folder({
5899+
title: localTree.title,
5900+
children: [
5901+
new Folder({
5902+
title: 'Window 0',
5903+
children: [
5904+
new Folder({
5905+
title: 'Test Group',
5906+
children: [
5907+
new Bookmark({ title: TEST_URL_TITLE, url: TEST_URL + '#test1' }),
5908+
new Bookmark({ title: TEST_URL_TITLE, url: TEST_URL + '#test2' })
5909+
]
5910+
})
5911+
]
5912+
})
5913+
]
5914+
}),
5915+
false
5916+
)
58905917
})
58915918

58925919
it('should create two tabs, then add them both to a tab group', async function() {
@@ -5908,6 +5935,8 @@ describe('Floccus', function() {
59085935
await account.sync()
59095936
expect(account.getData().error).to.not.be.ok
59105937

5938+
await awaitTabsUpdated()
5939+
59115940
// Verify the initial state
59125941
let tree = await getAllBookmarks(account)
59135942
expectTreeEqual(
@@ -5927,6 +5956,25 @@ describe('Floccus', function() {
59275956
false
59285957
)
59295958

5959+
const localTree = await account.localTabs.getBookmarksTree(true)
5960+
filterBookmarksInTree(localTree, b => b.url.startsWith('http'))
5961+
expectTreeEqual(
5962+
localTree,
5963+
new Folder({
5964+
title: localTree.title,
5965+
children: [
5966+
new Folder({
5967+
title: 'Window 0',
5968+
children: [
5969+
new Bookmark({ title: TEST_URL_TITLE, url: TEST_URL + '#test1' }),
5970+
new Bookmark({ title: TEST_URL_TITLE, url: TEST_URL + '#test2' })
5971+
]
5972+
})
5973+
]
5974+
}),
5975+
false
5976+
)
5977+
59305978
// Now group the tabs
59315979
const groupId = await browser.tabs.group({
59325980
tabIds: [tab1.id, tab2.id]
@@ -5942,6 +5990,8 @@ describe('Floccus', function() {
59425990
await account.sync()
59435991
expect(account.getData().error).to.not.be.ok
59445992

5993+
await awaitTabsUpdated()
5994+
59455995
// Verify the result
59465996
tree = await getAllBookmarks(account)
59475997
expectTreeEqual(
@@ -5965,6 +6015,30 @@ describe('Floccus', function() {
59656015
}),
59666016
false
59676017
)
6018+
6019+
const localTreeAfter = await account.localTabs.getBookmarksTree(true)
6020+
filterBookmarksInTree(localTreeAfter, b => b.url.startsWith('http'))
6021+
expectTreeEqual(
6022+
localTreeAfter,
6023+
new Folder({
6024+
title: localTreeAfter.title,
6025+
children: [
6026+
new Folder({
6027+
title: 'Window 0',
6028+
children: [
6029+
new Folder({
6030+
title: 'Test Group',
6031+
children: [
6032+
new Bookmark({ title: TEST_URL_TITLE, url: TEST_URL + '#test1' }),
6033+
new Bookmark({ title: TEST_URL_TITLE, url: TEST_URL + '#test2' })
6034+
]
6035+
})
6036+
]
6037+
})
6038+
]
6039+
}),
6040+
false
6041+
)
59686042
})
59696043

59706044
it('should move one tab out of a tab group', async function() {
@@ -5997,6 +6071,8 @@ describe('Floccus', function() {
59976071
await account.sync()
59986072
expect(account.getData().error).to.not.be.ok
59996073

6074+
await awaitTabsUpdated()
6075+
60006076
// Verify the initial state
60016077
let tree = await getAllBookmarks(account)
60026078
expectTreeEqual(
@@ -6022,6 +6098,32 @@ describe('Floccus', function() {
60226098
!ACCOUNT_DATA.noCache,
60236099
)
60246100

6101+
const localTree = await account.localTabs.getBookmarksTree(true)
6102+
filterBookmarksInTree(localTree, b => b.url.startsWith('http'))
6103+
expectTreeEqual(
6104+
localTree,
6105+
new Folder({
6106+
title: localTree.title,
6107+
children: [
6108+
new Folder({
6109+
title: 'Window 0',
6110+
children: [
6111+
new Folder({
6112+
title: 'Test Group',
6113+
children: [
6114+
new Bookmark({ title: TEST_URL_TITLE, url: TEST_URL + '#test1' }),
6115+
new Bookmark({ title: TEST_URL_TITLE, url: TEST_URL + '#test2' })
6116+
]
6117+
})
6118+
]
6119+
})
6120+
]
6121+
}),
6122+
false,
6123+
!ACCOUNT_DATA.noCache,
6124+
)
6125+
6126+
60256127
// Move one tab out of the group
60266128
await browser.tabs.ungroup([tab1.id])
60276129
await awaitTabsUpdated()
@@ -6030,6 +6132,8 @@ describe('Floccus', function() {
60306132
await account.sync()
60316133
expect(account.getData().error).to.not.be.ok
60326134

6135+
await awaitTabsUpdated()
6136+
60336137
// Verify the result
60346138
tree = await getAllBookmarks(account)
60356139
expectTreeEqual(
@@ -6054,6 +6158,31 @@ describe('Floccus', function() {
60546158
false,
60556159
!ACCOUNT_DATA.noCache,
60566160
)
6161+
6162+
const localTreeAfter = await account.localTabs.getBookmarksTree(true)
6163+
filterBookmarksInTree(localTreeAfter, b => b.url.startsWith('http'))
6164+
expectTreeEqual(
6165+
localTreeAfter,
6166+
new Folder({
6167+
title: localTreeAfter.title,
6168+
children: [
6169+
new Folder({
6170+
title: 'Window 0',
6171+
children: [
6172+
new Bookmark({ title: TEST_URL_TITLE, url: TEST_URL + '#test1' }),
6173+
new Folder({
6174+
title: 'Test Group',
6175+
children: [
6176+
new Bookmark({ title: TEST_URL_TITLE, url: TEST_URL + '#test2' })
6177+
]
6178+
})
6179+
]
6180+
})
6181+
]
6182+
}),
6183+
false,
6184+
!ACCOUNT_DATA.noCache,
6185+
)
60576186
})
60586187

60596188
it('should reorder tabs and tab groups', async function() {
@@ -6095,6 +6224,8 @@ describe('Floccus', function() {
60956224
await account.sync()
60966225
expect(account.getData().error).to.not.be.ok
60976226

6227+
await awaitTabsUpdated()
6228+
60986229
// Verify the initial state
60996230
let tree = await getAllBookmarks(account)
61006231
expectTreeEqual(
@@ -6126,6 +6257,37 @@ describe('Floccus', function() {
61266257
!ACCOUNT_DATA.noCache,
61276258
)
61286259

6260+
const localTree = await account.localTabs.getBookmarksTree(true)
6261+
filterBookmarksInTree(localTree, b => b.url.startsWith('http'))
6262+
expectTreeEqual(
6263+
localTree,
6264+
new Folder({
6265+
title: localTree.title,
6266+
children: [
6267+
new Folder({
6268+
title: 'Window 0',
6269+
children: [
6270+
new Folder({
6271+
title: 'Group 1',
6272+
children: [
6273+
new Bookmark({ title: TEST_URL_TITLE, url: TEST_URL + '#test1' })
6274+
]
6275+
}),
6276+
new Folder({
6277+
title: 'Group 2',
6278+
children: [
6279+
new Bookmark({ title: TEST_URL_TITLE, url: TEST_URL + '#test2' })
6280+
]
6281+
}),
6282+
new Bookmark({ title: TEST_URL_TITLE, url: TEST_URL + '#test3' })
6283+
]
6284+
})
6285+
]
6286+
}),
6287+
false,
6288+
!ACCOUNT_DATA.noCache,
6289+
)
6290+
61296291
// Reorder the tabs and groups
61306292
// Move tab3 to index 0
61316293
await browser.tabs.move(tab3.id, { index: 0 })
@@ -6137,6 +6299,8 @@ describe('Floccus', function() {
61376299
await account.sync()
61386300
expect(account.getData().error).to.not.be.ok
61396301

6302+
await awaitTabsUpdated()
6303+
61406304
// Verify the result
61416305
tree = await getAllBookmarks(account)
61426306
expectTreeEqual(
@@ -6167,6 +6331,37 @@ describe('Floccus', function() {
61676331
false,
61686332
!ACCOUNT_DATA.noCache,
61696333
)
6334+
6335+
const localTreeAfter = await account.localTabs.getBookmarksTree(true)
6336+
filterBookmarksInTree(localTreeAfter, b => b.url.startsWith('http'))
6337+
expectTreeEqual(
6338+
localTreeAfter,
6339+
new Folder({
6340+
title: localTreeAfter.title,
6341+
children: [
6342+
new Folder({
6343+
title: 'Window 0',
6344+
children: [
6345+
new Bookmark({ title: TEST_URL_TITLE, url: TEST_URL + '#test3' }),
6346+
new Folder({
6347+
title: 'Group 2',
6348+
children: [
6349+
new Bookmark({ title: TEST_URL_TITLE, url: TEST_URL + '#test2' })
6350+
]
6351+
}),
6352+
new Folder({
6353+
title: 'Group 1',
6354+
children: [
6355+
new Bookmark({ title: TEST_URL_TITLE, url: TEST_URL + '#test1' })
6356+
]
6357+
})
6358+
]
6359+
})
6360+
]
6361+
}),
6362+
false,
6363+
!ACCOUNT_DATA.noCache,
6364+
)
61706365
})
61716366

61726367
it('should create a tab group on the server and sync to local tabs', async function() {
@@ -6192,6 +6387,8 @@ describe('Floccus', function() {
61926387
await account.sync()
61936388
expect(account.getData().error).to.not.be.ok
61946389

6390+
await awaitTabsUpdated()
6391+
61956392
// Verify the initial state
61966393
let tree = await getAllBookmarks(account)
61976394
expectTreeEqual(
@@ -6212,6 +6409,26 @@ describe('Floccus', function() {
62126409
!ACCOUNT_DATA.noCache,
62136410
)
62146411

6412+
const localTreeBefore = await account.localTabs.getBookmarksTree(true)
6413+
filterBookmarksInTree(localTreeBefore, b => b.url.startsWith('http'))
6414+
expectTreeEqual(
6415+
localTreeBefore,
6416+
new Folder({
6417+
title: localTreeBefore.title,
6418+
children: [
6419+
new Folder({
6420+
title: 'Window 0',
6421+
children: [
6422+
new Bookmark({ title: TEST_URL_TITLE, url: TEST_URL + '#test1' }),
6423+
new Bookmark({ title: TEST_URL_TITLE, url: TEST_URL + '#test2' })
6424+
]
6425+
})
6426+
]
6427+
}),
6428+
false,
6429+
!ACCOUNT_DATA.noCache,
6430+
)
6431+
62156432
// Create a tab group on the server by modifying the bookmarks tree
62166433
await withSyncConnection(account, async() => {
62176434
// Get the current tree
@@ -6246,7 +6463,7 @@ describe('Floccus', function() {
62466463

62476464
// Verify the local tab state
62486465
const localTree = await account.localTabs.getBookmarksTree(true)
6249-
localTree.children[0].children = localTree.children[0].children.filter(item => !item.url || item.url.startsWith('http'))
6466+
filterBookmarksInTree(localTree, b => b.url.startsWith('http'))
62506467
expectTreeEqual(
62516468
localTree,
62526469
new Folder({
@@ -6331,6 +6548,8 @@ describe('Floccus', function() {
63316548
await account.sync()
63326549
expect(account.getData().error).to.not.be.ok
63336550

6551+
await awaitTabsUpdated()
6552+
63346553
// Verify the initial state
63356554
let tree = await getAllBookmarks(account)
63366555
expectTreeEqual(
@@ -6380,7 +6599,7 @@ describe('Floccus', function() {
63806599

63816600
// Verify the local tab state
63826601
const localTree = await account.localTabs.getBookmarksTree(true)
6383-
localTree.children[0].children = localTree.children[0].children.filter(item => !item.url || item.url.startsWith('http'))
6602+
filterBookmarksInTree(localTree, b => b.url.startsWith('http'))
63846603
expectTreeEqual(
63856604
localTree,
63866605
new Folder({
@@ -6463,6 +6682,8 @@ describe('Floccus', function() {
64636682
await account.sync()
64646683
expect(account.getData().error).to.not.be.ok
64656684

6685+
await awaitTabsUpdated()
6686+
64666687
// Verify the initial state
64676688
let tree = await getAllBookmarks(account)
64686689
expectTreeEqual(
@@ -6517,7 +6738,7 @@ describe('Floccus', function() {
65176738

65186739
// Verify the local tab state
65196740
const localTree = await account.localTabs.getBookmarksTree(true)
6520-
localTree.children[0].children = localTree.children[0].children.filter(item => !item.url || item.url.startsWith('http'))
6741+
filterBookmarksInTree(localTree, b => b.url.startsWith('http'))
65216742
expectTreeEqual(
65226743
localTree,
65236744
new Folder({
@@ -8504,3 +8725,14 @@ function awaitTabsUpdated() {
85048725
new Promise(resolve => setTimeout(resolve, 1300))
85058726
])
85068727
}
8728+
8729+
function filterBookmarksInTree(tree, fn) {
8730+
tree.children = tree.children.filter(item => {
8731+
if (item instanceof Bookmark) return fn(item)
8732+
else {
8733+
filterBookmarksInTree(item, fn)
8734+
return true
8735+
}
8736+
})
8737+
return tree
8738+
}

0 commit comments

Comments
 (0)