go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/ui/src/core/components/release_notes/common.test.tsx (about) 1 // Copyright 2023 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 import { 16 bumpLastReadVersion, 17 getLastReadVersion, 18 parseReleaseNotes, 19 } from './common'; 20 21 const unreleased = `\ 22 * unreleased update 1 23 * unreleased update 2 24 `; 25 26 const latest = `\ 27 <!-- __RELEASE__: 2 --> 28 * update 4 29 * update 5 30 `; 31 32 const past = `\ 33 <!-- __RELEASE__: 1 --> 34 # 2020-02-02 35 * update 2 36 * update 1 37 38 <!-- __RELEASE__: 0 --> 39 # 2020-02-01 40 * update 0 41 `; 42 43 const releaseNotes = `\ 44 ${unreleased}\ 45 ${latest}\ 46 ${past}\ 47 `; 48 49 const noUnreleasedNotes = `\ 50 ${latest}\ 51 ${past}\ 52 `; 53 54 const noPastNotes = `\ 55 ${unreleased}\ 56 ${latest}\ 57 `; 58 59 const onlyUnreleasedNotes = `\ 60 ${unreleased}\ 61 `; 62 63 describe('parseReleaseNotes', () => { 64 it('can parse release notes', () => { 65 const log = parseReleaseNotes(releaseNotes); 66 expect(log.latestVersion).toEqual(2); 67 expect(log.latest).toEqual(latest); 68 expect(log.past).toEqual(past); 69 }); 70 71 it('can parse release notes without unreleased notes', () => { 72 const log = parseReleaseNotes(noUnreleasedNotes); 73 expect(log.latestVersion).toEqual(2); 74 expect(log.latest).toEqual(latest); 75 expect(log.past).toEqual(past); 76 }); 77 78 it('can parse release notes without past notes', () => { 79 const log = parseReleaseNotes(noPastNotes); 80 expect(log.latestVersion).toEqual(2); 81 expect(log.latest).toEqual(latest); 82 expect(log.past).toEqual(''); 83 }); 84 85 it('can parse release notes with only unreleased notes', () => { 86 const log = parseReleaseNotes(onlyUnreleasedNotes); 87 expect(log.latestVersion).toEqual(-1); 88 expect(log.latest).toEqual(''); 89 expect(log.past).toEqual(''); 90 }); 91 92 it('can parse empty release notes', () => { 93 const log = parseReleaseNotes(''); 94 expect(log.latestVersion).toEqual(-1); 95 expect(log.latest).toEqual(''); 96 expect(log.past).toEqual(''); 97 }); 98 }); 99 100 describe('get/bumpLastReadVersion', () => { 101 beforeEach(() => { 102 localStorage.clear(); 103 }); 104 105 it('can read from nothing', () => { 106 expect(getLastReadVersion()).toEqual(-1); 107 }); 108 109 it('can store last read version', () => { 110 expect(getLastReadVersion()).toEqual(-1); 111 bumpLastReadVersion(10); 112 expect(getLastReadVersion()).toEqual(10); 113 }); 114 115 it('store version in persisted storage', () => { 116 expect(getLastReadVersion()).toEqual(-1); 117 bumpLastReadVersion(10); 118 expect(getLastReadVersion()).toEqual(10); 119 localStorage.clear(); 120 expect(getLastReadVersion()).toEqual(-1); 121 }); 122 123 it('does not decrease version', () => { 124 bumpLastReadVersion(10); 125 expect(getLastReadVersion()).toEqual(10); 126 bumpLastReadVersion(5); 127 expect(getLastReadVersion()).toEqual(10); 128 }); 129 });