Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add tests for creators #66

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/mocha.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Mocha

on:
workflow_run:
workflows:
- ESLint
types:
- completed
# workflow_run:
# workflows:
# - ESLint
# types:
# - completed
pull_request:
branches:
- main
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Release

on:
# workflow_run:
# workflows:
# - Mocha
# types:
# - completed
workflow_run:
workflows:
- Mocha
types:
- completed
push:
branches:
- main
Expand Down
20 changes: 20 additions & 0 deletions specs/creators/at-rule.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';

import createAtRule from '../../src/creators/at-rule.js';

describe('Create At Rule', () => {
it('create an object with args (name: String, hasBlock: true)', () => {
const rule = createAtRule('test-rule', true);

expect(rule).to.have.property('name', 'test-rule');
expect(rule).to.have.property('hasBlock', true);
});

it('create an object with args (name: String, hasBlock: false)', () => {
const rule = createAtRule('test-rule', false);

expect(rule).to.have.property('name', 'test-rule');
expect(rule).to.have.property('hasBlock', false);
});
});
14 changes: 14 additions & 0 deletions specs/creators/logical-group.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';

import createLogicalGroup from '../../src/creators/logical-group.js';

describe('Create Logical Group', () => {
it('create an object with args (groupName: String, properties: Array)', () => {
const properties = ['display', 'z-index'];
const logicalGroup = createLogicalGroup('Test Group Name', properties);

expect(logicalGroup).to.have.property('groupName', 'Test Group Name');
expect(logicalGroup).to.have.property('properties', properties);
});
});
42 changes: 42 additions & 0 deletions specs/creators/rule.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';

import createRule from '../../src/creators/rule.js';

describe('Create Rule', () => {
it('create an object with args (selector: String, [::pseudo-element])', () => {
const rule = createRule('::pseudo-element');

expect(rule).to.have.property('selector', '&::pseudo-element');
});

it('create an object with args (selector: String, [:pseudo-class])', () => {
const rule = createRule(':pseudo-class');

expect(rule).to.have.property('selector', '&:pseudo-class');
});

it('create an object with args (selector: RegExp, [\\[[^\\[\\]]+\\]])', () => {
const rule = createRule('\\[[^\\[\\]]+\\]');

expect(rule).to.have.property('selector', '&\\[[^\\[\\]]+\\]');
});

it('create an object with args (selector: RegExp, [\\..+])', () => {
const rule = createRule('\\..+');

expect(rule).to.have.property('selector', '&\\..+');
});

it('create an object with args (selector: RegExp, [--.+])', () => {
const rule = createRule('--.+');

expect(rule).to.have.property('selector', '&--.+');
});

it('create an object with args (selector: RegExp, [?.* &])', () => {
const rule = createRule('?.* &');

expect(rule).to.have.property('selector', '&?.* &');
});
});
1 change: 0 additions & 1 deletion specs/index.spec.js

This file was deleted.

24 changes: 24 additions & 0 deletions specs/regex/bem-pattern.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';

import CSSRules from '../../src/rules/css.js';

describe('BEM Class Pattern', () => {
const BEMClassPattern = new RegExp(CSSRules['selector-class-pattern'][0]);

it('block (String, [block])', () => {
expect('block').to.match(BEMClassPattern);
});

it('block with modifier (String, [block--modifier])', () => {
expect('block--modifier').to.match(BEMClassPattern);
});

it('block and element (String, [block__element])', () => {
expect('block__element').to.match(BEMClassPattern);
});

it('block and element with modifier (String, [block__element--modifier])', () => {
expect('block__element--modifier').to.match(BEMClassPattern);
});
});
22 changes: 22 additions & 0 deletions specs/regex/regex.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';

import REGEXP from '../../src/utils/regexps.js';

describe('Nested Selectors Pattern', () => {
it('nested (String, [&[attribute]])', () => {
expect('&[attribute]').to.match(new RegExp(`&${REGEXP.NESTED.ATTRIBUTE}`));
});

it('nested (String, [&.class])', () => {
expect('&.class').to.match(new RegExp(`&${REGEXP.NESTED.CLASS}`));
});

it('nested (String, [&--modifier])', () => {
expect('&--modifier').to.match(new RegExp(`&${REGEXP.NESTED.MODIFIER}`));
});

it('nested (String, [.class &])', () => {
expect('.class &').to.match(new RegExp(`&${REGEXP.NESTED.PARENT}`));
});
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/properties/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import nonStandard from './non-standard.js';

import REGEXP from '../utils/regexps.js';

import createLogicalGroup from '../utils/create-logical-group.js';
import createAtRule from '../utils/create-at-rule.js';
import createRule from '../utils/create-rule.js';
import createLogicalGroup from '../creators/logical-group.js';
import createAtRule from '../creators/at-rule.js';
import createRule from '../creators/rule.js';

const propertiesOrder = {
'order/order': [
Expand Down