forked from brave/browser-laptop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improves bookmark folder render for context menu
Resolves brave#10054 Auditors: Test Plan:
- Loading branch information
Showing
7 changed files
with
232 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
test/unit/app/renderer/components/common/contextMenu/contextMenuItemTest.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
/* global describe, before, after, it */ | ||
|
||
const Immutable = require('immutable') | ||
const mockery = require('mockery') | ||
const assert = require('assert') | ||
require('../../../../../braveUnit') | ||
const {mount} = require('enzyme') | ||
|
||
describe('ContextMenuItem unit test', function () { | ||
let ContextMenuItem | ||
|
||
before(function () { | ||
mockery.enable({ | ||
warnOnReplace: false, | ||
warnOnUnregistered: false, | ||
useCleanCache: true | ||
}) | ||
ContextMenuItem = require('../../../../../../../app/renderer/components/common/contextMenu/contextMenuItem') | ||
Array.prototype.contains = function (item) { return this.includes(item) } // eslint-disable-line | ||
}) | ||
|
||
after(function () { | ||
mockery.disable() | ||
}) | ||
|
||
describe('getYAxis', function () { | ||
let nodeTop, parentTop | ||
|
||
it('target is contextMenuItem and parentNode is contextMenu', function () { | ||
const event = { | ||
target: { | ||
dataset: { | ||
contextMenuItem: true | ||
}, | ||
getBoundingClientRect: () => { | ||
return { | ||
top: nodeTop | ||
} | ||
}, | ||
parentNode: { | ||
dataset: { | ||
contextMenu: true | ||
}, | ||
scrollTop: 1, | ||
getBoundingClientRect: () => { | ||
return { | ||
top: parentTop | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
const wrapper = mount( | ||
<ContextMenuItem contextMenuItem={Immutable.fromJS({ | ||
label: 'New Tab', | ||
accelerator: 'CmdOrCtrl+T', | ||
click: () => {} | ||
})} /> | ||
) | ||
const instance = wrapper.instance() | ||
nodeTop = 1 | ||
parentTop = 0 | ||
assert.equal(instance.getYAxis(event), 1) | ||
}) | ||
|
||
it('target is contextMenuItem and parentNode is second contextMenu', function () { | ||
const event = { | ||
target: { | ||
dataset: { | ||
contextMenuItem: true | ||
}, | ||
getBoundingClientRect: () => { | ||
return { | ||
top: nodeTop | ||
} | ||
}, | ||
parentNode: { | ||
dataset: { | ||
class: true | ||
}, | ||
scrollTop: 1, | ||
getBoundingClientRect: () => { | ||
return { | ||
top: 0 | ||
} | ||
}, | ||
parentNode: { | ||
dataset: { | ||
contextMenu: true | ||
}, | ||
scrollTop: 50, | ||
getBoundingClientRect: () => { | ||
return { | ||
top: parentTop | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
const wrapper = mount( | ||
<ContextMenuItem contextMenuItem={Immutable.fromJS({ | ||
label: 'New Tab', | ||
accelerator: 'CmdOrCtrl+T', | ||
click: () => {} | ||
})} /> | ||
) | ||
const instance = wrapper.instance() | ||
nodeTop = 1 | ||
parentTop = 10 | ||
assert.equal(instance.getYAxis(event), 40) | ||
}) | ||
|
||
it('target is second contextMenuItem and parentNode is second contextMenu', function () { | ||
const event = { | ||
target: { | ||
dataset: { | ||
class: true | ||
}, | ||
getBoundingClientRect: () => { | ||
return { | ||
top: 0 | ||
} | ||
}, | ||
parentNode: { | ||
dataset: { | ||
contextMenuItem: true | ||
}, | ||
scrollTop: 1, | ||
getBoundingClientRect: () => { | ||
return { | ||
top: nodeTop | ||
} | ||
}, | ||
parentNode: { | ||
dataset: { | ||
contextMenu: true | ||
}, | ||
scrollTop: 50, | ||
getBoundingClientRect: () => { | ||
return { | ||
top: parentTop | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
const wrapper = mount( | ||
<ContextMenuItem contextMenuItem={Immutable.fromJS({ | ||
label: 'New Tab', | ||
accelerator: 'CmdOrCtrl+T', | ||
click: () => {} | ||
})} /> | ||
) | ||
const instance = wrapper.instance() | ||
nodeTop = 20 | ||
parentTop = 10 | ||
assert.equal(instance.getYAxis(event), 59) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters