Admin.TagOverview.feature

backend lint fixes
This commit is contained in:
Ulf Gebhardt 2021-04-11 19:42:40 +02:00
parent 3ab9ad8c8f
commit b874d7a8ef
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD
7 changed files with 71 additions and 128 deletions

View File

@ -105,12 +105,12 @@ Factory.define('user')
})
Factory.define('post')
/*.option('categoryIds', [])
/* .option('categoryIds', [])
.option('categories', ['categoryIds'], (categoryIds) => {
if (categoryIds.length) return Promise.all(categoryIds.map((id) => neode.find('Category', id)))
// there must be at least one category
return Promise.all([Factory.build('category')])
})*/
}) */
.option('tagIds', [])
.option('tags', ['tagIds'], (tagIds) => {
return Promise.all(tagIds.map((id) => neode.find('Tag', id)))
@ -147,16 +147,16 @@ Factory.define('post')
return language || 'en'
})
.after(async (buildObject, options) => {
const [post, author, image, /*categories,*/ tags] = await Promise.all([
const [post, author, image, /* categories, */ tags] = await Promise.all([
neode.create('Post', buildObject),
options.author,
options.image,
//options.categories,
// options.categories,
options.tags,
])
await Promise.all([
post.relateTo(author, 'author'),
//Promise.all(categories.map((c) => c.relateTo(post, 'post'))),
// Promise.all(categories.map((c) => c.relateTo(post, 'post'))),
Promise.all(tags.map((t) => t.relateTo(post, 'post'))),
])
if (image) await post.relateTo(image, 'image')

View File

@ -0,0 +1,30 @@
Feature: Admin tag overview
As a database administrator
I would like to see a overview of all tags and their usage
In order to be able to decide which tags are popular or not
Background:
Given the following "users" are in the database:
| slug | email | password | id | name | role | termsAndConditionsAgreedVersion |
| admin | admin@example.org | 1234 | admin | Admin-Man | admin | 0.0.4 |
| u1 | u1@example.org | 1234 | u1 | User1 | user | 0.0.4 |
| u2 | u2@example.org | 1234 | u2 | User2 | user | 0.0.4 |
And the following "tags" are in the database:
| id |
| Ecology |
| Nature |
| Democracy |
And the following "posts" are in the database:
| id | title | authorId | tagIds |
| p1 | P1 from U1 | u1 | Nature, Democracy |
| p2 | P2 from U1 | u1 | Ecology, Democracy |
| p3 | P3 from U2 | u2 | Nature, Democracy |
And I am logged in as "admin"
Scenario: See an overview of tags
When I navigate to page "/admin/hashtags"
Then I can see the following table:
| No. | Hashtags | Users | Posts |
| 1 | #Nature | 2 | 2 |
| 2 | #Democracy | 2 | 3 |
| 3 | #Ecology | 1 | 1 |

View File

@ -0,0 +1,16 @@
import { Then } from "cypress-cucumber-preprocessor/steps";
Then('I can see the following table:', table => {
const headers = table.raw()[0]
headers.forEach((expected, i) => {
cy.get('thead th')
.eq(i)
.should('contain', expected)
})
const flattened = [].concat.apply([], table.rows())
flattened.forEach((expected, i) => {
cy.get('tbody td')
.eq(i)
.should('contain', expected)
})
})

View File

@ -1,21 +0,0 @@
import { When, Then } from 'cypress-cucumber-preprocessor/steps'
/* global cy */
When('I navigate to the administration dashboard', () => {
cy.get('.avatar-menu').click()
cy.get('.avatar-menu-popover')
.find('a[href="/admin"]')
.click()
})
Then('I can see the following table:', table => {
const headers = table.raw()[0]
headers.forEach((expected, i) => {
cy.get('thead th').eq(i).should('contain', expected)
})
const flattened = [].concat.apply([], table.rows())
flattened.forEach((expected, i) => {
cy.get('tbody td').eq(i).should('contain', expected)
})
})

View File

@ -1,21 +0,0 @@
import { When, Then } from "cypress-cucumber-preprocessor/steps";
import locales from '../../../webapp/locales'
import orderBy from 'lodash/orderBy'
const languages = orderBy(locales, 'name')
Then("I click on the {string} button", text => {
cy.get("button")
.contains(text)
.click();
});
When("I click on 'Pin post'", (string)=> {
cy.get("a.ds-menu-item-link").contains("Pin post")
.click()
})
/* Then('confirm crop', () => {
cy.get('.crop-confirm')
.click()
}) */

View File

@ -18,20 +18,6 @@ const annoyingParams = {
password: "1234",
};
Given("I log in as {string}", name => {
cy.logout()
cy.neode()
.first("User", {
name
})
.then(user => {
return new Cypress.Promise((resolve, reject) => {
return user.toJson().then((user) => resolve(user))
})
})
.then(user => cy.login(user))
})
Given("the {string} user searches for {string}", (_, postTitle) => {
cy.logout()
cy.neode()
@ -49,54 +35,8 @@ Given("the {string} user searches for {string}", (_, postTitle) => {
.type(postTitle);
});
Given("we have a selection of categories", () => {
cy.factory().build('category', { id: "cat0", slug: "just-for-fun" });
});
Given("we have a selection of tags and categories as well as posts", () => {
cy.factory()
.build('category', { id: 'cat12', name: "Just For Fun", icon: "smile", })
.build('category', { id: 'cat121', name: "Happiness & Values", icon: "heart-o"})
.build('category', { id: 'cat122', name: "Health & Wellbeing", icon: "medkit"})
.build("tag", { id: "Ecology" })
.build("tag", { id: "Nature" })
.build("tag", { id: "Democracy" })
.build("user", { id: 'a1' })
.build("post", {}, {
authorId: 'a1',
tagIds: ["Ecology", "Nature", "Democracy"],
categoryIds: ["cat12"]
})
.build("post", {}, {
authorId: 'a1',
tagIds: ["Nature", "Democracy"],
categoryIds: ["cat121"]
})
.build("user", { id: 'a2' })
.build("post", {}, {
authorId: 'a2',
tagIds: ['Nature', 'Democracy'],
categoryIds: ["cat12"]
})
.build("post", {}, {
tagIds: ['Democracy'],
categoryIds: ["cat122"]
})
});
Given("my user account has the role {string}", role => {
cy.factory().build("user", {
role,
...termsAndConditionsAgreedVersion,
}, /*loginCredentials*/ 'TODO');
});
When("I log out", cy.logout);
When("I visit {string}", page => {
cy.openPage(page);
});
When("a blocked user visits the post page of one of my authored posts", () => {
cy.logout()
cy.neode()
@ -112,10 +52,6 @@ When("a blocked user visits the post page of one of my authored posts", () => {
cy.openPage('post/previously-created-post')
})
Given("I am on the {string} page", page => {
cy.openPage(page);
});
When("I select {string} in the language menu", name => {
cy.switchLanguage(name, true);
});

View File

@ -3,30 +3,33 @@ import { Given } from "cypress-cucumber-preprocessor/steps";
Given("the following {string} are in the database:", (table,data) => {
switch(table){
case "posts":
data.hashes().forEach((attributesOrOptions, i) => {
data.hashes().forEach( entry => {
cy.factory().build("post", {
...attributesOrOptions,
deleted: Boolean(attributesOrOptions.deleted),
disabled: Boolean(attributesOrOptions.disabled),
pinned: Boolean(attributesOrOptions.pinned),
},
attributesOrOptions,
);
...entry,
deleted: Boolean(entry.deleted),
disabled: Boolean(entry.disabled),
pinned: Boolean(entry.pinned),
},{
...entry,
tagIds: entry.tagIds.split(',').map(item => item.trim()),
});
})
break
case "comments":
data.hashes().forEach((attributesOrOptions, i) => {
cy.factory().build("comment",
attributesOrOptions,
attributesOrOptions,
);
data.hashes().forEach( entry => {
cy.factory()
.build("comment",entry,entry);
})
break
case "users":
data.hashes().forEach(params => {
cy.factory().build("user",
params,
params);
data.hashes().forEach( entry => {
cy.factory().build("user",entry,entry);
});
break
case "tags":
data.hashes().forEach( entry => {
cy.factory().build("tag", entry, entry)
});
break
}
})