<commit_before>import stars from '@/store/modules/stars'
import sampleStars from '../../utils/sample-stars'
import router from '@/router'
import client from '@/store/api/client'

jest.mock('@/store/api/client')
jest.mock('@/router', () => ({
  replace: jest.fn(),
  currentRoute: {
    query: ''
  }
}))

const getters = stars.getters
const {
  CLEAR_STARS,
  ADD_TAG_TO_STARS,
  SET_CURRENT_LANGUAGE,
  SET_CURRENT_STAR,
  ADD_TO_CURRENT_STARS,
  SET_README,
  SET_STARS_PAGE_INFO,
  SET_STARS,
  SET_STAR_TAGS,
  SET_TOTAL_STARS,
  SET_USER_STARS,
  SET_VIEWING_UNTAGGED,
  MAP_USER_STARS_TO_GITHUB_STARS,
  SET_STAR_NOTES,
  RESET_STARS
} = stars.mutations
const {
  fetchGitHubStars,
  fetchUserStars,
  setCurrentLanguage,
  addTagToStars,
  setCurrentStar,
  addToCurrentStars,
  fetchReadme,
  setViewingUntagged,
  syncStarTags,
  editStarNotes,
  cleanupStars,
  autotagStars
} = stars.actions

let ctx, state
const defaultState = stars.state

describe('Stars Module', () => {
  beforeEach(() => {
    jest.resetModules()
    jest.clearAllMocks()
    state = JSON.parse(JSON.stringify(defaultState))
    ctx = {
      commit: jest.fn(),
      state,
      dispatch: jest.fn(),
      rootState: {
        user: {
          user: {
            access_token: '<KEY>'
          }
        },
        stars: {
          stars: []
        }
      }
    }
  })

  describe('Stars state', () => {
    it('returns the stars-related state', () => {
      expect(state).toEqual({
        userStars: [],
        stars: [],
        pageInfo: {},
        totalStars: 0,
        currentLanguage: '',
        currentStars: [],
        readme: '',
        viewingUntagged: false
      })
    })
  })

  describe('Stars getters', () => {
    it('returns the stars', () => {
      expect(getters.stars(state)).toEqual(state.stars)
    })

    it('returns the page info', () => {
      expect(getters.pageInfo(state)).toEqual(state.pageInfo)
    })

    it('returns total stars', () => {
      expect(getters.totalStars(state)).toEqual(state.totalStars)
    })

    it('returns a list of all star languages with counts', () => {
      state.stars = [...sampleStars.edges]
      expect(getters.languages(state)).toEqual({
        JavaScript: 3,
        PHP: 2
      })
    })

    it('returns the current language', () => {
      expect(getters.currentLanguage(state)).toEqual(state.currentLanguage)
    })

    it('returns the first current star or an empty object if there is none', () => {
      state.currentStars = [
        { name: 'First' },
        { name: 'Second' },
        { name: 'Third' }
      ]
      expect(getters.currentStar(state)).toEqual({ name: 'First' })

      state.currentStars = []
      expect(getters.currentStar(state)).toEqual({})
    })

    it('returns the current stars, and omits duplicates', () => {
      const stars = [sampleStars.edges[0], sampleStars.edges[1]]
      state.currentStars = stars
      expect(getters.currentStars(state)).toEqual(stars)

      // Concat a duplicate entry and assert the duplicate is not included in the getter<commit_msg>Added unit test for totalUntaggedStars getter<commit_after>import stars from '@/store/modules/stars'
import sampleStars from '../../utils/sample-stars'
import router from '@/router'
import client from '@/store/api/client'

jest.mock('@/store/api/client')
jest.mock('@/router', () => ({
  replace: jest.fn(),
  currentRoute: {
    query: ''
  }
}))

const getters = stars.getters
const {
  CLEAR_STARS,
  ADD_TAG_TO_STARS,
  SET_CURRENT_LANGUAGE,
  SET_CURRENT_STAR,
  ADD_TO_CURRENT_STARS,
  SET_README,
  SET_STARS_PAGE_INFO,
  SET_STARS,
  SET_STAR_TAGS,
  SET_TOTAL_STARS,
  SET_USER_STARS,
  SET_VIEWING_UNTAGGED,
  MAP_USER_STARS_TO_GITHUB_STARS,
  SET_STAR_NOTES,
  RESET_STARS
} = stars.mutations
const {
  fetchGitHubStars,
  fetchUserStars,
  setCurrentLanguage,
  addTagToStars,
  setCurrentStar,
  addToCurrentStars,
  fetchReadme,
  setViewingUntagged,
  syncStarTags,
  editStarNotes,
  cleanupStars,
  autotagStars
} = stars.actions

let ctx, state
const defaultState = stars.state

describe('Stars Module', () => {
  beforeEach(() => {
    jest.resetModules()
    jest.clearAllMocks()
    state = JSON.parse(JSON.stringify(defaultState))
    ctx = {
      commit: jest.fn(),
      state,
      dispatch: jest.fn(),
      rootState: {
        user: {
          user: {
            access_token: 'abc<PASSWORD>'
          }
        },
        stars: {
          stars: []
        }
      }
    }
  })

  describe('Stars state', () => {
    it('returns the stars-related state', () => {
      expect(state).toEqual({
        userStars: [],
        stars: [],
        pageInfo: {},
        totalStars: 0,
        currentLanguage: '',
        currentStars: [],
        readme: '',
        viewingUntagged: false
      })
    })
  })

  describe('Stars getters', () => {
    it('returns the stars', () => {
      expect(getters.stars(state)).toEqual(state.stars)
    })

    it('returns the page info', () => {
      expect(getters.pageInfo(state)).toEqual(state.pageInfo)
    })

    it('returns total stars', () => {
      expect(getters.totalStars(state)).toEqual(state.totalStars)
    })

    it('returns total untagged stars', () => {
      expect(getters.totalUntaggedStars(state)).toEqual(
        state.stars.filter(star => !star.tags.length).length
      )
    })

    it('returns a list of all star languages with counts', () => {
      state.stars = [...sampleStars.edges]
      expect(getters.languages(state)).toEqual({
        JavaScript: 3,
        PHP: 2
      })
    })

    it('returns the current language', () => {
      expect(getters.currentLanguage(state)).toEqual(state.currentLanguage)
    })

    it('returns the first current star or an empty object if there is none', () => {
      state.currentStars = [
        { name: 'First' },
        { name: 'Second' },
        { name: 'Third' }
      ]
      expect(getters.currentStar(state)).toEqual({ name: 'First' })

      state.currentStars = []
      expect(getters.currentStar(state)).toEqual({})
    })

    it('returns the current stars, and omits duplicates', () => {
      const stars = [sampleStars.edges[0], sampleStars.edges[1]]
      state.currentStars = stars
      expect(getters.currentStars(state)).toEqual(stars)

      // Concat a duplicate entry and assert the duplicate is not included in the getter
{'fraction_non_alphanumeric': 0.14151386929948284, 'fraction_numerical': 0.001567152483936687, 'mean_word_length': 2.7083091226031377, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '370824', 'n_tokens_mistral': 2155, 'n_tokens_neox': 2076, 'n_words': 387}