<commit_before>import MessageCompose from '~/components/MessageCompose'
import { mount, createStore } from 'helpers/client'

import noSsr from 'nuxt/lib/app/components/no-ssr'

describe('MessageCompose component', () => {
  let store, vm, wrapper
  beforeEach(() => {
    store = createStore()
    store.commit('SET_USER', {
      username: 'foo',
      id: 1,
      storage: {
        available: 0
      }
    })
    wrapper = mount(MessageCompose, {
      mocks: {
        $store: store
      },
      stubs: {
        noSsr,
        picker: true
      }
    })
    vm = wrapper.vm
  })
  it('disabled submit button when empty textarea', () => {
    expect(vm.calcDisabled).to.be.true
  })
  it('disabled when sending message', () => {
    vm.promise = true
    expect(vm.calcDisabled).to.be.true
  })
  describe('methods', () => {
    describe('submit button', () => {
      let $submitButton
      beforeEach(() => {
        $submitButton = wrapper.find('button[type="submit"]')
      })
      context('has no text', () => {
        it('disabled ', () => {
          expect($submitButton.attributes().disabled).to.equal('disabled')
        })
      })
      context('has text over 2048 characters', () => {
        it('disabled ', () => {
          vm.text = 'a'.repeat(2058)
          expect($submitButton.attributes().disabled).to.equal('disabled')
        })
      })
      context('has some photos but no text', () => {
        it('disabled', () => {
          expect($submitButton.attributes().disabled).to.equal('disabled')
        })
      })
      // TODO: write more tests
      // context('with some text', () => {
      //   it('return promise')
      // })
    })
  })
  describe('remain', () => {
    it('default remain is 2048', () => {
      const remaining = +wrapper.find('[data-test-id="message-counter"]').text()
      expect(remaining).is.equal(2048)
    })
    context('when text length is 128', () => {
      it('remain equals 1920', async () => {
        vm.text = 'a'.repeat(128)
        await new Promise(resolve => setTimeout(resolve, 500))
        const remaining = +wrapper
          .find('[data-test-id="message-counter"]')
          .text()
        expect(remaining).is.equal(1920)
      })
    })
    context('when text length is 2048', () => {
      it('remain equals 0 ', async () => {
        vm.text = 'a'.repeat(2048)
        await new Promise(resolve => setTimeout(resolve, 500))
        const remaining = +wrapper
          .find('[data-test-id="message-counter"]')
          .text()
        expect(remaining).is.equal(0)
      })
    })
    context('when text length is 2058', () => {
      it('remain equals -10', async () => {
        vm.text = 'a'.repeat(2058)
        await new Promise(resolve => setTimeout(resolve, 500))
        const remaining = +wrapper
          .find('[data-test-id="message-counter"]')
          .text()
        expect(remaining).is.equal(-10)
      })
    })
  })
  describe('add photo button', () => {
    context('when unpaid a user', () => {
      it('is hidden', () => {
        expect(wrapper.find('.add-photo').exists()).is.false
      })
    })
    context('when paid a user', () => {
      it('is shown', () => {
        store.commit('SET_USER', {
          username: 'foo',
          id: 1,
          storage: {
            available: 1
          }
        })
        expect(wrapper.find('.add-photo').exists()).is.true
      })
    })
  })
})
<commit_msg>message test like post test<commit_after>import MessageCompose from '~/components/MessageCompose'
import { mount, createStore } from 'helpers/client'

import noSsr from 'nuxt/lib/app/components/no-ssr'

describe('MessageCompose component', () => {
  let store, vm, wrapper
  beforeEach(() => {
    store = createStore()
    store.commit('SET_USER', {
      username: 'foo',
      id: 1,
      storage: {
        available: 0
      }
    })
    wrapper = mount(MessageCompose, {
      mocks: {
        $store: store
      },
      stubs: {
        noSsr,
        picker: true
      }
    })
    vm = wrapper.vm
  })
  it('disabled submit button when empty textarea', () => {
    expect(vm.calcDisabled).to.be.true
  })
  it('disabled when sending message', () => {
    vm.promise = true
    expect(vm.calcDisabled).to.be.true
  })
  describe('methods', () => {
    describe('submit button', () => {
      let $submitButton
      beforeEach(() => {
        $submitButton = wrapper.find('button[type="submit"]')
      })
      context('has no text', () => {
        it('disabled ', () => {
          expect($submitButton.attributes().disabled).to.equal('disabled')
        })
      })
      context('has text over 2048 characters', () => {
        it('disabled ', () => {
          vm.compiledTextLength = 'a'.repeat(2058)
          expect($submitButton.attributes().disabled).to.equal('disabled')
        })
      })
      context('has some photos but no text', () => {
        it('disabled', () => {
          expect($submitButton.attributes().disabled).to.equal('disabled')
        })
      })
      // TODO: write more tests
      // context('with some text', () => {
      //   it('return promise')
      // })
    })
  })
  describe('remain', () => {
    it('default remain is 2048', () => {
      const remaining = +wrapper.find('[data-test-id="message-counter"]').text()
      expect(remaining).is.equal(2048)
    })
    context('when text length is 128', () => {
      it('remain equals 1920', async () => {
        vm.text = 'a'.repeat(128)
        await new Promise(resolve => setTimeout(resolve, 500))
        const remaining = +wrapper
          .find('[data-test-id="message-counter"]')
          .text()
        expect(remaining).is.equal(1920)
      })
    })
    context('when text length is 2048', () => {
      it('remain equals 0 ', async () => {
        vm.text = 'a'.repeat(2048)
        await new Promise(resolve => setTimeout(resolve, 500))
        const remaining = +wrapper
          .find('[data-test-id="message-counter"]')
          .text()
        expect(remaining).is.equal(0)
      })
    })
    context('when text length is 2058', () => {
      it('remain equals -10', async () => {
        vm.text = 'a'.repeat(2058)
        await new Promise(resolve => setTimeout(resolve, 500))
        const remaining = +wrapper
          .find('[data-test-id="message-counter"]')
          .text()
        expect(remaining).is.equal(-10)
      })
    })
  })
  describe('add photo button', () => {
    context('when unpaid a user', () => {
      it('is hidden', () => {
        expect(wrapper.find('.add-photo').exists()).is.false
      })
    })
    context('when paid a user', () => {
      it('is shown', () => {
        store.commit('SET_USER', {
          username: 'foo',
          id: 1,
          storage: {
            available: 1
          }
        })
        expect(wrapper.find('.add-photo').exists()).is.true
      })
    })
  })
})

{'fraction_non_alphanumeric': 0.1813441483198146, 'fraction_numerical': 0.018829663962920046, 'mean_word_length': 2.081213743864346, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 63, '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': '2250076', 'n_tokens_mistral': 2154, 'n_tokens_neox': 2062, 'n_words': 392}