npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cypress-drupal-forms

v0.0.2

Published

Class that helps to write tests

Downloads

10

Readme

Cypress-drupal-forms

This package add somo class to make more easy to write test for Drupal forms.

Setup

Install this package via NPM:

npm install --dev cypress-drupal-forms

How to work with it.

Load the class inside a page Object

// cypress/e2e/pages/ArticlePage.js
const Property = require("cypress-drupal-forms").Property;
const Submit = require("cypress-drupal-forms").Submit;
const FileField = require("cypress-drupal-forms").FileField;
const TextField = require("cypress-drupal-forms").TextField;
const TextAreaField = require("cypress-drupal-forms").TextAreaField;


export default class ArticlePage {
  article_path = "/node/add/article";
  submitButton = 'input[data-drupal-selector="edit-submit"]';

  constructor() {
    this.Property = new Property();
    this.FileField = new FileField();
    this.TextAreaField = new TextAreaField();
    this.TextField = new TextField();
    this.Submit = new Submit();
  }

  userCanAccesArticlePage() {
    cy.visit(this.article_path, { failOnStatusCode: true });
  }

  havePermissionsToSeeNodeAddArticle() {
    cy.location("pathname").should("eq", this.article_path);
  }

  clickSubmitButttom() {
    cy.get(this.submitButton).click();
  }
}

Use the files in 'step_definitions' files or in '**/*.spec.js'

// Cypress/support/step_definitions/articlePage.js
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps';

const ArticlePage = require('../../e2e/pages/ArticlePage');
const articlePage = new ArticlePage();

const bodyAttribute = "edit-body-0-value";
const options = Cypress.env('Options');


Given('I am login as {string}', (user) => {
  cy.drupalLogin(user, user)
});

Given('I visit node add article', () => {
  articlePage.userCanAccesArticlePage();
});

And('I have permissions to see node add article form', () => {
  articlePage.havePermissionsToSeeNodeAddArticle();
});

Then('I see node add article form title {string}', (message) => {
  cy.get('h1').should('have.text', message);
});

And('I fill the title with {string}', (title) => {
  options.widget = 'noCkeditor';
  articlePage.TextField.type(
    title,
    articlePage.Property.set('edit-title-0-value'),
    options
  );
});

And('I fill the body with {string}', (body) => {
  options.widget = 'ckeditor';
  articlePage.TextAreaField.type(
    body,
    'edit-body-0-value',
    options
    );
});

And("I Upload a picture to the article", ()=>{
  articlePage.FileField.upload(
    articlePage.Property.set('edit-field-image-0-upload'),
    'picture_001.png',
    "/node/add/article?element_parents=field_image/widget/0&ajax_form=1&_wrapper_format=drupal_ajax",
    articlePage.Property.set('edit-field-image-0-alt'),
    'Esto es una descripción'
  );
});

And("I add the tag {string}", (tag) =>{
  options.widget = 'ckeditor';
  articlePage.TextField.type(
    tag,
    articlePage.Property.set('edit-field-tags-target-id'),
    options
  );
});

And("I click article page submit button", ()=>{
  articlePage.Submit.buttonClick(
    articlePage.Property.set('edit-submit')
  )
});

Fills env files

This module needs three env variables:

{
  "Property": "data-drupal-selector",
  "MediaFieldSelector": ".toolbar-tray-open > .ui-dialog > .ui-dialog-buttonpane > .ui-dialog-buttonset > ",
  "Options": {
    "widget": null,
    "delta": 0
  }
}
  • Property: this is default drupal data selector.
  • MediaFieldSelector: this is the css elementors needed to avoid hava a long string of html elements selector to updolad files throught media browser.
  • Options: This is an object needed to set the widget to user:
    • ckeditor: this widget option is used in TextField and TextAreaField fields and let to fill those fields without ckeditor.
    • noCkeditor: this widget option is used in TextField and TextAreaField fields and let to fill those fields that used a ckeditor.
    • checkBoxes: this widget option is used in TaxonomyReference field when the form element is defined as a check Boxes.
    • radioButton: this widget option is used in TaxonomyReference field when the form element is defined as a radioButton.
    • select: this widget option is used in TaxonomyReference field when the form element is defined as a select list.
    • autocomplete: this widget option is used in TaxonomyReference field when the form element is defined as a autocomplete.