chore: remove jest -> cypress for unit tests

This commit is contained in:
Divlo
2022-08-23 21:51:20 +02:00
parent d8cedd7b77
commit 7ad3d226dc
87 changed files with 2668 additions and 7876 deletions

View File

@ -0,0 +1,271 @@
import date from 'date-and-time'
import {
channelExample,
channelExample2
} from '../../../../../fixtures/channels/channel'
import { guildExample } from '../../../../../fixtures/guilds/guild'
import {
getGuildMemberNotOwnerWithGuildIdHandler,
getGuildMemberWithGuildIdHandler
} from '../../../../../fixtures/guilds/[guildId]/get'
import { getChannelWithChannelIdHandler } from '../../../../../fixtures/channels/[channelId]/get'
import { authenticationHandlers } from '../../../../../fixtures/handler'
import { getGuildsHandler } from '../../../../../fixtures/guilds/get'
import { getChannelsWithGuildIdHandler } from '../../../../../fixtures/guilds/[guildId]/channels/get'
import { getMessagesWithChannelIdHandler } from '../../../../../fixtures/channels/[channelId]/messages/get'
import {
messageExampleComplete,
messageExampleComplete2
} from '../../../../../fixtures/messages/message'
import { getMembersWithGuildIdHandler } from '../../../../../fixtures/guilds/[guildId]/members/get'
import { memberExampleComplete } from '../../../../../fixtures/members/member'
import { API_URL } from '../../../../../../tools/api'
import {
getMessagesUploadsAudioHandler,
getMessagesUploadsDownloadHandler,
getMessagesUploadsImageHandler,
getMessagesUploadsVideoHandler
} from '../../../../../fixtures/uploads/messages/get'
describe('Pages > /application/[guildId]/[channelId]', () => {
beforeEach(() => {
cy.task('stopMockServer')
})
it('should succeeds and display the left sidebar correctly (member is owner)', () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildMemberWithGuildIdHandler,
getChannelWithChannelIdHandler,
getGuildsHandler
]).setCookie('refreshToken', 'refresh-token')
cy.intercept(`${API_URL}${getGuildsHandler.url}*`).as('getGuildsHandler')
cy.visit(`/application/${guildExample.id}/${channelExample.id}`)
cy.wait(['@getGuildsHandler']).then(() => {
cy.get('[data-cy=application-title]').should(
'have.text',
`# ${channelExample.name}`
)
cy.get('[data-cy=guild-left-sidebar-title]').should(
'have.text',
guildExample.name
)
cy.get('.guilds-list').children().should('have.length', 2)
cy.get('[data-cy=link-add-channel]')
.should('be.visible')
.should(
'have.attr',
'href',
`/application/${guildExample.id}/channels/create`
)
cy.get('[data-cy=link-settings-guild]')
.should('be.visible')
.should('have.attr', 'href', `/application/${guildExample.id}/settings`)
})
})
it('should succeeds and display the left sidebar correctly (member is not owner)', () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildMemberNotOwnerWithGuildIdHandler,
getChannelWithChannelIdHandler,
getGuildsHandler
]).setCookie('refreshToken', 'refresh-token')
cy.intercept(`${API_URL}${getGuildsHandler.url}*`).as('getGuildsHandler')
cy.visit(`/application/${guildExample.id}/${channelExample.id}`)
cy.wait(['@getGuildsHandler']).then(() => {
cy.get('[data-cy=application-title]').should(
'have.text',
`# ${channelExample.name}`
)
cy.get('[data-cy=guild-left-sidebar-title]').should(
'have.text',
guildExample.name
)
cy.get('.guilds-list').children().should('have.length', 2)
cy.get('[data-cy=link-add-channel]').should('not.exist')
cy.get('[data-cy=link-settings-guild]')
.should('be.visible')
.should('have.attr', 'href', `/application/${guildExample.id}/settings`)
})
})
it('should succeeds and display the channels in left sidebar correctly', () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildMemberWithGuildIdHandler,
getChannelWithChannelIdHandler,
getChannelsWithGuildIdHandler
]).setCookie('refreshToken', 'refresh-token')
cy.intercept(`${API_URL}${getChannelsWithGuildIdHandler.url}*`).as(
'getChannelsWithGuildIdHandler'
)
cy.visit(`/application/${guildExample.id}/${channelExample.id}`)
cy.wait(['@getChannelsWithGuildIdHandler']).then(() => {
cy.get('.channels-list').children().should('have.length', 2)
cy.get('.channels-list [data-cy=channel-name]:first').should(
'have.text',
`# ${channelExample.name}`
)
cy.get('.channels-list [data-cy=channel-name]:last').should(
'have.text',
`# ${channelExample2.name}`
)
})
})
it('should succeeds and display the messages correctly', () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildMemberWithGuildIdHandler,
getChannelWithChannelIdHandler,
getMessagesWithChannelIdHandler,
getMessagesUploadsImageHandler,
getMessagesUploadsAudioHandler,
getMessagesUploadsVideoHandler,
getMessagesUploadsDownloadHandler
]).setCookie('refreshToken', 'refresh-token')
cy.intercept(`${API_URL}${getMessagesWithChannelIdHandler.url}*`).as(
'getMessagesWithChannelIdHandler'
)
cy.intercept(`${API_URL}${getMessagesUploadsImageHandler.url}`).as(
'getMessagesUploadsImageHandler'
)
cy.intercept(`${API_URL}${getMessagesUploadsAudioHandler.url}`).as(
'getMessagesUploadsAudioHandler'
)
cy.intercept(`${API_URL}${getMessagesUploadsVideoHandler.url}`).as(
'getMessagesUploadsVideoHandler'
)
cy.intercept(`${API_URL}${getMessagesUploadsDownloadHandler.url}`).as(
'getMessagesUploadsDownloadHandler'
)
cy.visit(`/application/${guildExample.id}/${channelExample.id}`)
cy.wait([
'@getMessagesWithChannelIdHandler',
'@getMessagesUploadsImageHandler',
'@getMessagesUploadsAudioHandler',
'@getMessagesUploadsVideoHandler',
'@getMessagesUploadsDownloadHandler'
]).then(() => {
cy.get('.messages-list').children().should('have.length', 9)
cy.get('[data-cy=message-1] p').should(
'have.text',
messageExampleComplete.value
)
cy.get('[data-cy=message-1] [data-cy=message-member-user-name]').should(
'have.text',
messageExampleComplete.member.user.name
)
cy.get('[data-cy=message-1] [data-cy=message-date]').should(
'have.text',
date.format(
new Date(messageExampleComplete.createdAt),
'DD/MM/YYYY - HH:mm:ss'
)
)
cy.get('[data-cy=message-2] p').should(
'have.text',
messageExampleComplete2.value
)
cy.get('[data-cy=message-3] p').should(
'have.text',
'Message with bold text and italic text.\nNewlines and some emoji: '
)
cy.get('[data-cy=message-3] strong').should('have.text', 'bold text')
cy.get('[data-cy=message-3] em').should('have.text', 'italic text')
cy.get('[data-cy=message-3] span[title=smile]').should('exist')
cy.get('[data-cy=message-3] span[title=smile]').should(
'have.css',
'width',
'20px'
)
cy.get('[data-cy=message-3] span[title=smile]').should(
'have.css',
'height',
'20px'
)
cy.get('[data-cy=message-4] p:first').should(
'have.text',
'The Quadratic Formula:'
)
cy.get('[data-cy=message-4] .math').should('have.length', 3)
cy.get('[data-cy=message-5] span[title=wave]').should('exist')
cy.get('[data-cy=message-5] span[title=wave]').should(
'have.css',
'width',
'40px'
)
cy.get('[data-cy=message-5] span[title=wave]').should(
'have.css',
'height',
'40px'
)
cy.get('[data-cy=message-file-image-6]').should('exist')
cy.get('[data-cy=message-file-audio-7]').should('exist')
cy.get('[data-cy=message-file-video-8]').should('exist')
cy.get('[data-cy=message-file-download-9]').should('exist')
})
})
it('should succeeds and display the members in right sidebar correctly', () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildMemberWithGuildIdHandler,
getChannelWithChannelIdHandler,
getMembersWithGuildIdHandler
]).setCookie('refreshToken', 'refresh-token')
cy.intercept(`${API_URL}${getMembersWithGuildIdHandler.url}*`).as(
'getMembersWithGuildIdHandler'
)
cy.visit(`/application/${guildExample.id}/${channelExample.id}`)
cy.wait(['@getMembersWithGuildIdHandler']).then(() => {
cy.get('.members-list').should('not.be.visible')
cy.get('[data-cy=icon-button-right-sidebar-members]').click()
cy.get('.members-list').should('be.visible')
cy.get('[data-cy=members-title]').should('have.text', 'Member(s)')
cy.get('.members-list').children().should('have.length', 1)
cy.get('.members-list [data-cy=member-user-name]:first').should(
'have.text',
memberExampleComplete.user.name
)
})
})
it('should redirect the user to `/404` if `guildId` or `channelId` are not numbers', () => {
cy.task('startMockServer', authenticationHandlers).setCookie(
'refreshToken',
'refresh-token'
)
cy.visit('/application/abc/abc', {
failOnStatusCode: false
})
.location('pathname')
.should('eq', '/404')
})
it("should redirect the user to `/404` if `guildId` doesn't exist", () => {
cy.task('startMockServer', [
...authenticationHandlers,
getChannelWithChannelIdHandler
]).setCookie('refreshToken', 'refresh-token')
cy.visit(`/application/123/${channelExample.id}`, {
failOnStatusCode: false
})
.location('pathname')
.should('eq', '/404')
})
it("should redirect the user to `/404` if `channelId` doesn't exist", () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildMemberWithGuildIdHandler
]).setCookie('refreshToken', 'refresh-token')
cy.visit(`/application/${guildExample.id}/123`, { failOnStatusCode: false })
.location('pathname')
.should('eq', '/404')
})
})
export {}

View File

@ -0,0 +1,136 @@
import { deleteChannelWithChannelIdHandler } from '../../../../../fixtures/channels/[channelId]/delete'
import { putChannelWithChannelIdHandler } from '../../../../../fixtures/channels/[channelId]/put'
import {
channelExample,
channelExample2
} from '../../../../../fixtures/channels/channel'
import { guildExample } from '../../../../../fixtures/guilds/guild'
import {
getGuildMemberNotOwnerWithGuildIdHandler,
getGuildMemberWithGuildIdHandler
} from '../../../../../fixtures/guilds/[guildId]/get'
import {
getChannelWithChannelIdHandler,
getChannelWithChannelIdHandler2
} from '../../../../../fixtures/channels/[channelId]/get'
import { authenticationHandlers } from '../../../../../fixtures/handler'
import { API_URL } from '../../../../../../tools/api'
describe('Pages > /application/[guildId]/[channelId]/settings', () => {
beforeEach(() => {
cy.task('stopMockServer')
})
it('should succeeds and update the channel name', () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildMemberWithGuildIdHandler,
getChannelWithChannelIdHandler,
putChannelWithChannelIdHandler
]).setCookie('refreshToken', 'refresh-token')
cy.intercept(`${API_URL}${putChannelWithChannelIdHandler.url}*`).as(
'putChannelWithChannelIdHandler'
)
cy.visit(`/application/${guildExample.id}/${channelExample.id}/settings`)
cy.get('[data-cy=channel-name-input]')
.clear()
.type(putChannelWithChannelIdHandler.response.body.name)
cy.get('[data-cy=button-save-channel-settings]').click()
cy.wait('@putChannelWithChannelIdHandler').then(() => {
cy.location('pathname').should(
'eq',
`/application/${guildExample.id}/${channelExample.id}`
)
})
})
it('should succeeds and delete the channel', () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildMemberWithGuildIdHandler,
getChannelWithChannelIdHandler,
getChannelWithChannelIdHandler2,
deleteChannelWithChannelIdHandler
]).setCookie('refreshToken', 'refresh-token')
cy.intercept(`${API_URL}${deleteChannelWithChannelIdHandler.url}*`).as(
'deleteChannelWithChannelIdHandler'
)
cy.visit(`/application/${guildExample.id}/${channelExample.id}/settings`)
cy.get('[data-cy=button-delete-channel-settings]').click()
cy.get('[data-cy=confirm-popup-yes-button]').click()
cy.wait('@deleteChannelWithChannelIdHandler').then(() => {
cy.location('pathname').should(
'eq',
`/application/${guildExample.id}/${channelExample2.id}`
)
})
})
it('should fails with too long channel name on update', () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildMemberWithGuildIdHandler,
getChannelWithChannelIdHandler
]).setCookie('refreshToken', 'refresh-token')
cy.visit(`/application/${guildExample.id}/${channelExample.id}/settings`)
cy.get('[data-cy=channel-name-input]').type(
'random channel name that is really too long for a channel name'
)
cy.get('[data-cy=button-save-channel-settings]').click()
cy.get('#error-name').should(
'have.text',
'Error: The field must contain at most 20 characters.'
)
})
it('should redirect the user to `/404` if member is not owner', () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildMemberNotOwnerWithGuildIdHandler,
getChannelWithChannelIdHandler
]).setCookie('refreshToken', 'refresh-token')
cy.visit(`/application/${guildExample.id}/${channelExample.id}/settings`, {
failOnStatusCode: false
})
.location('pathname')
.should('eq', '/404')
})
it('should redirect the user to `/404` if `guildId` or `channelId` are not numbers', () => {
cy.task('startMockServer', authenticationHandlers).setCookie(
'refreshToken',
'refresh-token'
)
cy.visit('/application/abc/abc/settings', {
failOnStatusCode: false
})
.location('pathname')
.should('eq', '/404')
})
it("should redirect the user to `/404` if `guildId` doesn't exist", () => {
cy.task('startMockServer', [
...authenticationHandlers,
getChannelWithChannelIdHandler
]).setCookie('refreshToken', 'refresh-token')
cy.visit(`/application/123/${channelExample.id}/settings`, {
failOnStatusCode: false
})
.location('pathname')
.should('eq', '/404')
})
it("should redirect the user to `/404` if `channelId` doesn't exist", () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildMemberWithGuildIdHandler
]).setCookie('refreshToken', 'refresh-token')
cy.visit(`/application/${guildExample.id}/123/settings`, {
failOnStatusCode: false
})
.location('pathname')
.should('eq', '/404')
})
})
export {}

View File

@ -0,0 +1,76 @@
import { postChannelsWithGuildIdHandler } from '../../../../../fixtures/guilds/[guildId]/channels/post'
import { API_URL } from '../../../../../../tools/api'
import { channelExample2 } from '../../../../../fixtures/channels/channel'
import { guildExample } from '../../../../../fixtures/guilds/guild'
import { getGuildMemberWithGuildIdHandler } from '../../../../../fixtures/guilds/[guildId]/get'
import { authenticationHandlers } from '../../../../../fixtures/handler'
import { getChannelWithChannelIdHandler2 } from '../../../../../fixtures/channels/[channelId]/get'
describe('Pages > /application/[guildId]/channels/create', () => {
beforeEach(() => {
cy.task('stopMockServer')
})
it('should succeeds and create the channel', () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildMemberWithGuildIdHandler,
postChannelsWithGuildIdHandler,
getChannelWithChannelIdHandler2
]).setCookie('refreshToken', 'refresh-token')
cy.intercept(`${API_URL}${postChannelsWithGuildIdHandler.url}*`).as(
'postChannelsWithGuildIdHandler'
)
cy.visit(`/application/${guildExample.id}/channels/create`)
cy.get('[data-cy=channel-name-input]').type(channelExample2.name)
cy.get('[data-cy=button-create-channel]').click()
cy.wait('@postChannelsWithGuildIdHandler').then(() => {
cy.location('pathname').should(
'eq',
`/application/${guildExample.id}/${channelExample2.id}`
)
})
})
it('should fails with too long channel name on update', () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildMemberWithGuildIdHandler
]).setCookie('refreshToken', 'refresh-token')
cy.visit(`/application/${guildExample.id}/channels/create`)
cy.get('[data-cy=channel-name-input]').type(
'random channel name that is really too long for a channel name'
)
cy.get('[data-cy=button-create-channel]').click()
cy.get('#error-name').should(
'have.text',
'Error: The field must contain at most 20 characters.'
)
})
it('should redirect the user to `/404` if `guildId` is not a number', () => {
cy.task('startMockServer', authenticationHandlers).setCookie(
'refreshToken',
'refresh-token'
)
cy.visit('/application/abc/channels/create', {
failOnStatusCode: false
})
.location('pathname')
.should('eq', '/404')
})
it("should redirect the user to `/404` if `guildId` doesn't exist", () => {
cy.task('startMockServer', [...authenticationHandlers]).setCookie(
'refreshToken',
'refresh-token'
)
cy.visit(`/application/123/channels/create`, {
failOnStatusCode: false
})
.location('pathname')
.should('eq', '/404')
})
})
export {}

View File

@ -0,0 +1,106 @@
import { deleteLeaveMembersWithGuildIdHandler } from '../../../../fixtures/guilds/[guildId]/members/leave'
import { guildExample } from '../../../../fixtures/guilds/guild'
import {
getGuildMemberNotOwnerWithGuildIdHandler,
getGuildMemberWithGuildIdHandler
} from '../../../../fixtures/guilds/[guildId]/get'
import { authenticationHandlers } from '../../../../fixtures/handler'
import { API_URL } from '../../../../../tools/api'
import { deleteGuildWithGuildIdHandler } from '../../../../fixtures/guilds/[guildId]/delete'
describe('Pages > /application/[guildId]/settings', () => {
beforeEach(() => {
cy.task('stopMockServer')
})
it('should succeeds and display correctly the settings of the guild (member is owner)', () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildMemberWithGuildIdHandler
]).setCookie('refreshToken', 'refresh-token')
cy.visit(`/application/${guildExample.id}/settings`)
cy.get('[data-cy=guild-name-input]').should('have.value', guildExample.name)
cy.get('[data-cy=guild-description-input]').should(
'have.value',
guildExample.description
)
cy.get('[data-cy=button-save-guild-settings]').should('be.visible')
cy.get('[data-cy=button-delete-guild-settings]').should('be.visible')
cy.get('[data-cy=button-leave-guild-settings]').should('not.exist')
})
it('should succeeds and display correctly the settings of the guild (member is not owner)', () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildMemberNotOwnerWithGuildIdHandler
]).setCookie('refreshToken', 'refresh-token')
cy.visit(`/application/${guildExample.id}/settings`)
cy.get('[data-cy=guild-name-input]').should('not.exist')
cy.get('[data-cy=guild-description-input]').should('not.exist')
cy.get('[data-cy=button-save-guild-settings]').should('not.exist')
cy.get('[data-cy=button-delete-guild-settings]').should('not.exist')
cy.get('[data-cy=button-leave-guild-settings]').should('be.visible')
})
it('should succeeds and leave the guild (member is not owner)', () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildMemberNotOwnerWithGuildIdHandler,
deleteLeaveMembersWithGuildIdHandler
]).setCookie('refreshToken', 'refresh-token')
cy.intercept(`${API_URL}${deleteLeaveMembersWithGuildIdHandler.url}*`).as(
'deleteLeaveMembersWithGuildIdHandler'
)
cy.visit(`/application/${guildExample.id}/settings`)
cy.get('[data-cy=button-leave-guild-settings]').click()
cy.wait('@deleteLeaveMembersWithGuildIdHandler').then(() => {
cy.location('pathname').should('eq', '/application')
})
})
it('should succeeds and delete the guild', () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildMemberWithGuildIdHandler,
deleteGuildWithGuildIdHandler
]).setCookie('refreshToken', 'refresh-token')
cy.intercept(`${API_URL}${deleteGuildWithGuildIdHandler.url}*`).as(
'deleteGuildWithGuildIdHandler'
)
cy.visit(`/application/${guildExample.id}/settings`)
cy.get('[data-cy=button-delete-guild-settings]').click()
cy.get('[data-cy=confirm-popup-yes-button]').click()
cy.wait('@deleteGuildWithGuildIdHandler').then((interception) => {
expect(interception.response).to.not.be.eql(undefined)
if (interception.response !== undefined) {
expect(interception.response.statusCode).to.eq(200)
}
})
})
it('should redirect the user to `/404` if `guildId` is not a number', () => {
cy.task('startMockServer', authenticationHandlers).setCookie(
'refreshToken',
'refresh-token'
)
cy.visit('/application/abc/settings', {
failOnStatusCode: false
})
.location('pathname')
.should('eq', '/404')
})
it("should redirect the user to `/404` if `guildId` doesn't exist", () => {
cy.task('startMockServer', [...authenticationHandlers]).setCookie(
'refreshToken',
'refresh-token'
)
cy.visit(`/application/123/settings`, {
failOnStatusCode: false
})
.location('pathname')
.should('eq', '/404')
})
})
export {}

View File

@ -0,0 +1,46 @@
import { getChannelWithChannelIdHandler } from '../../../../fixtures/channels/[channelId]/get'
import { getGuildsHandler } from '../../../../fixtures/guilds/get'
import { getGuildMemberWithGuildIdHandler } from '../../../../fixtures/guilds/[guildId]/get'
import { channelExample } from '../../../../fixtures/channels/channel'
import { guildExample } from '../../../../fixtures/guilds/guild'
import { postGuildsHandler } from '../../../../fixtures/guilds/post'
import { authenticationHandlers } from '../../../../fixtures/handler'
describe('Pages > /application/guilds/create', () => {
beforeEach(() => {
cy.task('stopMockServer')
})
it('should succeeds and create the guild', () => {
cy.task('startMockServer', [
...authenticationHandlers,
postGuildsHandler,
getGuildsHandler,
getGuildMemberWithGuildIdHandler,
getChannelWithChannelIdHandler
]).setCookie('refreshToken', 'refresh-token')
cy.visit('/application/guilds/create')
cy.get('[data-cy=application-title]').should('have.text', 'Create a Guild')
cy.get('#error-name').should('not.exist')
cy.get('[data-cy=input-name]').type(guildExample.name)
cy.get('[data-cy=submit]').click()
cy.location('pathname').should(
'eq',
`/application/${guildExample.id}/${channelExample.id}`
)
})
it('should fails with internal api server error', () => {
cy.task('startMockServer', [...authenticationHandlers]).setCookie(
'refreshToken',
'refresh-token'
)
cy.visit('/application/guilds/create')
cy.get('#error-name').should('not.exist')
cy.get('[data-cy=input-name]').type(guildExample.name)
cy.get('[data-cy=submit]').click()
cy.get('#message').should('have.text', 'Error: Internal Server Error.')
})
})
export {}

View File

@ -0,0 +1,82 @@
import { guildExample, guildExample2 } from '../../../../fixtures/guilds/guild'
import {
getGuildsPublicEmptyHandler,
getGuildsPublicHandler,
getGuildsPublicSearchHandler
} from '../../../../fixtures/guilds/public/get'
import { authenticationHandlers } from '../../../../fixtures/handler'
import { API_URL } from '../../../../../tools/api'
describe('Pages > /application/guilds/join', () => {
beforeEach(() => {
cy.task('stopMockServer')
})
it('should shows all the guilds', () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildsPublicHandler
]).setCookie('refreshToken', 'refresh-token')
cy.intercept(`${API_URL}${getGuildsPublicHandler.url}*`).as(
'getGuildsPublicHandler'
)
cy.visit('/application/guilds/join')
cy.wait(['@getGuildsPublicHandler']).then(() => {
cy.get('[data-cy=application-title]').should('have.text', 'Join a Guild')
cy.get('.guilds-public-list').children().should('have.length', 2)
cy.get('.guilds-public-list [data-cy=guild-name]:first').should(
'have.text',
guildExample.name
)
cy.get('.guilds-public-list [data-cy=guild-name]:last').should(
'have.text',
guildExample2.name
)
})
})
it('should shows the searched guild', () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildsPublicSearchHandler
]).setCookie('refreshToken', 'refresh-token')
cy.visit('/application/guilds/join')
cy.intercept(`${API_URL}${getGuildsPublicHandler.url}*`).as(
'getGuildsPublicHandler'
)
cy.wait(['@getGuildsPublicHandler']).then(() => {
cy.get('[data-cy=search-guild-input]').type(guildExample2.name)
cy.get('.guilds-public-list').children().should('have.length', 1)
cy.get('.guilds-public-list [data-cy=guild-name]:first').should(
'have.text',
guildExample2.name
)
})
})
it('should shows no guild if there are no public guilds', () => {
cy.task('startMockServer', [
...authenticationHandlers,
getGuildsPublicEmptyHandler
]).setCookie('refreshToken', 'refresh-token')
cy.intercept(`${API_URL}${getGuildsPublicEmptyHandler.url}*`).as(
'getGuildsPublicEmptyHandler'
)
cy.visit('/application/guilds/join')
cy.wait('@getGuildsPublicEmptyHandler').then(() => {
cy.get('.guilds-public-list').children().should('have.length', 0)
})
})
it('should shows loader with internal api server error', () => {
cy.task('startMockServer', [...authenticationHandlers]).setCookie(
'refreshToken',
'refresh-token'
)
cy.visit('/application/guilds/join')
cy.get('.guilds-public-list').children().should('have.length', 1)
cy.get('[data-cy=progress-spinner]').should('be.visible')
})
})
export {}

View File

@ -0,0 +1,34 @@
import { authenticationHandlers } from '../../../fixtures/handler'
describe('Pages > /application', () => {
beforeEach(() => {
cy.task('stopMockServer')
})
it('should redirect user to `/application/guilds/create` on click on "Create a Guild"', () => {
cy.task('startMockServer', [...authenticationHandlers]).setCookie(
'refreshToken',
'refresh-token'
)
cy.visit('/application')
cy.get('[data-cy=application-title]').should('have.text', 'Application')
cy.get('a[href="/application/guilds/create"]')
.click()
.location('pathname')
.should('eq', '/application/guilds/create')
})
it('should redirect user to `/application/guilds/join` on click on "Join a Guild"', () => {
cy.task('startMockServer', [...authenticationHandlers]).setCookie(
'refreshToken',
'refresh-token'
)
cy.visit('/application')
cy.get('a[href="/application/guilds/join"]')
.click()
.location('pathname')
.should('eq', '/application/guilds/join')
})
})
export {}

View File

@ -0,0 +1,37 @@
import date from 'date-and-time'
import { userExample } from '../../../../../fixtures/users/user'
import { getUserByIdHandler } from '../../../../../fixtures/users/[userId]/get'
import { authenticationHandlers } from '../../../../../fixtures/handler'
describe('Pages > /application/users/[userId]', () => {
beforeEach(() => {
cy.task('stopMockServer')
})
it('should succeeds and display the public user profile correctly', () => {
cy.task('startMockServer', [
...authenticationHandlers,
getUserByIdHandler
]).setCookie('refreshToken', 'refresh-token')
cy.visit(`/application/users/${userExample.id}`)
cy.get('[data-cy=user-name]').should('have.text', userExample.name)
cy.get('[data-cy=user-email]').should('have.text', userExample.email)
cy.get('[data-cy=user-createdAt]').should(
'have.text',
date.format(new Date(userExample.createdAt), 'DD/MM/YYYY')
)
})
it("should redirect the user to `/404` if `userId` doesn't exist", () => {
cy.task('startMockServer', [...authenticationHandlers]).setCookie(
'refreshToken',
'refresh-token'
)
cy.visit(`/application/users/123`, { failOnStatusCode: false })
.location('pathname')
.should('eq', '/404')
})
})
export {}