Skip to content

Commit

Permalink
M.react_onTabReplaced: add stub and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cxw42 committed Dec 18, 2020
1 parent c8413ba commit 2bd8528
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
13 changes: 13 additions & 0 deletions app/win/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,19 @@ me.react_onTabAttached = function react_onTabAttached(ctabid, cwinid, cidx) {

// }}}2

// onTabReplaced() {{{2

/// Replace a tab in the tree based on its new Chrome tab ID
/// This implements the design decisions in spec/app-win-model.js for onTabReplaced().
///
/// @param ctabid The tab's Chrome tab ID
/// @param cwinid The Chrome window ID of the window the tab is attaching to
/// @param cidx The Chrome tab index where the tab is attaching
/// @return True on success; a string error message on failure
me.react_onTabReplaced = function react_onTabReplaced(ctabid, cwinid, cidx) {
return "not yet implemented";
} // }}}2

// }}}1

module.exports = me;
Expand Down
46 changes: 43 additions & 3 deletions t/spec/app-win-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ describe('app/win/model', function() {
M.markTabAsOpen(tab_vn.val,
{ // Fake ctab
id: next_tab_id++,
windowId: win_vn.val.id,
windowId: win_vn.val.win_id,
index: tab_index++,
url: 'about:blank',
title: tab_vn.val.raw_title,
Expand Down Expand Up @@ -755,9 +755,49 @@ describe('app/win/model', function() {
} //foreach testcase
}); // }}}2

}); //index mapping
describe('onTabReplaced',()=>{ // {{{2
// Each testcase:
// [window state, tab that is being replaced]
let testcases = [
['A', 'a'],
['AB', 'b'],
['xAB', 'a'],
['xAB', 'b'],
['ABx', 'a'],
['ABx', 'b'],
['xABy', 'a'],
['xABy', 'b'],
['aBcDe', 'b'],
['aBcDe', 'd'],
];

for(const thetest of testcases) {
let testname = `${thetest[0]}: replace ${thetest[1]}`;
it(testname, ()=>{
// Mock
let winvn = makeFakeWindow(thetest[0]);
let tabvn = findTabInWindow(winvn, thetest[1]);
const oldidx = tabvn.val.index;
const newctabid = 31337;

// Do the work
const ok =
M.react_onTabReplaced(tabvn.val.tab_id, newctabid);
expect(ok).toBe(true);

// Check it
expect(tabvn.val.win_id).toBe(winvn.val.win_id);
expect(tabvn.val.tab_id).toBe(newctabid);
expect(tabvn.val.index).toBe(oldidx);
expectWindowState(winvn, thetest[0]);

expect(M.eraseWin(winvn)).toBeTruthy();
});
} //foreach testcase
}); // }}}2

}); //reacting to Chrome events }}}1

// }}}1
// Teardown //////////////////////////////////////////////////////// {{{1
afterAll(()=>{
this.$div.remove();
Expand Down

0 comments on commit 2bd8528

Please sign in to comment.