Skip to content

Commit

Permalink
Some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Zusoy committed Sep 17, 2023
1 parent de68bea commit 720d10c
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 26 deletions.
32 changes: 32 additions & 0 deletions apps/client/src/features/Messages/List/slice.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import slice, {
fetchAll,
received,
error,
initialState,
MessagesStatus
} from 'features/Messages/List/slice'
import { messageMock } from 'test-utils'

describe('Features/Messages/List', () => {
it('reduces fetchAll action', () => {
expect(slice.reducer(initialState, fetchAll('stationId'))).toEqual({
...initialState,
status: MessagesStatus.Fetching,
})
})

it('reduces received action', () => {
expect(slice.reducer(initialState, received([ messageMock ]))).toEqual({
...initialState,
status: MessagesStatus.Received,
items: [ messageMock ],
})
})

it('reduces error action', () => {
expect(slice.reducer(initialState, error())).toEqual({
...initialState,
status: MessagesStatus.Error,
})
})
})
25 changes: 0 additions & 25 deletions apps/client/src/features/Sidebar/Menu.tsx

This file was deleted.

1 change: 0 additions & 1 deletion apps/client/src/features/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Toolbar from '@mui/material/Toolbar'
import IconButton from '@mui/material/IconButton'
import ChevronLeft from '@mui/icons-material/ChevronLeft'
import Divider from '@mui/material/Divider'
import Menu from 'features/Sidebar/Menu'
import { styled } from '@mui/material/styles'

interface Props extends PropsWithChildren {
Expand Down
25 changes: 25 additions & 0 deletions apps/client/src/features/Stations/Join/effects.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import assert from 'assert'
import { joinStationEffect } from 'features/Stations/Join/effects'
import { join, joined } from 'features/Stations/Join/slice'
import { call, put } from 'redux-saga/effects'
import { post } from 'services/api'
import { stationMock } from 'test-utils'

describe('Effects/Stations/Join', () => {
describe('JoinStation', () => {
it('join station and notify', () => {
const action = join({ token: 'invitation_token' })
const effect = joinStationEffect(action)

assert.deepEqual(
effect.next().value,
call(post, '/stations/join', { token: 'invitation_token' })
)

assert.deepEqual(
effect.next(stationMock).value,
put(joined())
)
})
})
})
23 changes: 23 additions & 0 deletions apps/client/src/features/Stations/Join/slice.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import slice, { join, joined, error, initialState, JoinStatus } from 'features/Stations/Join/slice'

describe('Features/Stations/Join', () => {
it('reduces join action', () => {
expect(slice.reducer(initialState, join({ token: 'token' }))).toEqual({
...initialState,
status: JoinStatus.Joining,
})
})

it('reduces joined action', () => {
const initial = slice.reducer(initialState, join({ token: 'token' }))

expect(slice.reducer(initial, joined())).toEqual(initialState)
})

it('reduces error action', () => {
expect(slice.reducer(initialState, error())).toEqual({
...initialState,
status: JoinStatus.Error
})
})
})
13 changes: 13 additions & 0 deletions apps/client/src/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IUser } from 'models/user'
import { IStation } from 'models/station'
import { IChannel } from 'models/channel'
import { IMessage } from 'models/message'

export const userMock: IUser = {
id: 'ac199cb3-4211-4912-a32b-ab93d3a5bb7d',
Expand Down Expand Up @@ -29,3 +30,15 @@ export const channelMock: IChannel = {
updatedAt: '2023-01-01',
station: stationMock
}

export const messageMock: IMessage = {
id: '15b5c108-8372-4a13-9de1-8841b9cdf196',
content: 'Hello world !',
createdAt: '2023-01-01',
updatedAt: '2023-01-01',
author: {
id: 'ad53d256-a27e-4212-89a0-a7732e10b904',
name: 'John Doe',
},
channel: channelMock
}

0 comments on commit 720d10c

Please sign in to comment.