Fix/extend cypress tests

This commit is contained in:
mattwr18 2020-01-08 17:08:06 +01:00
parent c297b83f87
commit cd7f0e2783
7 changed files with 46 additions and 23 deletions

View File

@ -36,7 +36,6 @@ export default function create() {
if (categoryIds)
categories = await Promise.all(categoryIds.map(id => neodeInstance.find('Category', id)))
categories = categories || (await Promise.all([factoryInstance.create('Category')]))
const { tagIds = [] } = args
delete args.tags
const tags = await Promise.all(

View File

@ -29,10 +29,20 @@ const narratorParams = {
...termsAndConditionsAgreedVersion,
};
const annoyingParams = {
email: "spammy-spammer@example.org",
password: "1234",
...termsAndConditionsAgreedVersion
};
Given("I am logged in", () => {
cy.login(loginCredentials);
});
Given("I am logged in as the blacklisted user", () => {
cy.login({ email: annoyingParams.email, password: '1234' });
});
Given("we have a selection of categories", () => {
cy.createCategories("cat0", "just-for-fun");
});
@ -227,7 +237,6 @@ Given("I previously created a post", () => {
lastPost.authorId = narratorParams.id
lastPost.title = "previously created post";
lastPost.content = "with some content";
lastPost.categoryIds = ["cat0"];
cy.factory()
.create("Post", lastPost);
});
@ -407,11 +416,6 @@ Then("there are no notifications in the top menu", () => {
});
Given("there is an annoying user called {string}", name => {
const annoyingParams = {
email: "spammy-spammer@example.org",
password: "1234",
...termsAndConditionsAgreedVersion
};
cy.factory().create("User", {
...annoyingParams,
id: "annoying-user",
@ -519,12 +523,12 @@ When("I blacklist the user {string}", name => {
.first("User", {
name
})
.then(blacklisted => {
.then(blacklistedUser => {
cy.neode()
.first("User", {
name: narratorParams.name
})
.relateTo(blacklisted, "blacklisted");
.relateTo(blacklistedUser, "blacklisted");
});
});

View File

@ -26,7 +26,7 @@ Feature: Blacklist a User
Scenario: Posts of blacklisted users are filtered from search results
Given we have the following posts in our database:
| id | title | content |
| id | title | content |
| im-not-blacklisted | Post that should be seen | cause I'm not blacklisted |
Given "Spammy Spammer" wrote a post "Spam Spam Spam"
When I search for "Spam"
@ -41,3 +41,13 @@ Feature: Blacklist a User
Then I should see the following posts in the select dropdown:
| title |
| Post that should be seen |
Scenario: Blacklisted users can still see my posts
Given I previously created a post
And I blacklist the user "Spammy Spammer"
Given I log out
And I am logged in as the blacklisted user
When I search for "previously created"
Then I should see the following posts in the select dropdown:
| title |
| previously created post |

View File

@ -10,7 +10,7 @@ Feature: Blacklist a User
Scenario Outline: Blacklisted users cannot see each others posts
Given "Spammy Spammer" wrote a post "Spam Spam Spam"
And I wrote a post "I hate spammers"
And I block the user "Spammy Spammer"
And I I blacklist the user "Spammy Spammer"
When I log in with:
| Email | Password |
| <email> | <password> |

View File

@ -60,7 +60,7 @@ Cypress.Commands.add("login", ({ email, password }) => {
.as("submitButton")
.click();
cy.get(".iziToast-message").should("contain", "You are logged in!");
cy.get(".iziToast-close").click();
cy.location("pathname").should("eq", "/");
});
Cypress.Commands.add("logout", (email, password) => {

View File

@ -22,8 +22,8 @@
:resource="user"
:is-owner="myProfile"
class="user-content-menu"
@blacklist="blacklist"
@whitelist="whitelist"
@blacklist="blacklistUserContent"
@whitelist="whitelistUserContent"
/>
</client-only>
<ds-space margin="small">
@ -399,16 +399,26 @@ export default {
this.hasMore = true
},
async blacklistUserContent(user) {
await this.$apollo.mutate({ mutation: blacklistUserContent(), variables: { id: user.id } })
this.$apollo.queries.User.refetch()
this.resetPostList()
this.$apollo.queries.profilePagePosts.refetch()
try {
await this.$apollo.mutate({ mutation: blacklistUserContent(), variables: { id: user.id } })
} catch (error) {
this.$toast.error(error.message)
} finally {
this.$apollo.queries.User.refetch()
this.resetPostList()
this.$apollo.queries.profilePagePosts.refetch()
}
},
async whitelistUserContent(user) {
await this.$apollo.mutate({ mutation: whitelistUserContent(), variables: { id: user.id } })
this.$apollo.queries.User.refetch()
this.resetPostList()
this.$apollo.queries.profilePagePosts.refetch()
try {
this.$apollo.mutate({ mutation: whitelistUserContent(), variables: { id: user.id } })
} catch (error) {
this.$toast.error(error.message)
} finally {
this.$apollo.queries.User.refetch()
this.resetPostList()
this.$apollo.queries.profilePagePosts.refetch()
}
},
pinPost(post) {
this.$apollo

View File

@ -98,7 +98,7 @@ export default {
avatar: '',
name: this.$t('settings.blacklisted-users.columns.name'),
slug: this.$t('settings.blacklisted-users.columns.slug'),
whitelistUserContent: this.$t('settings.blacklisted-users.columns.unblock'),
whitelistUserContent: this.$t('settings.blacklisted-users.columns.whitelist'),
}
},
},