<commit_before>import test from "ava"

import { spy } from "sinon"

import { identity } from "ramda"
import { v4 } from "uuid"

import { LEFT, RIGHT } from "~/share/constants/direction"

import store from "~/client/store"

test("hideNavigation", t => {
  const state = { showNavigation: true }
  store.mutations.hideNavigation(state)
  t.false(state.showNavigation)
})

test("toggleNavigation", t => {
  const state = { showNavigation: true }

  store.mutations.toggleNavigation(state)
  t.false(state.showNavigation)

  store.mutations.toggleNavigation(state)
  t.true(state.showNavigation)
})

test("login", t => {
  const state = { user: null }

  const user = { }
  const payload = { user }

  store.mutations.login(state, payload)

  t.is(user, state.user)
})

test("logout", t => {
  const state = { user: { } }
  store.mutations.logout(state)
  t.falsy(state.user)
})

test("universe", t => {
  const state = { universe: null }

  const universe = { }
  const payload = { universe }

  store.mutations.universe(state, payload)

  t.is(universe, state.universe)
})

test("logout action", async t => {
  global.fetch = identity
  store.actions.logout({ commit: identity })
  t.pass()
})

test("rotateLeft: when already rotating does nothing", t => {
  const send = spy()
  const state = { send, rotating: true }

  store.mutations.rotateLeft(state)

  t.true(send.notCalled)
})

test("rotateLeft: when after game exists", t => {
  const send = spy()
  const after = { uuid: v4() }
  const games = { after }

  const state = { send, games }

  store.mutations.rotateLeft(state)

  t.true(state.rotating)

  t.true(send.calledOnce)
  t.true(send.calledWithMatch({
    action: "rotate",
    direction: LEFT,
    of: games.after.uuid
  }))
})

test("rotateRight: when already rotating does nothing", t => {
  const send = spy()
  const state = { send, rotating: true }

  store.mutations.rotateRight(state)

  t.true(send.notCalled)
})

test("rotateRight: when before game exists", t => {
  const send = spy()
  const before = { uuid: v4() }
  const games = { before }

  const state = { send, games }

  store.mutations.rotateRight(state)

  t.true(state.rotating)

  t.true(send.calledOnce)
  t.true(send.calledWithMatch({
    action: "rotate",
    direction: RIGHT,
    of: games.before.uuid
  }))
})
<commit_msg>organize<commit_after>import test from "ava"

import { spy } from "sinon"

import { identity } from "ramda"
import { v4 } from "uuid"

import { LEFT, RIGHT } from "~/share/constants/direction"

import store from "~/client/store"

test("hideNavigation", t => {
  const state = { showNavigation: true }
  store.mutations.hideNavigation(state)
  t.false(state.showNavigation)
})

test("toggleNavigation", t => {
  const state = { showNavigation: true }

  store.mutations.toggleNavigation(state)
  t.false(state.showNavigation)

  store.mutations.toggleNavigation(state)
  t.true(state.showNavigation)
})

test("login", t => {
  const state = { user: null }

  const user = { }
  const payload = { user }

  store.mutations.login(state, payload)

  t.is(user, state.user)
})

test("logout", t => {
  const state = { user: { } }
  store.mutations.logout(state)
  t.falsy(state.user)
})

test("universe", t => {
  const state = { universe: null }

  const universe = { }
  const payload = { universe }

  store.mutations.universe(state, payload)

  t.is(universe, state.universe)
})

test("rotateLeft: when already rotating does nothing", t => {
  const send = spy()
  const state = { send, rotating: true }

  store.mutations.rotateLeft(state)

  t.true(send.notCalled)
})

test("rotateLeft: when after game exists", t => {
  const send = spy()
  const after = { uuid: v4() }
  const games = { after }

  const state = { send, games }

  store.mutations.rotateLeft(state)

  t.true(state.rotating)

  t.true(send.calledOnce)
  t.true(send.calledWithMatch({
    action: "rotate",
    direction: LEFT,
    of: games.after.uuid
  }))
})

test("rotateRight: when already rotating does nothing", t => {
  const send = spy()
  const state = { send, rotating: true }

  store.mutations.rotateRight(state)

  t.true(send.notCalled)
})

test("rotateRight: when before game exists", t => {
  const send = spy()
  const before = { uuid: v4() }
  const games = { before }

  const state = { send, games }

  store.mutations.rotateRight(state)

  t.true(state.rotating)

  t.true(send.calledOnce)
  t.true(send.calledWithMatch({
    action: "rotate",
    direction: RIGHT,
    of: games.before.uuid
  }))
})

test("actions: logout", async t => {
  global.fetch = identity
  store.actions.logout({ commit: identity })
  t.pass()
})

{'fraction_non_alphanumeric': 0.149211833297344, 'fraction_numerical': 0.0012956164975167351, 'mean_word_length': 3.608955223880597, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '782832', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1558, 'n_words': 368}