Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

mirego/html_test_identifiers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

28 Commits

Repository files navigation



HTMLTestIdentifiers provides the basic functionality to add data-testid
attribute depending on configuration.

Installation

The package can be installed by adding html_test_identifiers to your list of dependencies in mix.exs:

def deps do
[
{:html_test_identifiers, github: "mirego/html_test_identifiers", tag: "v0.1.1"}
]
end

Configuration

Add the following to your config files if you want data-testid included in your release :

config :html_test_identifiers, provider: HTMLTestIdentifiers.TestID

Add the following to your config files if you don't want data_testid attribute to be included in your release :

config :html_test_identifiers, provider: HTMLTestIdentifiers.NoTestID

If there is no configuration, HTMLTestIdentifiers.NoTestID will be used by default

Usage

# With `config :html_test_identifiers, provider: HTMLTestIdentifiers.TestID`

HTMLTestIdentifiers.testid_attribute("hello")
# => "data-testid=\"hello\"

HTMLTestIdentifiers.testid_key("hello")
# => "hello"

# With `config :html_test_identifiers, provider: HTMLTestIdentifiers.NoTestID`

HTMLTestIdentifiers.testid_attribute("hello")
# => nil

HTMLTestIdentifiers.testid_key("hello")
# => nil

You can also import the module in a view helpers module:

defmodule MyView do
import HTMLTestIdentifiers
end

Considering .eex file content

<h1 <%= testid_attribute("title-id") %>>Title</h1>
<%= content_tag :p, "paragraph text content", data_testid: testid_key("paragraph-id") %>

with config :html_test_identifiers, provider: HTMLTestIdentifiers.TestID, resulting HTML will be

<h1 data-testid="title-id">Titleh1>
<p data-testid="paragraph-id">paragraph text contentp>

with config :html_test_identifiers, provider: HTMLTestIdentifiers.NoTestID, resulting HTML will be

<h1>Titleh1>
<p>paragraph text contentp>

Contributors

  • @romarickb

License

html_test_identifiers is (c) 2019 Mirego and may be freely distributed under the New BSD license. See the LICENSE.md file.

About Mirego

Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We're a team of talented people who imagine and build beautiful Web and mobile applications. We come together to share ideas and change the world.

We also love open-source software and we try to give back to the community as much as we can.

About

HTMLTestIdentifiers provides the basic functionality to add data-testid attribute depending on configuration.

Topics

Resources

Readme

License

BSD-3-Clause license

Stars

Watchers

Forks

Packages

Contributors

Languages