-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for cross module features
- Loading branch information
Showing
7 changed files
with
181 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/// <reference types="cypress" /> | ||
/// <reference path="../support/index.d.ts" /> | ||
import testHtml from '../support/testHtmlContents.ts' | ||
import { ViewMode } from "../support/interfaces" | ||
import { getUrl } from '../support/utils.ts' | ||
|
||
describe('Changes can be saved and content will be sanitized on save', () => { | ||
const widgetId = 'Cypr3s5Test' | ||
beforeEach(() => { | ||
cy.setupWidgetItem('Initial text ', { viewMode: ViewMode.EDITING, widgetId }) | ||
cy.contains('Initial text').should('exist') | ||
cy.contains('Start writing').should('not.exist') | ||
}) | ||
|
||
it('Retains content changes on save', () => { | ||
cy.get('div.jodit-wysiwyg').type(' new content!') | ||
cy.contains('Save').click() | ||
cy.visit(getUrl(ViewMode.EDITABLE, widgetId)) | ||
cy.get('#content').should('exist') | ||
cy.get('#content').contains('new content!') | ||
}) | ||
|
||
it('Sanitizes insecure tags on save', () => { | ||
cy.get('span[aria-label="Change mode"]').click() | ||
cy.get('div.ace_content').type(testHtml.dirtyContentTags, {parseSpecialCharSequences: false}) | ||
cy.get('span[aria-label="Change mode"]').click() | ||
cy.contains('Save').click() | ||
cy.visit(getUrl(ViewMode.EDITABLE, widgetId)) | ||
cy.get('#content link').should('not.exist') | ||
}) | ||
|
||
it('Sanitizes disallowed iframes on save', () => { | ||
cy.get('span[aria-label="Change mode"]').click() | ||
cy.get('div.ace_content').type( | ||
testHtml.dirtyContentIframes, {parseSpecialCharSequences: false} | ||
) | ||
cy.get('span[aria-label="Change mode"]').click() | ||
cy.contains('Save').click() | ||
cy.visit(getUrl(ViewMode.EDITABLE, widgetId)) | ||
cy.get('#content iframe').each(($iframe) => { | ||
cy.wrap($iframe).invoke('attr', 'src').should('match', /^(https:\/\/)?www.youtube.com/) | ||
}) | ||
cy.get('#snackbar').should('exist') | ||
cy.get('#snackbar').contains('is not currently an allowed domain for iframe content') | ||
}) | ||
|
||
it('Shows no error for valid nested menu', () => { | ||
cy.get('span[aria-label="Change mode"]').click() | ||
cy.addNestedMenu(testHtml.nestedMenu) | ||
cy.get('span[aria-label="Change mode"]').click() | ||
cy.contains('Save').click() | ||
cy.visit(getUrl(ViewMode.EDITABLE, widgetId)) | ||
cy.get('#snackbar').should('not.be.visible') | ||
cy.get('#content').contains('Hello') | ||
cy.contains('World').click() | ||
cy.contains('World').should('have.class', 'selected') | ||
cy.contains('What a Wonderful').click() | ||
cy.contains('I see trees').click() | ||
cy.contains('Of green').should('have.attr', 'onclick') | ||
}) | ||
|
||
it('Shows error when invalid nested menu syntax is provided', () => { | ||
const invalidNestedMenu = testHtml.nestedMenu.replace('</pre>', 'ExtraText</pre>') | ||
cy.get('span[aria-label="Change mode"]').click() | ||
cy.addNestedMenu(invalidNestedMenu) | ||
cy.get('span[aria-label="Change mode"]').click() | ||
cy.contains('Save').click() | ||
cy.visit(getUrl(ViewMode.EDITABLE, widgetId)) | ||
cy.get('#content').contains('There was an error with the nested menu syntax:') | ||
cy.get('#content').contains('ExtraText') | ||
}) | ||
|
||
afterEach(() => { | ||
cy.removeWidgetItem() | ||
cy.wait(1000) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,4 +1,15 @@ | ||
import { ViewMode } from "./interfaces" | ||
|
||
export function styleMatch(styleStr: string): RegExp { | ||
const escaped = styleStr.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') | ||
return RegExp(`(^${escaped}| ${escaped})`) | ||
} | ||
|
||
export function getUrl(viewMode: ViewMode, widgetId: string): string { | ||
const urlByViewMode = { | ||
[ViewMode.DISPLAY]: `?dashboardItemId=${widgetId}`, | ||
[ViewMode.EDITABLE]: `?dashboardItemId=${widgetId}#/xxx/edit`, | ||
[ViewMode.EDITING]: `edit.html?dashboardItemId=${widgetId}` | ||
} | ||
return urlByViewMode[viewMode] | ||
} |
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