-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4091 from duhdugg/main
allow nonce values for style elements
- Loading branch information
Showing
4 changed files
with
100 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { createChartWithOptions } from './utils/utils.js' | ||
|
||
describe('chart.nonce option', () => { | ||
beforeEach(() => { | ||
window.Apex = {}; | ||
}); | ||
afterEach(() => { | ||
document.getElementsByTagName('html')[0].innerHTML = '' | ||
}) | ||
|
||
it('undefined (default) will not render a nonce attribute', () => { | ||
createChartWithOptions({ | ||
series: [ | ||
{ | ||
name: "A", | ||
data: [ | ||
[1, 1], | ||
[4, 4], | ||
[3, 3], | ||
], | ||
}, | ||
{ | ||
name: "B", | ||
data: [ | ||
[2, 2], | ||
[5, 5], | ||
[6, 6], | ||
], | ||
}, | ||
], | ||
chart: { | ||
type: 'bar', | ||
}, | ||
}) | ||
expect(document.head.querySelectorAll('#apexcharts-css').length).toBe(1) | ||
expect( | ||
document.head.querySelectorAll('#apexcharts-css[nonce]').length | ||
).toBe(0) | ||
expect(document.body.querySelectorAll('foreignObject style').length).toBe(1) | ||
}) | ||
|
||
it('will render a nonce attribute when provided as an option', () => { | ||
createChartWithOptions({ | ||
series: [ | ||
{ | ||
data: [ | ||
[1, 1], | ||
[4, 4], | ||
[3, 3], | ||
], | ||
}, | ||
], | ||
chart: { | ||
type: 'bar', | ||
nonce: 'noncevalue1', | ||
}, | ||
}) | ||
expect(document.head.querySelectorAll('#apexcharts-css').length).toBe(1) | ||
expect( | ||
document.head.querySelectorAll("#apexcharts-css[nonce='noncevalue1']") | ||
.length | ||
).toBe(1) | ||
}) | ||
|
||
it('will render a nonce attribute when defined as a global config', () => { | ||
window.Apex = { | ||
chart: { | ||
nonce: 'noncevalue2' | ||
} | ||
}; | ||
createChartWithOptions({ | ||
series: [ | ||
{ | ||
data: [ | ||
[1, 1], | ||
[4, 4], | ||
[3, 3], | ||
], | ||
}, | ||
], | ||
chart: { | ||
type: 'bar', | ||
}, | ||
}) | ||
expect(document.head.querySelectorAll('#apexcharts-css').length).toBe(1) | ||
expect( | ||
document.head.querySelectorAll("#apexcharts-css[nonce='noncevalue2']") | ||
.length | ||
).toBe(1) | ||
}) | ||
}) |