Skip to content

Commit

Permalink
test: add e2e test for Slider and fix cypress:run not showing correct…
Browse files Browse the repository at this point in the history
… coverage - refs #254313
  • Loading branch information
ana-oprea authored Jun 23, 2023
1 parent 8096e3b commit 6aced9b
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ i18n:

.PHONY: cypress-run
cypress-run:
rm -rf .nyc_output
NODE_ENV=development $(NODE_MODULES)/cypress/bin/cypress run

.PHONY: cypress-open
Expand Down
16 changes: 16 additions & 0 deletions cypress/e2e/01-style-block-basics.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ describe('Blocks Tests', () => {
).click();
cy.get('.github-picker.color-picker div[title="#9dc6d4"]').click();

cy.get(
'.inline.field.field-wrapper-shadowDepth .slider-widget-wrapper .slider-knob.single',
).dblclick();
cy.get(
'.inline.field.field-wrapper-shadowDepth .slider-widget-wrapper input',
).type('3{enter}');

cy.get(
'.inline.field.field-wrapper-shadowDepth .slider-widget-wrapper .slider-knob.single',
).trigger('mousedown', { which: 1 });
cy.get(
'.inline.field.field-wrapper-shadowDepth .slider-widget-wrapper .semantic_ui_range_inner',
)
.trigger('mousemove', { clientX: 500 })
.trigger('mouseup');

cy.get('[contenteditable=true]').first().type('{enter}');

// Save page
Expand Down
89 changes: 89 additions & 0 deletions src/helpers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { getFieldURL } from './helpers';

describe('getFieldURL', () => {
it('handles a URL type object with type and value', () => {
const data = {
'@type': 'URL',
value: 'value_url',
url: 'url_url',
href: 'href_url',
};
expect(getFieldURL(data)).toEqual('value_url');
});

it('handles an object with type and url', () => {
const data = {
'@type': 'URL',
url: 'url_url',
href: 'href_url',
};
expect(getFieldURL(data)).toEqual('url_url');
});

it('handles an object with type and href', () => {
const data = {
'@type': 'URL',
href: 'href_url',
};
expect(getFieldURL(data)).toEqual('href_url');
});

it('handles an object with type and no value, url and href', () => {
const data = {
'@type': 'URL',
};
expect(getFieldURL(data)).toEqual({ '@type': 'URL' });
});

it('handles an object without a specific type and url', () => {
const data = {
url: 'url_url',
href: 'href_url',
};
expect(getFieldURL(data)).toEqual('url_url');
});

it('handles an object without a specific type and href', () => {
const data = {
href: 'href_url',
};
expect(getFieldURL(data)).toEqual('href_url');
});

it('handles an object without a specific type and no id, url, href', () => {
const data = {
test: 'test_url',
};
expect(getFieldURL(data)).toEqual({
test: 'test_url',
});
});

it('handles an array', () => {
const data = [
{
'@type': 'URL',
value: 'value_url',
url: 'url_url',
href: 'href_url',
},
{
'@id': 'id_url',
url: 'url_url',
href: 'href_url',
},
];
expect(getFieldURL(data)).toEqual(['value_url', 'id_url']);
});

it('handles a string', () => {
const data = '/some/url';
expect(getFieldURL(data)).toEqual('/some/url');
});

it('returns the data unchanged for non-object/non-array/non-string inputs', () => {
expect(getFieldURL(42)).toEqual(42);
expect(getFieldURL(undefined)).toEqual(undefined);
expect(getFieldURL(null)).toEqual(null);
});
});

0 comments on commit 6aced9b

Please sign in to comment.