Skip to content
Open
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
42 changes: 21 additions & 21 deletions cypress/e2e/view_filters_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,31 @@ describe('View Filter', () => {
assertInEntries('This is a TOML front matter post');
});

it('can apply multiple filters', () => {
// enable filter
filter('Posts Without Index');

assertEntriesCount(3);

assertInEntries('This is a YAML front matter post');
assertInEntries('This is a JSON front matter post');
assertInEntries('This is a TOML front matter post');

filter('Posts With Index');

assertEntriesCount(0);

cy.contains('div', 'No Entries');
});

it('can apply boolean filter', () => {
// enable filter
filter('Drafts');
filter('Relation Test');

assertEntriesCount(10);
for (let i = 1; i <= 20; i++) {
const draft = i % 2 === 0;
if (draft) {
const inRelationTest = i % 2 !== 0;
if (inRelationTest) {
assertInEntries(`This is post # ${i} --`);
} else {
assertNotInEntries(`This is post # ${i} --`);
Expand All @@ -73,7 +90,7 @@ describe('View Filter', () => {
assertNotInEntries('This is a TOML front matter post');

// disable filter
filter('Drafts');
filter('Relation Test');
assertEntriesCount(23);
for (let i = 1; i <= 20; i++) {
assertInEntries(`This is post # ${i} --`);
Expand All @@ -82,21 +99,4 @@ describe('View Filter', () => {
assertInEntries('This is a JSON front matter post');
assertInEntries('This is a TOML front matter post');
});

it('can apply multiple filters', () => {
// enable filter
filter('Posts Without Index');

assertEntriesCount(3);

assertInEntries('This is a YAML front matter post');
assertInEntries('This is a JSON front matter post');
assertInEntries('This is a TOML front matter post');

filter('Drafts');

assertEntriesCount(0);

cy.contains('div', 'No Entries');
});
});
6 changes: 3 additions & 3 deletions cypress/e2e/view_groups_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ describe('View Group', () => {
assertInEntries('This is a TOML front matter post');

//enable group
group('Drafts');
group('Relation Test');

assertEntriesCount(23);
assertGroupsCount(3);
assertEachGroupCount('Draftstrue', 10);
assertEachGroupCount('Draftsfalse', 10);
assertEachGroupCount('Relation Testtrue', 10);
assertEachGroupCount('Relation Testfalse', 10);
assertEachGroupCount('missing_value', 3);
});
});
4 changes: 0 additions & 4 deletions dev-test/backends/azure/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ collections:
- label: Title
name: title
widget: string
- label: Draft
name: draft
widget: boolean
default: true
- label: Body
name: body
widget: markdown
4 changes: 0 additions & 4 deletions dev-test/backends/bitbucket/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ collections:
- label: Title
name: title
widget: string
- label: Draft
name: draft
widget: boolean
default: true
- label: Body
name: body
widget: markdown
4 changes: 0 additions & 4 deletions dev-test/backends/git-gateway/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ collections:
- label: Title
name: title
widget: string
- label: Draft
name: draft
widget: boolean
default: true
- label: Body
name: body
widget: markdown
4 changes: 0 additions & 4 deletions dev-test/backends/gitea/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ collections:
- label: Title
name: title
widget: string
- label: Draft
name: draft
widget: boolean
default: true
- label: Body
name: body
widget: markdown
4 changes: 0 additions & 4 deletions dev-test/backends/github/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ collections:
- label: Title
name: title
widget: string
- label: Draft
name: draft
widget: boolean
default: true
- label: Body
name: body
widget: markdown
4 changes: 0 additions & 4 deletions dev-test/backends/gitlab/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ collections:
- label: Title
name: title
widget: string
- label: Draft
name: draft
widget: boolean
default: true
- label: Body
name: body
widget: markdown
4 changes: 0 additions & 4 deletions dev-test/backends/proxy/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ collections:
- label: Title
name: title
widget: string
- label: Draft
name: draft
widget: boolean
default: true
- label: Body
name: body
widget: markdown
10 changes: 5 additions & 5 deletions dev-test/backends/test/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ collections: # A list of collections the CMS should be able to edit
- label: Posts Without Index
field: title
pattern: front matter post
- label: Drafts
field: draft
- label: Relation Test
field: relation_test
pattern: true
view_groups:
- label: Year
field: date
pattern: \d{4}
- label: Drafts
field: draft
- label: Relation Test
field: relation_test
fields: # The fields each document in this collection have
- { label: 'Title', name: 'title', widget: 'string', tagname: 'h1' }
- { label: 'Draft', name: 'draft', widget: 'boolean', default: false }
- { label: 'Relation Test', name: 'relation_test', widget: 'hidden', default: true }
- {
label: 'Publish Date',
name: 'date',
Expand Down
2 changes: 1 addition & 1 deletion dev-test/backends/test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
var slug = dateString + "-post-number-" + i + ".md";

window.repoFiles._posts[slug] = {
content: "---\ntitle: \"This is post # " + i + `\"\ndraft: ${i % 2 === 0}` + "\ndate: " + dateString + "T00:00:00.000Z\n---\n\n# The post is number " + i + "\n\nAnd this is yet another identical post body"
content: "---\ntitle: \"This is post # " + i + `\"\nrelation_test: ${i % 2 !== 0}` + "\ndate: " + dateString + "T00:00:00.000Z\n---\n\n# The post is number " + i + "\n\nAnd this is yet another identical post body"
}
}

Expand Down
22 changes: 15 additions & 7 deletions dev-test/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,25 @@ collections: # A list of collections the CMS should be able to edit
sortable_fields:
- title
- { field: date, default_sort: desc }
- draft
view_filters:
- label: Posts With Index
field: title
pattern: 'This is post #'
- label: Posts Without Index
field: title
pattern: front matter post
- label: Drafts
field: draft
- label: Relation Test
field: relation_test
pattern: true
view_groups:
- label: Year
field: date
pattern: \d{4}
- label: Drafts
field: draft
- label: Relation Test
field: relation_test
fields: # The fields each document in this collection have
- { label: 'Title', name: 'title', widget: 'string', tagname: 'h1' }
- { label: 'Draft', name: 'draft', widget: 'boolean', default: false }
- { label: 'Relation Test', name: 'relation_test', widget: 'hidden', default: true }
- {
label: 'Publish Date',
name: 'date',
Expand Down Expand Up @@ -75,7 +74,16 @@ collections: # A list of collections the CMS should be able to edit
- { label: 'Title', name: 'title', widget: 'string', tagname: 'h1' }
- { label: 'Body', name: 'body', widget: 'markdown', hint: 'Main content goes here.' }
- { name: 'gallery', widget: 'image', choose_url: true, media_library: {config: {multiple: true, max_files: 999}}}
- { name: 'post', widget: relation, collection: posts, multiple: true, search_fields: [ "title" ], display_fields: [ "title" ], value_field: "{{slug}}", filters: [ {field: "draft", values: [false]} ] }
- name: post
widget: relation
collection: posts
multiple: true
search_fields: ['title']
display_fields: ['title']
value_field: '{{slug}}'
filters:
- field: relation_test
values: [true]
- name: authors
label: Authors
label_singular: 'Author'
Expand Down
2 changes: 1 addition & 1 deletion dev-test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
var slug = dateString + "-post-number-" + i + ".md";

window.repoFiles._posts[slug] = {
content: "---\ntitle: \"This is post # " + i + `\"\ndraft: ${i % 2 === 0}` + "\ndate: " + dateString + "T00:00:00.000Z\n---\n\n# The post is number " + i + "\n\nAnd this is yet another identical post body"
content: "---\ntitle: \"This is post # " + i + `\"\nrelation_test: ${i % 2 !== 0}` + "\ndate: " + dateString + "T00:00:00.000Z\n---\n\n# The post is number " + i + "\n\nAnd this is yet another identical post body"
}
}

Expand Down
24 changes: 14 additions & 10 deletions packages/decap-cms-widget-relation/src/__tests__/relation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const filterBooleanFieldConfig = {
value_field: 'title',
filters: [
{
field: 'draft',
field: 'featured',
values: [false],
},
],
Expand Down Expand Up @@ -120,7 +120,7 @@ const multipleFiltersFieldConfig = {
values: ['Post # 1', 'Post # 2', 'Post # 7', 'Post # 9', 'Post # 15'],
},
{
field: 'draft',
field: 'featured',
values: [true],
},
],
Expand All @@ -134,7 +134,7 @@ const emptyFilterFieldConfig = {
value_field: 'title',
filters: [
{
field: 'draft',
field: 'featured',
values: [],
},
],
Expand All @@ -158,10 +158,10 @@ function generateHits(length) {
const hits = Array.from({ length }, (val, idx) => {
const title = `Post # ${idx + 1}`;
const slug = `post-number-${idx + 1}`;
const draft = idx % 2 === 0;
const featured = idx % 2 === 0;
const num = idx + 1;
const path = `posts/${slug}.md`;
return { collection: 'posts', data: { title, slug, draft, num }, slug, path };
return { collection: 'posts', data: { title, slug, featured, num }, slug, path };
});

return [
Expand Down Expand Up @@ -385,7 +385,7 @@ describe('Relation widget', () => {
const label = 'Post # 1 post-number-1';
const metadata = {
post: {
posts: { 'Post # 1': { title: 'Post # 1', draft: true, num: 1, slug: 'post-number-1' } },
posts: { 'Post # 1': { title: 'Post # 1', featured: true, num: 1, slug: 'post-number-1' } },
},
};

Expand All @@ -405,7 +405,7 @@ describe('Relation widget', () => {
const label = 'Post # 1 post-number-1';
const metadata = {
post: {
posts: { 'Post # 1': { title: 'Post # 1', draft: true, num: 1, slug: 'post-number-1' } },
posts: { 'Post # 1': { title: 'Post # 1', featured: true, num: 1, slug: 'post-number-1' } },
},
};

Expand Down Expand Up @@ -465,7 +465,7 @@ describe('Relation widget', () => {
const metadata = {
post: {
posts: {
'post-number-1': { title: 'Post # 1', draft: true, num: 1, slug: 'post-number-1' },
'post-number-1': { title: 'Post # 1', featured: true, num: 1, slug: 'post-number-1' },
},
},
};
Expand Down Expand Up @@ -524,12 +524,16 @@ describe('Relation widget', () => {
const { getByText, input, onChangeSpy } = setup({ field });
const metadata1 = {
post: {
posts: { 'Post # 1': { title: 'Post # 1', draft: true, num: 1, slug: 'post-number-1' } },
posts: {
'Post # 1': { title: 'Post # 1', featured: true, num: 1, slug: 'post-number-1' },
},
},
};
const metadata2 = {
post: {
posts: { 'Post # 2': { title: 'Post # 2', draft: false, num: 2, slug: 'post-number-2' } },
posts: {
'Post # 2': { title: 'Post # 2', featured: false, num: 2, slug: 'post-number-2' },
},
},
};

Expand Down
Loading